# Possible bug with @ command

5 messages
Open this post in threaded view
|
Report Content as Inappropriate

## Possible bug with @ command

 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?
Open this post in threaded view
|
Report Content as Inappropriate

## Re: Possible bug with @ command

 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
Open this post in threaded view
|
Report Content as Inappropriate

## Re: Possible bug with @ command

 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
Open this post in threaded view
|
Report Content as Inappropriate

## Re: Possible bug with @ command

 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?