I have this assembler code, which I'm supposed to translate into machine code in binary form:
.text
.align 2
.global main
.equ val,0x4712
main:
movi r16,val
movi r17,0
loop: addi r17,r17,1
subi r16,r16,1
bne r16,r0,loop
stop: br stop
.end
and I'm not sure how "bne r16,r0,loop" and "br stop" is interpreted.
My instruction set reference says that the bne instruction does this:
if(rA != rB)
then PC ← PC + 4 + σ(IMM16)
else PC ← PC +4
which, as I understand it, is the program counter being incremented by 4 + offset or simply by 4.
But, in my case, what is the offset/IMM16 value? The instruction set reference says:
"In the instruction encoding, the offset given by IMM16 is treated as a signed number of bytes relative to the instruction immediately following bne".
My interpretation of this is that the IMM16 value is the "distance" to the next instruction address, but I have no idea if this is correct. The hex-address for bne is 0x40010 and 0x40014 for br, so this would mean that the IMM16 value is 4? (which would result in PC jumping past the 0x40014 address if rA != rB?)