.text
main:
check whether the second value that user entered is less than zero and if yes the exit the program
blez $t1, exit
Taking the first input from the user
la,$a0,InputValone
li,$v0,4
syscall
li,$v0,5
move $t0,$v0
syscall
Taking the second input from the user
la,$a0,InputValTwo
li $v0,4
syscall
li $v0,5
move $v0,$t1
syscall
multiply the two inputs
mul $t2,$t1,$t0
move $t3,$t0
loop:
beq $t2,$t3, endloop #if $t2==$t3, end the program
add $t3,$t3,$t0 #else $t3=$t3+$t0
b loop
la $a0,OutputValue
li $v0,4
syscall
move $a0,$t3
li $v0,1
syscall
endloop:
.data
InputValone: .asciiz "Enter Your First Value : "
InputValTwo: .asciiz "Enter Your Second Value : "
OutputValue: .asciiz "Output is : "
endloop: .data
You do not really want to do this??
Using a jump instruction like blez $t1, exit
or beq $t2,$t3, endloop
you jump to a label.
Obviously the exit:
label is missing.
And it is not defined which instruction follows the endloop:
label:
Normal compilers (for real MIPS CPUs, not for MIPS emulators) would insert some dummy bytes between the last instruction of the code section and the .data
section - just like that:
endloop:
.word some_dummy_data
.word some_dummy_data
.word some_dummy_data
.word some_dummy_data
.word some_dummy_data
...
.data
The CPU would interpret that bytes as instructions and execute them...
You'll have to add the exit:
label and youll have to add code after the
endloop:` label:
exit:
endloop:
li $v0,<value that exits the program>
syscall
Not knowing your simulator I cannot tell you the correct value for v0
for exiting the program. For Linux/MIPS a value of v0=4001
would be suitable...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With