Answer:
Explanation:
MIPS program which increments from 0 to 15 and display results in Decimal on the console
In this program the user defined procedures print_int and print_eot were used to print the integer values and new line characters(\n) respectively.the mechanisam of the loop is explaine in the comment section of the program.
addi $s0, $0, 0
addi $s1, $0, 15
print_int:
li $v0, 1 # system call to print integer
syscall
jr $ra # return
print_eol: # prints "\n"
li $v0, 4
la $a0, linebrk
syscall
jr $ra # return
main: . . .
li $a0, 0 # print 0
jal print_int # print value in $a0
loop: move $a0, $s0 # print loop count
jal print_int
jal print_eol # print "\n" character
addi $s0, $s0, 1 # increment loop count by 1
ble $s1, $s0, loop # exit if $s1<$s0
beq $s0, $0, end
end:
MIPS progam to increment from 0 to 15 and display results in Hexadecimal on the console
this program is slightly differed from the previous program in this program the system call issued in print_int is implemented with a system call that prints numbers in hex.
addi $s0, $0, 15
addi $s1, $0, 0
print_int:
li $v0,34 # syscall number for "print hex"
syscall # issue the syscall
jr $ra # return
print_eol: # prints "\n"
li $v0, 4
la $a0, linebrk
syscall
jr $ra # return
main: . . .
li $a0, 0 # print 0
jal print_int # print value in $a0
loop: move $a0, $s0 # print loop count
jal print_int
jal print_eol # print "\n" character
addi $s0, $s0, 1 # increment loop count by 1
ble $s1, $s0, loop # exit if $s0>$s1
beq $s0, $0, end
end: