[Solved] Suppose the program counter PC is set to 0x20000000 a What range – Computer Architecture

a) The RISC-V jump-and-link (jal) instruction allows the program counter (PC) to jump to a target address and save the address of the next instruction in the link register (ra). The target address is calculated by adding a 20-bit immediate value (sign-extended to 32 bits) to the current PC.

Since the immediate value is 20 bits, it can represent values from -2^19 to 2^19-1. When adding this immediate value to the PC, the lower 2 bits of the PC are ignored, so the target address will always be aligned to a multiple of 4.

Therefore, the range of addresses that can be reached using the jal instruction is from PC + 4 – 2^19 to PC + 4 + 2^19 – 4.

b) The RISC-V branch if equal (beq) instruction allows the PC to branch to a target address if the two source registers are equal. The target address is calculated by adding a 12-bit immediate value (sign-extended to 32 bits) to the current PC.

Since the immediate value is 12 bits, it can represent values from -2^11 to 2^11-1. When adding this immediate value to the PC, the lower 1 bit of the PC is ignored, so the target address will always be aligned to a multiple of 2.

Therefore, the range of addresses that can be reached using the beq instruction is from PC + 4 – 2^11 to PC + 4 + 2^11 – 2.

Note: In both cases, the PC + 4 is added to account for the fact that the PC is always incremented by 4 after each instruction is fetched.

Read more here: Source link