addressing - MIPS - How to find the address value of branch and jump instructions -
i have exam coming up, , stuck on question (see below); looking @ model answer did not help. i've tried reading our main text topic, still have no idea how this. if provide step-by-step walk through of question, grateful.
"assuming first instruction of mips snippet below located @ memory address 0x10001000. value else , exit in bne , 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 link image of original question well. http://i.imgur.com/nghpzxs.png
first, we'll deal branch. branches i-type
instruction, branch target encoded in 16
bits. easiest way figure out immediate field of branch count number of instructions between branch instruction , target. in case, else
label 4
instructions after beq
, however, pc
incremented 4
during instruction fetch stage, actual immediate field 3
. of course in binary, matches sample 0000000000000011
.
next, jump j-type
instruction encodes target of jump using first 24
bits of address. however, because jump target must word aligned, last 2 bits 0
making them unnecessary. therefore, jump field of j
instruction matches sample answer: 0x1000101c >> 2 = 0x4000407 = 00000000000000010000000111
Comments
Post a Comment