You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For inst.s, just the first one inst our teacher gave us.
The PC of beq is 0x20,and the ins is 0x12320001,so we will get a imm32 = 0x01 after decode and extend;
Next if beq is ok, we will get a new PC = PC + 4 + imm32<<2. So there is a trap in the priority between "<< " and "+": the priority of "+" is higher than "<<".
If we write our code like this,we will get a wrong adress 0x94.( Now the PC is 0x20,io.pc_imm_32 is 0x01)
pc_b := pc + 4 + io.pc_imm32 << 2
This is because the priority of "+" is higher than "<<",so we first get pc+4+io.pc_imm32, which is 0x20+0x04+0x01 = 0x25 ( for the demical is 37 ) ;then we let 0x25<<2,so we get a wrong address 0x94(for the demical is 37*4=148).
But that's not we want. we just want imm32<<2 first, so we can just do , add a bracket like this:
pc_b := pc + 4 + (io.pc_imm32 << 2)
The text was updated successfully, but these errors were encountered:
But that's not we want. we just want imm32<<2 first, so we can just do , add a bracket like this:
pc_b := pc + 4 + (io.pc_imm32 << 2)
The text was updated successfully, but these errors were encountered: