mips-assembler
mips-assembler copied to clipboard
Wrong behavior when assemble instruction beq
I test this asm with the assembler, but it gives wrong result of instruction beq:
.text
loop:
addi $t1, $t1, 1
add $t0, $t0, $t1
addi $t6, $zero, 100
slt $t5, $t1, $t6
addi $t6, $zero, 1
beq $t5, $t6, loop
It give machine code:
21290001
01094020
200E0064
012E682A
200E0001
11AE0018
I attempted to assemble by other assembler (https://alanhogan.com/asu/assembler.php) which gave result:
00400000: <loop> ; <input:4> loop:
00400000: 21290001 ; <input:5> addi $t1, $t1, 1
00400004: 01094020 ; <input:6> add $t0, $t0, $t1
00400008: 200e0064 ; <input:7> addi $t6, $zero, 100
0040000c: 012e682a ; <input:8> slt $t5, $t1, $t6
00400010: 200e0001 ; <input:9> addi $t6, $zero, 1
00400014: 11aefffa ; <input:10> beq $t5, $t6, loop
I checked the last instruction beq and found that the assembler generated incorrect address offset of label loop. In this case, offset should be a negative number.