[Coco] Assembler Question???

uhmgawa uhmgawa at third-harmonic.com
Thu Sep 3 21:19:51 EDT 2009


jdaggett at gate.net wrote:

>> There was a poor example in my first message but regards the assembler 
>> vs the ALU ....
>>
>>   ADDA #-1   gives $8B $FF
>>   SUBA #1    gives $80 $01
>>
>> and the other pair
>>
>>   ADDA #1    gives $8B $01
>>   SUBA #-1   gives $80 $FF
>>
>> In short, the assembler uses twos complimentary notation but does not 
>> convert subtractions into additions.
>>
> 
> Robert
> 
> Thanks. What that tells me is that negative numbers are represented as their 2's 
> compliment. 

Which intuitively seems the sensible thing for
the assembler to do.  Although I suppose an argument
could be made for the assembler flagging the
negative operand as an error in this situation.

In any case the ALU still interprets the data
as unsigned.  This really boils down to the
disposition of the carry bit.  For example assuming
register A contains 0x80:

ADDA #-1 -> 0x80 + 0xff -> 0x7f (logical result: 0x17f, true carry == 1)

SUBA #1 -> 0x80 - 0x01 -> 0x80 + 0xff -> 0x7f, (logical result: 0x7f, inverted carry == 0)

While the end result in A is the same, in the case
of apparently adding -1 we're actually adding 0xff
which results in treatment of the carry bit opposite
that of a subtract operation.  This can alter the
behavior of subsequent branch and subtract operations.

Other architectures do not invert the carry generated
by a subtract operation and interpret c == 1 into a
subsequent subtract operation as indicating no
borrow had been previously generated.

-- 
uhmgawa at third-harmonic.com



More information about the Coco mailing list