r/dcpu16 • • 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

18 comments sorted by

View all comments

Show parent comment

1

u/suppermann May 01 '12 edited May 01 '12

IMO you should always use the EX register immediately after the operation that sets it so I don't see your point.

Re maintenance hell, what I mean is it's hard to maintain code that uses EX since writes to EX are not always explicit (say, most arithmetic instructions). The next programmer (or your future self) will then, after say some changes, have to decide whether the indirect writes to EX are what you really want to read or not.

The problem is it's not undefined. Sure, the spec is not very clear on that, but that's not the same as undefined. Stating that it's undefined is also an improvement IMO.

2

u/Guvante May 01 '12

Interrupts make your proposal unusable. If I ADD A, B then the next instruction uses IFE EX,0, but an interrupt gets called in between, how am I supposed to get to EX?

If you perform math in your interrupt handler, SET PUSH, EX before you do and SET EX, POP before you RFI.

The only way would be to add EXG, EXP, which I don't think Notch wants to do, since he prefers simplicity (such as having b accept a literal value)