You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The beq x0 x0 loop instruction seems to be encoded incorrectly. According to chapter 19 "RV32/64G Instruction Set Listings" of the spec, this is a B-type instruction whose encoding is as follows:
According to section 2.3 "Immediate Encoding Variants", imm[12] is the sign of the immediate, so since imm[12] = 0, we have a positive offset, so beq x0 x0 loop will jump forward, even though it's supposed to jump backward, back to the loop label.
The immediate is:
0000 1 111110 1010 0 = 4052
So we'll jump 4052 bytes forward???
Furthermore, RARS provides a different encoding for this instruction:
v--- different leading bit
1 111111 00000 00000 000 1100 1 1100011 <- RARS
0 111110 00000 00000 000 1010 1 1100011 <- this assembler
RARS's immediate is 1111 1 111111 1100 0 = -8, so that's a jump 8 / 2 = 4 bytes back, so 2 instructions back, which leads to the loop label, which makes sense.
The text was updated successfully, but these errors were encountered:
Assembly code
Assembling it
Instructions in binary
This is the
.txt
file produced byconvert
:Issue
The
beq x0 x0 loop
instruction seems to be encoded incorrectly. According to chapter 19 "RV32/64G Instruction Set Listings" of the spec, this is a B-type instruction whose encoding is as follows:Thus, the immediate bytes are:
imm[4:1] = 1010
imm[10:5] = 111110
imm[11] = 1
imm[12] = 0
According to section 2.3 "Immediate Encoding Variants",
imm[12]
is the sign of the immediate, so sinceimm[12] = 0
, we have a positive offset, sobeq x0 x0 loop
will jump forward, even though it's supposed to jump backward, back to theloop
label.The immediate is:
So we'll jump 4052 bytes forward???
Furthermore, RARS provides a different encoding for this instruction:
RARS's immediate is
1111 1 111111 1100 0 = -8
, so that's a jump8 / 2 = 4
bytes back, so 2 instructions back, which leads to theloop
label, which makes sense.The text was updated successfully, but these errors were encountered: