In: Computer Science
Please give full explanation.
Assume that the program counter (PC) is set to 0x00000000.
Describe
how each of the instructions below could be used to set the next
value of PC to 0x0FFFFFFC.
j, beq, jr, jal, bne
J - The jump instruction causes the content of the PC to change to the address given in the instruction. Therefore, all we need to do is the following to change the content of the PC:
j 0x0FFFFFFC
BEQ - This instruction checks the zero flag and if it is set to 1, then beq will cause a jump to an address given in the instruction. So, to set PC to 0x0FFFFFFC, we will set the zero flag to 1 and execute the following:
BEQ 0x0FFFFFFC
JR - This instruction loads into the PC the address stored in register $ra. Hence, to set PC to 0x0FFFFFFC, we need to load 0x0FFFFFFC to $ra and then call JR, using the following:
LOAD $ra 0x0FFFFFFC
jr $ra
JAL - JAL branches the PC to a given subroutine address and stores the address to the instruction next to jal in $ra for the PC to return after completing the subroutine.
So, to set PC to 0x0FFFFFFC, we need to execute the following:
JAL 0x0FFFFFFC
BNE - This instruction branches to a given address if the two registers given to it does not contain equal values.
So,
LOAD r1 4
LOAD r2 8
BNE r1 r2 0x0FFFFFFC
This will change the PC to 0x0FFFFFFC.