pong.asm, strange dest syntax

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

pong.asm, strange dest syntax

ChesterPerry
In pong.asm is written the instruction:
MD=M+1

I'm reading the book, second edition, and the reference Figure 6.2 has not MD as dest instruction, but DM, so I did not implemented my assembler with MD. Is it a mistake by me? Do I have to implement DM and MD, AM and MA... or is a script's error?
Reply | Threaded
Open this post in threaded view
|

Re: pong.asm, strange dest syntax

ashort
the destinations should be from this list:

M
D
MD
A
AM
AD
AMD

Anything not in that list is undefined, meaning DM would be undefined, for example.  That’s the way I implemented it when I took the course a long time ago.

If the book says “DM”, that is surely a bug in my opinion.
Reply | Threaded
Open this post in threaded view
|

Re: pong.asm, strange dest syntax

ashort
The book’s Figure 6.2 also shows “ADM” instead of “AMD”.  Also a bug in my opinion.  Unless the authors intended on changing the specification.  
Reply | Threaded
Open this post in threaded view
|

Re: pong.asm, strange dest syntax

ashort
The first edition book used “MD” and “AMD”
Reply | Threaded
Open this post in threaded view
|

Re: pong.asm, strange dest syntax

WBahn
Administrator
The first edition of the book has an inconsistency in the specification that was corrected in the second edition. This is going to cause some confusion for people that use both editions (or classes in which different students use different editions).

In the first edition, the ordering of the destination bits in the Hack opcodes is ADM (Figure 4.4), but the bit ordering in the Hack Assembly Language specification (same Figure) is AMD. This is a common source of errors when students are implementing their assembler because they can easily switch the M and the D destination bits.

The authors have addressed this in the second edition by making the mnemonics consistent with the hardware bit ordering. The new software tools, when they are finished, are also supposed to be strictly compliant (the current ones are too permissive in what they will accept).

They probably have not caught all the places where example code uses the old ordering, and that is going to be an ongoing thorn in their side. I don't know if the second edition (I haven't received a final copy yet) makes it explicit that there was this change. It really should.
Reply | Threaded
Open this post in threaded view
|

Re: pong.asm, strange dest syntax

ashort
ahh, I see.  since M = 001 and D = 010, then it would make sense if 011 were referred to as DM, not MD.  

And same with 111, it makes more sense to refer to it as ADM, not AMD.

somehow I never noticed that inconsistency before :-)

Reply | Threaded
Open this post in threaded view
|

Re: pong.asm, strange dest syntax

WBahn
Administrator
In reply to this post by ChesterPerry
To more directly answer your question, you should only have to implement the mnemonics that are explicitly given by the instruction set architecture (ISA). It is best to think of "AM" as not being two independent pieces of information that happen to be placed next to each other, but rather a code word that has a specific meaning.

Instead of "AM", they could have chosen "BOB" to mean that both the A and the M registers get written to, while SUE could mean write to the D and the M registers. You would not expect an assembler to recognize USE as being equivalent to SUE just because it uses the same three letters but in a different order. The same is true with the opcode mnemonics. D+M is not a mathematical expression, but merely a codeword. We would not expect +DM and DM+ to be recognized, so there is no reason to expect M+D to be recognized.

Because we try to choose mnemonics that make it easy for humans to remember what they mean, we can fall into the trap of reading more into them than is really there.