In: Computer Science
Write MIPs program that will read two intergers from the user and compute for the sum and difference of the two intergers. Ask the user whether he wants to repeat the program : "[Y/y] / [N/n] ?".
For addition:
.data
msg1: .asciiz "Enter the first number: "
msg2: .asciiz "\nEnter the second number: "
result: .asciiz "\nThe result of addition is: "
.text
li $v0,4
la $a0,msg1
syscall
li $v0,5
syscall
move $t1,$v0
li $v0,4
la $a0,msg2
syscall
li $v0,5
syscall
move $t2,$v0
Add $t3,$t1,$t2
li $v0,4
la $a0,msg3
syscall
li $v0,1
move $a0,$t3
syscall
li $v0,10
syscall
For Subtraction:
.data
msg1: .asciiz "Enter the first number: "
msg2: .asciiz "Enter the second number: "
result: .asciiz "The result of subtraction is: "
.text
li $vo,4
la $a0,msg1
syscall
li $v0,5
syscall
move $v0,$t1
li $vo,4
la $a0,msg1
syscall
li $v0,5
syscall
move $v0,$t2
sub $t1,$t1,$t2
li $v0,4
la $a0,result
syscall
li $v0,1
move $a0,$t1
syscall
li $v0,10
syscall
For prompting the user to repeat the program:
.data
again:
.asciiz "Again (y or n)? "
answer:
.space 256
.text
.globl main
main:
li $v0, 4
la $a0, again
syscall
la $a0, answer
li $a1, 3
li $v0, 8
syscall
lb $t4, 0($a0)
beq $t4, 'y', main
beq $t4, 'Y', main
li $v0, 10
syscall