Shall we deal with the error input?

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

Shall we deal with the error input?

woodylcy
I mean we guarantee  that the input .asm file is right?

   I know someone has asked this kind of question, but I think my program is so awkward.
And there are instructions like this: D+A  A+1   ...   , when we write the .asm program, will A+D 1+A  ... do?

thanks very much. I am just a beginner with little programming experience
Reply | Threaded
Open this post in threaded view
|

Re: Shall we deal with the error input?

cadet1620
Administrator
You should check that the input is valid, and print an error message and abort.

The easiest way to write Code.comp is to write a table of comp strings and their instruction bit values. For example, in my assembler (written in Python) I have:

_compDict = {
    ...
    'D+1': '0011111',
    'A+1': '0110111',
    ...
    'D+A': '0000010',
    'A+D': '0000010',
    ...
};
Most high level languages have an easy way to search a table like this. If the mnemonic is not found, print an error message and abort. Otherwise, return the bit string.

You can see that I chose to support D+A and A+D, but not 1+D or 1+A. It would be simple to add them to the table if in the future I want to support them.

--Mark