It is currently Sun Oct 22, 2017 6:01 pm

All times are UTC - 7 hours





Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: 6502 Coding Tips
PostPosted: Sat Jul 13, 2013 11:04 am 
Offline
User avatar

Joined: Sun Jan 02, 2011 11:50 am
Posts: 522
There is a 6502 asm tricks thread here but I am curious if anyone has any other simple, straighforward, but maybe overlooked coding techniques that maybe aren't considered quite hacks/tricks for experienced 6502 coders, but useful to share with those that are a bit newer to 6502 asm.

For example, a 16 bit compare:

Code:
foo .res 2  ; 16 bit variables
bar .res 2 

lda foo
cmp bar     ; carry clear if low byte of foo < bar, set if foo >= bar
lda foo + 1
sbc bar + 1 ; subtract high byte bar, or in effect subtract one more if foo < bar
bcc label   ; if all 16 bits foo < bar goto label


The cmp instruction always sets the carry first, so for the second part of the compare you have to use sbc to not set the carry.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC - 7 hours


Who is online

Users browsing this forum: Bing [Bot] and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group