Possible bug with @ command

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

Possible bug with @ command

ElliottS
As I understand the language specifications, all A commands are supposed to start with 0
ie the A command is in the format 0vvvvvvvvvvvvvvv. When I try an A command with a negative number however it starts it off with 1
This is an example of what the assembler will do for me.
@-1 -------------> 1111111111111111

Should it not be 0111111111111111?
Reply | Threaded
Open this post in threaded view
|

Re: Possible bug with @ command

ElliottS
The more I think about this, the more I think it isn't possible to use negative values with the A command...  Two's complement requires the first bit be 1, wheres the A command requires the first bit be 0. I suppose what I experienced was just an oddity from doing something that you really shouldn't be doing in the first place. Any instance where I really need to load a negative value could be accomplished by the following bit of code:
@100
A=-A
Reply | Threaded
Open this post in threaded view
|

Re: Possible bug with @ command

cadet1620
Administrator
ElliottS wrote
Any instance where I really need to load a negative value could be accomplished by the following bit of code:
@100
A=-A
Nice analysis!
You can also load directly into D if that's where you need the negative number.

This works for all negative numbers except for the always troublesome -32768, because @32768 is illegal.

Can you see how to load -32768 into the A or D register with only 2 instructions?

--Mark
Reply | Threaded
Open this post in threaded view
|

Re: Possible bug with @ command

ElliottS
Took me a second to think about it but I think this works.
@32767
AD=!A

All this came about because I had it in my head that @-X should work when I was building my assembler.
As it stands now doing an A command with a negative number generates 0 followed by the twos complement representation of the negative number, but with 15 bits as opposed to 16. I now realise of course that this will load garbage positive numbers into the A register...

Is there any reason that the supplied assembler behaves the way it does or is this just a case of garbage in / garbage out. Mostly I'm hoping I can call my assembler done even though it handles @-X commands strangely. After all if its expected that assembly code should never have @-X commands than it shouldn't matter how oddly my assembler does it, right?
Reply | Threaded
Open this post in threaded view
|

Re: Possible bug with @ command

cadet1620
Administrator
ElliottS wrote
Is there any reason that the supplied assembler behaves the way it does or is this just a case of garbage in / garbage out. Mostly I'm hoping I can call my assembler done even though it handles @-X commands strangely. After all if its expected that assembly code should never have @-X commands than it shouldn't matter how oddly my assembler does it, right?
Definitely GIGO -- it's a bug in the supplied assembler and your assembler doesn't need to worry about it.  FWIW, my assembler prints an error message and terminates.

Another sequence to get -32768 into A is
    @32767
    A=A+1
But it's uglier than A=!A since the addition intentionally causes a "signed integer overflow".

--Mark