开发者

Showing a BEQ MIPS instruction in binary

开发者 https://www.devze.com 2023-01-29 08:07 出处:网络
beq$s1, $s2, endif(assume endif is 22 instructions after the branch) The answer to the following question is
beq   $s1, $s2, endif(assume endif is 22 instructions after the branch)

The answer to the following question is

000100 10001 10010 0000000000001111

Can someone explain what "assume endif开发者_开发问答 is 22 instructions after the branch" means?

Helpful data:

opcode for beq is 000100

$s1 is 10010

$s2 is 10001

I just need help understanding how we get the last part, which is the endif.


You want to jump to the 22th instruction after the beq, that is skip the next 21 instructions. Now, that would be 10101 binary which is 21 decimal (the number of instructions to skip). The instruction for such a jump would be 0001 0010 0011 0010 0000 0000 0001 0101 and not what you have written (your branch offset is wrong).

You have to take into account that in MIPS every instruction is the same size (4 bytes), thus the branches count the number of words (4 bytes each) to jump.

As a note aside, these values are encoded in two's complement so when you skip forward you just have to read that number in binary and if it were backwards you would have to apply two's complement to "see" were it will jump.

0

精彩评论

暂无评论...
验证码 换一张
取 消