Quick Reference for NESMaker ASM newbies

Hi guys, I wish I could offer this all myself, but having never programmed in ASM before I have been starting from nothing.

I know a lot of people are looking at the ASM code and seeing hieroglyphics, and I couldn't find a good quick reference guide myself.
So instead, I have been slowly deciphering it from the tutorial videos we have so far and playing around with scripts.

I figured I would post my notes here in case it helps someone else.
I think it would be helpful to have a stickied quick reference guide for this board. Just so those who know nothing can actually read a line and understand what it means.
That way we can start to learn by reading the existing code.

Here is what I have so far:
Code:
ASM REFERENCE

#$00 	- Literal numer
myVar	- Variable
myLabel:- Label
;	- comment, all after the semicolon is ignored

GAMEPAD BITS:
00000000
LRDUSSBA
    ||
StartSelect

LDA arg - Load Argument into accumulator A
	- Can be a literal or a variable

LDA arg1, arg2 - effectively: load value of type arg1 from object arg2
(actually uses arg2 as an offset to find arg1) store in accumulator
LDX arg1, arg2 - effectively: load value of type arg1 from object arg2
(actually uses arg2 as an offset to find arg1) store in x
LDY arg1, arg2 - effectively: load value of type arg1 from object arg2
(actually uses arg2 as an offset to find arg1) store in y

STA arg1 - Store accumulator in variable arg1
STA arg1, arg2 - Store value in arg2's arg1 type
STX arg1 - Store x in arg1
STY arg1 - Store y in arg1

TAX - Transfer value of accumulator to x
TAY - Transfer value of accumulator to y
TXA - self explanatory
TYA - self explanatory

LDX arg - same as LDA for the X address
LDY arg - same as LDA for the Y address

CMP arg - compare arg to accumulator and set flags for branching
CPX arg - same for X address
CPY arg - same for Y address

BEQ arg - if stored result is true, jump to label arg
BNE arg - if stored value is false, jump to label arg
BCC arg - if stored accumulator value is evaluated to less than, jump to arg
BCS arg - if stored accumulator value is evaluated to greater than, jump to arg
JMP arg - jump directly to label arg
NOTE: There is a physical distance limitation in code for these commands
JMP can reach much further than BEQ or BNE
Take this in mind when creating your branches, Branch to nearby code, Jump to faraway code.

RTI 	- return from interrupt
RTS	- return from subroutine

DEC arg	- decrease arg by 1
INC arg - increase arg by 1

CLC - clear carry bit for arithmetic

ADC arg - Add with carry. Add arg to the number in the accumulator
SBC arg - Subtract with carry. Subtract arg from number in the accumulator

AND arg - Logical AND, leaves accumulator with only those bits in common between it and the arg. 
0010 + 1100 = 0000
0100 + 1100 = 0100

ORA arg - Logical OR, leaves the accumulator with all true bits in both accumulator and arg
0100 + 0010 = 0110

I will try and update this as I learn more, but I hope I may be able to get some help from those more experienced.
Edit: Updated to include new info.
 

dale_coop

Moderator
Staff member
LDA Object_movement,x ;;<<-- load into the Accumulator, the "object_movement" value of the object "X" (usually the Player object is loaded in "X")
CLC ;;<<---to clear the carry (usually needed when you do additions)
ADC #$10 ;;<-- add "10" to the value already stored in the Accumulator (in hex... so "12" decimal value).
 

chronosv2

New member
This might help. More technical but gives a list of 6502 commands.
http://www.obelisk.me.uk/6502/reference.html
 

WolfMerrik

New member
I have had this tab open: http://www.6502.org/tutorials/6502opcodes.html
For the past week while I learn ASM =P
 

Kasumi

New member
Code:
CMP arg - compare arg to accumulator and store result
I'm not sure I'd say the result is stored, but the processor status flags are affected.

How the 6502 "compares" numbers is by subtracting them. So CMP does not store the result of the subtraction in the accumulator, but SBC does. This is also why when you do say...
Code:
lda #$04
cmp #$04
You can branch on equal. 4-4=0, which sets the zero flag allowing the branch. Branch on Equal (BEQ) is actually specifically branch on equal to zero.
Code:
lda #$04
sec;cmp ignores the carry flag, sbc does not
sbc #$04
Is identical in behavior except afterwards 0 is in A. (The result of the subtract is actually stored.)
Code:
LDA arg1, arg2 - load value of type arg1 from object arg2
This isn't quite correct. It loads using x or y as an offset.
Code:
ldx #0
lda $0200,x;loads the value from $0200+the value in X. (Which is zero.) So it loads from $0200

ldx #$02
lda $0200,x;loads the value from $0200+the value in X. (Which is two.) So it loads from $0202.
In NES Maker, each object uses a number as an index in an array, so that object's data is placed that number of spaces away from the beginning of each data array, but the real use is way more general.
 
Thank you guys so much for your help!

With what I have learned so far I am starting to be able to decipher the existing code and understand how it works.
I hope this thread will be helpful to others as well.

On another note, something I find that is helping me learn:

Grab a short script that you do not understand how it works. Use the reference to figure out what is happening one line at a time.
You will begin to notice the data being manipulated in 'steps' or 'blocks' of code.

Modify the script yourself to have a comment stating what each step you decipher does, like you are trying to explain it to somebody else.
At least in my case, it is helping me to understand and read the code and know what it is doing, as well as how to use similar methods to modify scripts to do what I want.
 
Top Bottom