justinmeiners / lc3-vm

Write your own virtual machine for the LC-3 computer!

Home Page:https://www.jmeiners.com/lc3-vm/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Changes to the LEA and TRAP instructions in the Third Edition

auraes opened this issue · comments

Changes have been made to the LEA and TRAP instructions in the third edition of Introduction to Computing Systems, that you don't seem to have taken into account:

Major Changes in the Third Edition
The LC-3
A hallmark of our book continues to be the LC-3 ISA, which is small enough to be described in a few pages and hopefully mastered in a very short time, yet rich enough to convey the essence of what an ISA provides. It is the LC “3” because it took us three tries to get it right. Four tries, actually, but the two changes in the LC-3 ISA since the second edition (i.e., changes to the LEA instruction and to the TRAP instruction) are so minor that we decided not to call the slightly modified ISA the LC-4. The LEA instruction no longer sets condition codes. It used to set condition codes on the mistaken belief that since LEA stands for Load Effective Address, it should set condition codes like LD, LDI, and LDR do. We recognize now that this reason was silly. LD, LDI, and LDR load a register from memory, and so the condition codes provide useful information – whether the value loaded is negative, zero, or positive. LEA loads an address into a register, and for that, the condition codes do not really provide any value. Legacy code written before this change should still run correctly. The TRAP instruction no longer stores the linkage back to the calling pro- gram in R7. Instead, the PC and PSR are pushed onto the system stack and popped by the RTI instruction (renamed Return from Trap or Interrupt) as the last instruc- tion in a trap routine. Trap routines now execute in privileged memory (x0000 to x2FFF). This change allows trap routines to be re-entrant. It does not affect old code provided the starting address of the trap service routines, obtained from the Trap Vector Table, is in privileged memory and the terminating instruction of each trap service routine is changed from RET to RTI. As before, Appendix A specifies the LC-3 completely.

Similar to #51, I'm not sure what the best move is here.

I searched around online a bit, but only found official online resources for the second edition of the book. I wasn't able to find an official simulator or public copy of Appendix A for the third edition of the book. Also, the third-party simulators I found seemed to also follow the second edition spec.

On the one hand, I can understand wanting to keep this tutorial and its implementation up-to-date with the latest edition of the book LC-3 is defined by. However, since that edition isn't as common online, it makes me wonder if it would be better for us to just call out that the guide is based on the second edition of the book, and that later editions may vary.

Yeah, you're the one who knew what's best.

After some discussion, we've decided to continue implementing the LC-3 architecture as defined by the second edition of the textbook, primarily due to the more widespread availability of second edition resources. I've updated the tutorial to indicate that we're using the second edition in 403778f.

Thanks for calling out the difference though!