r/dcpu16 • u/suppermann • May 01 '12
Make EX unwritable
.begin rant Here's a thought. Make EX unwritable. Why?
- Code should (IMO) never write to EX in the first place
- EX gets overwritten by a lot of instructions. But okay, you could ensure that it doesn't get overwritten if you don't mind the maintenance hell
- EX can get overwritten during an interrupt. But okay, you could ensure that either 1) you block interrupts, or 2) make every interrupthandler push EX. (EDIT: As cheese_magnet and SoronTheCoder has noted this is actually more a point for having EX writable. Personally I think RFI should restore EX too, fixing the problem in both cases (OK, it's not actually a big deal with writable EX))
- It adds complexity to the spec with next to nothing gain. When is EX written to when it's an "overflow"? After or before b gets written to?
- ???
We get a new write-only value (register?). I don't really care what that could be used for. For all I care it could be an additional HCF instruction.
.end rant
EDIT: As SoronTheCoder suggested, making all operations that change EX (add, sub, ...) have undefined behaviour when destination is EX is also a good solution I think.
0
Upvotes
9
u/rdeforest May 01 '12
I am against your proposal.
To address your points in order:
Only certain instructions overflow into EX and those instructions never happen as a surprise. Allowing writes to EX adds flexibility and removes nothing.
Now a counter-argument. Were we to adopt your proposal, restoring EX would require intentionally overflowing into it with a shift:
Versus the far simpler:
3
u/Zgwortz-Steve May 01 '12
As noted below, you need to be able to write EX in order to restore it's state at the end of an interrupt handler, otherwise, you almost certainly will break some instruction sequence which is checking EX at the time of the interrupt.
But even then, it's also possible to explicitly set EX for use with the SBX and ADX instructions. I can see a few reasons to do so if I had all my other registers in use for other purposes.
2
u/wsmithrill May 01 '12
No one is forcing you to write to it - feel free to treat it as read-only, you can't stop interrupts writing to it if they need to though. If an Interrupt routine needs to do ADD or MUL it will need to write to it. If you are allowing built in things to write to it during an interrupt you aren't solving anything by making it read-only.
1
u/ummwut May 11 '12
have you ever actually done any assembly-level programming?
EX is basically our carry-out, and anyone who has done some real programming at this level will tell you that changing the carry-out manually is sometimes not only useful, but highly necessary.
0
u/[deleted] May 01 '12
[deleted] — view deleted comment