-
Notifications
You must be signed in to change notification settings - Fork 53
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
LDV - a better way to deal with 16-bit immediate value #28
Comments
Hey thanks for the feedback! The encoding strategy you've proposed is really nice compared with my brute force That said, a lot of what you've said could definitely improve the language. Would you be interested in opening a pull request with you're proposed changes? |
What do you mean by "all numbers are unsigned"? for a 16-bit addition, the result with signed or unsigned addends is the same. For instance, 0xFFFE + 0xFFFF = 0xFFFD. 0xFFFD can be seen as 65533 or -3, it's just a subjective viewpoint. When using ADD mode through bit 0 in OO, you just need to sign-extend the immediate value before adding it to register. |
"opening a pull request with you're proposed changes": do you suggest for me to clone your project, do the changes and then open pull request here? |
Ah good point. As for pull request, yes that's normally the easiest way. |
hum, there are that assembler and that bf compiler... if I don't want to touch that bf compiler, I'd better to keep LDV16 but as a pseudo using the new instruction and define LDV as a pseudo as well. I could also keep INC and DEC the same way. But I would need to rename the real instruction LDV with another name - unless there is a way to have an optional third argument, that is |
3rd argument can definitely work. While I agree the names are not the best, I'd rather take the path of least resistance when it comes to changes. |
## Instruction LDV LDV is renamed as MVV and LDV, MVI, ADI, MUI and AUI become pseudos using MVV ### Before: |LDV| D, V | VVVVVVVVVVDD0001 | Load a value into destination register. ### After: |LDV| D, V, O | VVVVVVVVOODD0001 | Load a value into destination register. |MVI| D, V | VVVVVVVV00DD0001 | Set a zero-extended lower byte to destination register. |ADI| D, V | VVVVVVVV01DD0001 | Set a zero-extended lower byte to destination register. |MUI| D, V | VVVVVVVV10DD0001 | Set a byte left shifted by 8 bits to destination register. |AUI| D, V | VVVVVVVV11DD0001 | Add a byte left shifted by 8 bits to destination register. Retro-compatibility is kept for assembly code, not for machine code.
* MOV is renamed as MVR and MOV, DEC, and INC become pseudos using MVR *Pseudo instructions to keep Retro-compatibility * LDV is renamed as MVV and LDV, MVI, ADI, MUI and AUI become pseudos using MVV * LDV becomes a pseudo instruction for retro compatibility * Update README.md to include changes due to proposals #28 and #33
Merged proposal to master |
Since you word is 16-bit wide, you may split it into 2×8-bit, and keep two bits of immediate (SS bits) to select a special operation.
In MIPS, you have LUI instruction which sets a register with imm16 left shifted by 16 bits. Then you can use ADDIU or ORI to add/or-ize the register with a signed 16-bit immediate value, allowing in two instructions to set a 32-bit immediate value to a register. ARM Cortex architecture also have a similar way.
So in your case, it could be:
And
|
LDV
|D, V
|VVVVVVVVVVDD0001
| Load a value into destination register.becomes
|
LDV
|D, V, O
|VVVVVVVVOODD0001
| Load a value into destination register.with pseudos
|
MVI
|D, V
|VVVVVVVV00DD0001
| Set a zero-extended lower byte to destination register.|
ADI
|D, V
|VVVVVVVV01DD0001
| Set a zero-extended lower byte to destination register.|
MUI
|D, V
|VVVVVVVV10DD0001
| Set a byte left shifted by 8 bits to destination register.|
AUI
|D, V
|VVVVVVVV11DD0001
| Add a byte left shifted by 8 bits to destination register.Mnemonics stand for:
The rationale is:
– the 8-bit immediate is zero/signed-extended respectively when bit 0 of SS is 0/1.
– the effective immediate value is set with the extended 8-bit immediate left shifted by 0/8 bits respectively when bit 1 of SS is 0/1,
– the effective immediate value is set/added respectively to the destination register when bit 0 of SS is 0/1.
As a result,
MVI Dr, 0xLL; AUI Dr, 0xHH
<=> Dr = 0x00LL + 0xHH00 <=> Dr = 0xHHLL and define a pseudoMVA Dr, 0xHHLL
,AUI Dr, 0xHH;ADI Dr,0xLL
<=> Dr = Dr + 0xHH00 + 0x00LL <=> Dr = Dr + 0xHHLL if 0xLL is inferior or equals to 0x7f,AUI Dr, 0xHH+1; ADI Dr, 0xLL
<=> Dr = Dr + (0xHH00+0x0100) + (0xffLL) <=> Dr = Dr + 0xHHLL if 0xLL is greater than 0x7f.ADA Dr, 0xHHLL
for the previous two points and which issues the right pair according to the sign bit of 0xLL.The text was updated successfully, but these errors were encountered: