0
\$\begingroup\$

Consider the attached discussion of a reduced MIPS microprocessor from Weste and Harris's CMOS VLSI Design. My recollection of my computer organization course is relatively weak, so I'm hoping someone can clarify two quick questions I had:

enter image description here

(1) Why doesn't \$Destination\$ need to be multiplied by 4 as with \$Imm\$ in the BEQ instruction, and as per footnote a?

(2) If the PC has 8 bits, how is that we can put \$Destination\$ (with 26 bits) in it?

\$\endgroup\$
2
  • \$\begingroup\$ the program counter (PC) would not be 8 bits long \$\endgroup\$
    – jsotola
    Commented Dec 14, 2023 at 0:59
  • \$\begingroup\$ Would you be able to elaborate if you get the chance? The answer below seems to suggest it would be? @jsotola \$\endgroup\$
    – EE18
    Commented Dec 14, 2023 at 3:26

1 Answer 1

1
\$\begingroup\$

(1) In MIPS assembly, when dealing with the BEQ instruction, the Imm represents the offset in words, not bytes. Since MIPS instructions are 32 bits or 4 bytes long, the offset is specified in words, and it is implicitly multiplied by 4 during instruction execution. This is why the Imm is multiplied by 4.

However, for the Destination in the BEQ instruction, it refers to the target address to which the PC jumps if the branch condition is true. The Destination in this context represents the actual address, not an offset, so it doesn't need to be multiplied by 4.

(2) In MIPS Assembly, the Destination field in the BEQ instruction is a 26-bit field. The full 26 bits of the Destination are not directly placed into the PC. Instead, the branch target address is calculated by concatenating the upper 4 bits of the PC with the 26-bit Destination, effectively providing a 32-bit target address. This ensures that the branch target address fits within the available address space.

\$\endgroup\$
5
  • \$\begingroup\$ With regard to (1), the footnote does seem to say the "jump constant [is] specified in words". Are you saying that the coder of the assembly has to just be careful to write Destination as some multiple of 4, because one could in theory write any byte address (e.g. 3) in Destination with no problem (seems to contradict the footnote)? \$\endgroup\$
    – EE18
    Commented Dec 14, 2023 at 3:25
  • \$\begingroup\$ With regard to (2), would it be possible to expand a bit more on how this calculation works? For example, if the upper 4 bits of the PC and the 26 bit Destination come to together, what gets stored in the PC after? \$\endgroup\$
    – EE18
    Commented Dec 14, 2023 at 3:26
  • \$\begingroup\$ 1) You're on the right track. The coder does not need to manually multiply the Destination by 4 because it represents the actual address, not an offset in words. The assembler and processor handle the necessary calculations during execution. 2) First you would sign-extend the 26-bit Destination to 32 bits. Then shift left by 2, as mentioned in the footnotes. Next you would add PC+4. The reason for adding 4 is to account for the fact that the PC holds the address of the current instruction, and we want to jump to the target address. (cont...) \$\endgroup\$
    – user319168
    Commented Dec 14, 2023 at 3:52
  • \$\begingroup\$ (cont...) Now you want to concatenate with the upper bits of the PC. Lastly you store the PC, resulting 32-bit branch target address and replacing the old value. This is the address of the instruction that the processor will fetch and execute next if the branch condition is true. These steps ensure that the branch target address fits within the MIPS address space, allowing for both forward and backward branches. \$\endgroup\$
    – user319168
    Commented Dec 14, 2023 at 3:54
  • \$\begingroup\$ I think I can sort of follow this, and have therefore accepted, but I just want to check one last thing: you say that we store a 32-bit branch target address in the PC? But the PC can only host 8 bits, right? I guess the divergence here is that we are considering a restricted form of the MIPS architecture and in a full mIPS architecture the PC would be 32 bits? \$\endgroup\$
    – EE18
    Commented Dec 14, 2023 at 15:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.