Category:6502 Assembly: Difference between revisions
m
→A True 8-Bit Computer
Puppydrum64 (talk | contribs) m (→RAM) |
Puppydrum64 (talk | contribs) |
||
Line 70:
==A True 8-Bit Computer==
The 6502 is an 8-bit computer in the purest sense. Unlike the Z80, the 6502 is not capable of 16 bit operations within a single register. To work with a 16 bit number you will need to split it in two and work with each half individually. The carry flag is useful for this, as (like on other CPUs with a carry flag) it acts as a conditional addition
<lang C>unsigned short foo = 0x00C0;
foo = foo + 0x50;</lang>
Equivalent 6502 Assembly:
<lang 6502asm>LDA #$C0
STA $20 ;we'll use $20 as the memory location of foo, just to keep things simple. A real C compiler would use the stack.
LDA #$00
STA $21 ;low byte was #$C0, high byte was #$00
;now we add #$50
LDA $20 ;load #$C0
CLC
ADC #$50
STA $20
LDA $21
;this time we DON'T clear the carry before adding.
ADC #0 ;since there's a carry from the last addition, this actually adds 1! If there was no carry, it would add 0.
STA $21</lang>
==Processor Flags==
|