Gotchas: Difference between revisions
Content added Content deleted
Puppydrum64 (talk | contribs) |
Puppydrum64 (talk | contribs) |
||
Line 33: | Line 33: | ||
<lang 6502asm>INC $2005 ;the intent was to scroll the NES's screen to the right one pixel. That's not gonna happen. |
<lang 6502asm>INC $2005 ;the intent was to scroll the NES's screen to the right one pixel. That's not gonna happen. |
||
;What actually happens? Who knows! (I made this mistake once long ago.)</lang> |
;What actually happens? Who knows! (I made this mistake once long ago.)</lang> |
||
===Inverted Carry=== |
|||
The carry flag is "backwards" compared to most languages with regard to comparisons and subtractions. |
|||
On most CPUs, carry set is used to mean "less than", and carry clear is used to mean "greater than or equal." The 6502 is the opposite! |
|||
<lang 6502asm>LDA #$20 |
|||
CMP #$19 |
|||
BCS foo ;this branch is always taken, since #$20 >= #$19. If this were any other CPU this branch would never be taken!</lang> |
|||
Not only that, carry clear indicates a borrow when subtracting. This is also the opposite to most CPUs. To do a normal subtraction you need to ''set'' the carry before subtracting. |
|||
<lang 6502asm>LDA #8 |
|||
SEC |
|||
SBC #4 ;eight minus four</lang> |
|||
=={{header|68000 Assembly}}== |
=={{header|68000 Assembly}}== |