0% found this document useful (0 votes)
238 views5 pages

Mips Practice Questions

This document provides examples of MIPS assembly language code for common tasks like printing data types, arithmetic operations, and functions. It includes code samples for printing strings, integers, floats, and characters. It also demonstrates how to perform addition, subtraction, multiplication using mul, mult and shift instructions, and division to get quotients and remainders in MIPS assembly. Finally, it shows a simple example of a function call.

Uploaded by

Manzar Ali
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
238 views5 pages

Mips Practice Questions

This document provides examples of MIPS assembly language code for common tasks like printing data types, arithmetic operations, and functions. It includes code samples for printing strings, integers, floats, and characters. It also demonstrates how to perform addition, subtraction, multiplication using mul, mult and shift instructions, and division to get quotients and remainders in MIPS assembly. Finally, it shows a simple example of a function call.

Uploaded by

Manzar Ali
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

MIPS ASSEMBLY LANGUAGE PRACTICE QUESTIONS

1. HELLO WORLD PROGRAM

.data
Message: .asciiz "Hello World"
.text
li $v0, 4
lw $a0, Message
syscall

2. PRINTING AN INTEGER

.data
INT: .word 14
.text
li $v0, 1
lwc1 $a0, INT
syscall

3. PRINTING A FLOAT

.data
FLOAT: .float 14.23
.text
li $v0, 2
lwc1 $f12, FLOAT
syscall
4. PRINTING A CHARACTER

.data
CHAR: .byte 'A'
.text
li $v0, 11
lb $a0, CHAR
syscall
MIPS ASSEMBLY LANGUAGE PRACTICE QUESTIONS

5. ADDING / SUBTRACTING TWO INTEGERS

.data
n1: .word 12
n2: .word 21
.text
lw $t0 n1($zero)
lw $t1 n2($zero)
add $t2, $t0, $t1 #REPLACE add WITH sub F0R SUBTRACTION
li $v0, 1
add $a0, $zero, $t2 #REPLACE add WITH sub F0R SUBTRACTION
syscall
6. MULTIPLYING INTEGERS
6.1. USING mul

.data
.text
#mul,mult.sll are the diiferent ways to multiply in mips assembly
#we are using mul in this code
addi $s0,$zero,10
addi $s1,$zero,2
mul $t0,$s0,$s1
li $v0,1
add $a0,$zero,$t0
syscall

6.2. USING mult

.data
.text
addi $t0, $zero,10203
addi $t1, $zero, 12
mult $t0,$t1
mflo $s0
li $v0,1
add $a0, $zero,$s0
syscall
MIPS ASSEMBLY LANGUAGE PRACTICE QUESTIONS

6.3. USING sll

.data
.text
# multiplying any number by 2^n
addi $s0,$zero,3
sll $t0,$s0,3 # multiplying $s0 by 2^3 and storing the result in $t0

#print
li $v0, 1
add $a0,$zero,$t0
syscall

7. DIVISION
7.1. SIMPLE DIVISION (CALCULATES ONLY QOUTIENT)

.data
.text
addi $t0, $zero,30
addi $t1, $zero,5

div $s0, $t0, $t1

li $v0, 1
add $a0, $zero,$s0
syscall
MIPS ASSEMBLY LANGUAGE PRACTICE QUESTIONS

7.2. QOUTIENT, REMAINDER AND A LITTLE BIT OF FUNCTION CALLING

.data
msg: .asciiz"Qoutients is"
msg2: .asciiz"Remainder is"
.text
main:
addi $t0, $zero,30
addi $t1, $zero,7

div $t0, $t1


mflo $s0
mfhi $s1

jal display
li $v0, 1
add $a0, $zero,$s0
syscall

jal display2
li $v0, 1
add $a0, $zero,$s1
syscall
li $v0,10
syscall

display:
li $v0,4
la $a0, msg
syscall
jr $ra

display2:
li $v0,4
la $a0, msg2
syscall
jr $ra
MIPS ASSEMBLY LANGUAGE PRACTICE QUESTIONS

8. A SIMPLE FUNCTION

.data
msg: .asciiz"Function call was succuessful"
.text
main:
jal display
li $v0,10
syscall
display:
li $v0,4
la $a0, msg
syscall
jr $ra

You might also like