- #1
- 37,626
- 9,861
A recent thread asking what a Python program does induced me to post this MIPS assembly program, and ask why we get the incorrect addition in the second line of output.
Here's the output from this code:
And here's the code that produces that output.
Edit: The first line of code after the Loop label adds the values in the $a1 and $a2 registers, and puts the sum in the $a3 register.
The code here was run in the QtSpim MIPS simulator, producing the output you see above.
Here's the output from this code:
Code:
5 + 2 = 7
5 + 2 = 3
Edit: The first line of code after the Loop label adds the values in the $a1 and $a2 registers, and puts the sum in the $a3 register.
The code here was run in the QtSpim MIPS simulator, producing the output you see above.
Code:
AddAddr = 0x400030
.data
Msg: .asciiz "5 + 2 = "
.text
.globl main
main:
li $a1, 5
li $a2, 2
li $t0, 2
Loop:
add $a3, $a1, $a2
lw $s0, AddAddr
addiu $s0, $s0, 2
sw $s0, AddAddr
la $a0, Msg
li $v0, 4
syscall
move $a0, $a3
li $v0, 1
syscall
li $a0, '\n'
li $v0, 11
syscall
sub $t0, $t0, 1
bgt $t0, $0, Loop
Done:
li $v0, 10
syscall
.end main
Last edited: