Two's complement: Difference between revisions
m
→{{header|6502 Assembly}}
Puppydrum64 (talk | contribs) m (→{{header|C}}) |
Puppydrum64 (talk | contribs) |
||
Line 17:
CLC
ADC #1 ;result: #%10101011</lang>
===16-bit===
<lang 6502asm>myVar equ $20
LDA #3
STA myVar
LDA #0
STA myVar+1 ;equivalent C: uint16_t myVar = 3;
negate:
LDA myVar+1
EOR #255
STA myVar+1
LDA myVar
EOR #255
STA myVar
CLC
ADC #1
STA myVar
;this handles the case if we started with something where the low byte was zero.
LDA myVar+1
ADC #0
STA myVar+1</lang>
=={{header|Z80 Assembly}}==
|