Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BEQ get wrong adrress because we may ignore the priority between "<<" and "+" #7

Open
XuDongZe opened this issue May 19, 2017 · 1 comment

Comments

@XuDongZe
Copy link

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)

@zavs
Copy link
Owner

zavs commented May 19, 2017

pc_b := pc + 4  + io.pc_imm32 << 2

equals

pc_b := (pc + 4 + io.pc_imm32) << 2

ADD operation has higher priority than SHIFT

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants