So I am new to MIPS and I wanted to implement simple modulo arithmetic functions. I am unable to see why the program is not jumping according to the jump statements in the code. Any help would be appreciated.
.data
text_enquiry : .asciiz "Enter operation code (1-add, 2-subtract, 3-multiply, 4-exponentiation, 5-inversion, 6-exit): "
text_a : .asciiz "Enter a: "
text_b : .asciiz "Enter b: "
text_m : .asciiz "Enter m: "
text_result : .asciiz "Result = "
new_line : .asciiz "\n"
.text
main:
## t0 = code, t1 = a, t2 = b, t3 = m
#print operation message
la $a0, text_enquiry
li $v0, 4
syscall
#read code
li $v0, 5
syscall
move $t0, $v0
#if code == 6
beq $t0, 6, exit
j rest
exit:
li $v0, 10
syscall
#else, continue procedure
#print 'a, b, m' messages and read them
rest:
la $a1, text_a
li $v0, 4
syscall
li $v0, 5
syscall
move $t1, $v0
la $a1, text_b
li $v0, 4
syscall
li $v0, 5
syscall
move $t2, $v0
la $a1, text_m
li $v0, 4
syscall
li $v0, 5
syscall
move $t3, $v0
j mod
## t0 = code, t1 = a, t2 = b, t3 = m, t4 = un-modded result, t5 = modded result, t6 =
mod:
beq $t0, 1, func_add
beq $t0, 2, func_sub
beq $t0, 3, func_mul
# beq $t0, 4, func_exp
func_add:
add $t4, $t1, $t2
div $t4, $t3
mfhi $t5
#print accordingly
la $a3, text_result
li $v0, 4
syscall
move $a3, $t5
li $v0, 1
syscall
la $a3, new_line
li $v0, 4
syscall
j main
func_sub:
sub $t4, $t1, $t2
div $t4, $t3
mfhi $t5
#print accordingly
la $a3, text_result
li $v0, 4
syscall
move $a3, $t5
li $v0, 1
syscall
j main
func_mul:
mult $t1, $t2
mflo $t4
div $t4, $t3
mfhi $t5
#print accordingly
la $a3, text_result
li $v0, 4
syscall
move $a3, $t5
li $v0, 1
syscall
j main
As you can see, the code works fine when the code is '6' but doesn't work for any other code value.
Aucun commentaire:
Enregistrer un commentaire