MIPS - How to find the address value of branch and jump instructions

helencrump

I have an exam coming up, and I am completely stuck on this question (see below); even looking at the model answer did not help. I've tried reading our main text for the topic, but still have no idea how to do this. If anyone could provide a step-by-step walk through of the question, I would be very grateful.

"Assuming the first instruction of the MIPS snippet below is located at memory address 0x10001000. What is the value for else and exit in bne and j instruction?"

1   0x10001000:   addi $s0, $0, 5
2   0x10001004:   sub $s2, $0, $s1
3   0x10001008:   beq $s0, $s2, else
4   0x1000100C:   add $s0, $0, $0
5   0x10001010:   add $t0, $s2, $s0
6   0x10001014:   j exit
7   0x10001018:   else: addi $s1, $s0, -1
8   0x1000101C:   exit:

Model Answer:

Else: 0000000000000011 Exit: 00000000000000010000000111

I have included a link to an image of the original question as well. http://i.imgur.com/NgHpZXs.png

Konrad Lindenbach

First, we'll deal with the branch. Branches are an I-Type instruction, so the branch target is encoded in 16 bits. The easiest way to figure out the immediate field of a branch is to count the number of instructions between the branch instruction and its target. In this case, the else label is 4 instructions after the beq, however, the PC is incremented by 4 during the instruction fetch stage, so the actual immediate field will actually be 3. Of course in binary, this matches up with the sample 0000000000000011.

Next, the jump is a J-Type instruction which encodes the target of the jump using the first 24 bits of its address. However, because the jump target must be word aligned, the last two bits will always be 0 making them unnecessary. Therefore, the jump field of the j instruction matches the sample answer: 0x1000101C >> 2 = 0x4000407 = 00000000000000010000000111

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

MIPS - How to find the address value of branch and jump instructions

From Dev

Branch instructions and Jump instruction in Mips

From Dev

MIPS jump and branch instructions range

From Dev

MIPS branch instead of jump

From Dev

MIPS Branch Instructions

From Dev

Why are branch instructions faster than jump instructions?

From Dev

Two sequential branch instructions in MIPS assembly?

From Dev

Two sequential branch instructions in MIPS assembly?

From Dev

MIPS/UP16 Branch instructions

From Dev

MIPS: J-format Instructions and Address Encoding

From Dev

How to find the minimum value of an array in MIPS

From Dev

How to save program counter address without using J-Type instructions in MIPS architecture

From Dev

MIPS jump instruction and consequence of the absolute value

From Dev

How to convert MIPS instructions to machine code?

From Dev

How to convert MIPS instructions to machine code?

From Dev

Instructions that takes register of ASCII character value as operand in MIPS

From Dev

Find value at address

From Dev

JUMP instruction in MIPS

From Dev

How to get asm to jump to a variable address in c?

From Dev

How to jump to an address saved in a register in intel assembly?

From Dev

How to find the branch of a commit?

From Dev

How to find the branch of a commit?

From Dev

How can I find the value of what a memory address currently holds?

From Dev

Will this set of instructions jump?

From Dev

BNE branch in MIPS assembly

From Dev

how to find character in string in MIPS assembly

From Dev

How to load and store word from/to address that index is in a register, MIPS

From Dev

How are the address of the memory and that of the register connected?(AddrConstant MIPS instruction)

From Dev

How are the address of the memory and that of the register connected?(AddrConstant MIPS instruction)

Related Related

  1. 1

    MIPS - How to find the address value of branch and jump instructions

  2. 2

    Branch instructions and Jump instruction in Mips

  3. 3

    MIPS jump and branch instructions range

  4. 4

    MIPS branch instead of jump

  5. 5

    MIPS Branch Instructions

  6. 6

    Why are branch instructions faster than jump instructions?

  7. 7

    Two sequential branch instructions in MIPS assembly?

  8. 8

    Two sequential branch instructions in MIPS assembly?

  9. 9

    MIPS/UP16 Branch instructions

  10. 10

    MIPS: J-format Instructions and Address Encoding

  11. 11

    How to find the minimum value of an array in MIPS

  12. 12

    How to save program counter address without using J-Type instructions in MIPS architecture

  13. 13

    MIPS jump instruction and consequence of the absolute value

  14. 14

    How to convert MIPS instructions to machine code?

  15. 15

    How to convert MIPS instructions to machine code?

  16. 16

    Instructions that takes register of ASCII character value as operand in MIPS

  17. 17

    Find value at address

  18. 18

    JUMP instruction in MIPS

  19. 19

    How to get asm to jump to a variable address in c?

  20. 20

    How to jump to an address saved in a register in intel assembly?

  21. 21

    How to find the branch of a commit?

  22. 22

    How to find the branch of a commit?

  23. 23

    How can I find the value of what a memory address currently holds?

  24. 24

    Will this set of instructions jump?

  25. 25

    BNE branch in MIPS assembly

  26. 26

    how to find character in string in MIPS assembly

  27. 27

    How to load and store word from/to address that index is in a register, MIPS

  28. 28

    How are the address of the memory and that of the register connected?(AddrConstant MIPS instruction)

  29. 29

    How are the address of the memory and that of the register connected?(AddrConstant MIPS instruction)

HotTag

Archive