Test Cases for Assembler

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

Test Cases for Assembler

Chamkey
This post was updated on .
Hi

Doing week 6 atm and I'm well on my way to finishing the assembler.
In doing so I made a test asm file that has some really stupid test cases like @R01N and @21JumpStreet or even just @R, coz knowing me, I might actually do something that stupid in the future.
I'm using the supplied assembler to see what should happen in these cases and one of my test cases "DM=A" throws an error, namely "Destination expected." Yet it doesn't throw the error if I reverse DM to become MD = A.
does anyone know why this is the case or is this just the assembler being weird.
Reply | Threaded
Open this post in threaded view
|

Re: Test Cases for Assembler

WBahn
Administrator
This is because the valid destination codes are mnemonics with the mnemonic "DM" being defined as indicating that the value is to be written to both the D register and RAM[A]. There is no mnemonic "MD" defined.
Reply | Threaded
Open this post in threaded view
|

Re: Test Cases for Assembler

Chamkey
If the mnemonic DM is defined. It means that DM should work right?
DM is write to the D Register and RAM[A].
MD is write to RAM[A] and the D Register.

It's just a reverse of operations. First do D, then do M. Or First do M, then do D.
In terms of the assembler this should not matter because it's still writing to both locations.
Why would "DM = A" fail, if "MD = A" doesn't?
Why does the order of operations, so to speak, matter?
Reply | Threaded
Open this post in threaded view
|

Re: Test Cases for Assembler

WBahn
Administrator
You need to understand what a mnemonic is.

It is nothing more than a string of letters that is defined to stand for something.

The authors CHOSE to define the two-character string of letters "DM" as meaning that the output of the ALU should be written to both the D register and RAM[A]. The could have chosen ANY string to use for this purpose, include "LEON". That would NOT mean that "NOEL" would have any similar meaning just because it happens to be "LEON" spelled backwards.

It's the same reason that you can't replace the keyword "for" in a C program with "repeat" or "loop" or even "FOR" just because you, as a human, are able to infer that they mean the same thing. The language definition defines the three-letter sequence 'f'-'o'-'r' as meaning something specific and if you use any other sequence of letters the compiler has no idea that you meant a particular loop construct.

If the writer of the assembler WANTS to define another, different, mnemonic "MD" that happens to have the same meaning, they are completely free to do so. But the only destination mnemonics they are required to support are the seven listed in Figure 4.4 in the text.

While it might seem like supporting all of the permutations of each destination mnemonic is a good idea, it really isn't. If your assembler supports ADM, MAD, MDA, DMA, and DAM in addition to AMD then it fosters people writing assembly code to be sloppy about adhering to the official language definition. That's fine as long as their code is ONLY ever assembled on YOUR assembler. But as soon as they go to assemble it on someone else's perfectly valid assembler, now they have a bunch of errors.

Reply | Threaded
Open this post in threaded view
|

Re: Test Cases for Assembler

Chamkey
Ah. So you meant that MD is defined, not the other way around. So me writing DM was just essentially me writing garbage.
I get it now.
Lol, Thanks