It is currently Thu Nov 15, 2018 11:36 am

All times are UTC - 7 hours





Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Sat Sep 15, 2018 1:26 am 
Offline

Joined: Sat May 26, 2018 6:14 am
Posts: 49
Location: Italy
Hello to everyone,
I've another noob question on ASM 6052. I can't really understand the difference between LDA VARIABLE and LDA #VARIABLE. To be more precise:

I've a variable:

EM_ENEMY_1_STATE .rs 1

and a constant:

PLAYER_STATUS_WALK = $0001

I know that if I do LDA #EM_ENEMY_1_STATE it load the ADDRESS into accumulator, if I do LDA EM_ENEMY_1_STATE it load the VALUE. And that's ok, but, I i try to load a Constant and put the value into a variable, the variable is always 0000.

lda PLAYER_STATUS_WALK
sta EM_ENEMY_1_STATE


EM_ENEMY_1_STATE == 00

lda #PLAYER_STATUS_WALK
sta EM_ENEMY_1_STATE

EM_ENEMY_1_STATE == 01

But, that's the value or the address? I can't understand why in the first case is 0 and in the second is 01.

Thanks a lot for any response! :)


Top
 Profile  
 
PostPosted: Sat Sep 15, 2018 1:51 am 
Offline
User avatar

Joined: Wed Apr 02, 2008 2:09 pm
Posts: 1251
When you .rs 1, you are naming a number. When you "= $0001" you are also naming a number.

EM_ENEMY_1_STATE is a number. PLAYER_STATUS_WALK is a number. They are the same type of thing, even if you have defined them differently.

The 6502 can use numbers 2 ways. As an address, or as an "immediate" value. If you want to use the number as an immediate value, you precede it with a '#' symbol. If you want to use the number as an address, you don't.

Code:
lda PLAYER_STATUS_WALK;Use $0001 as an address. So A gets the value from address $0001
lda #PLAYER_STATUS_WALK;Use $0001 as an immediate value. So A gets the value 1.

lda EM_ENEMY_1_STATE;Use... whatever number this ends up getting as an address. So A gets the value from that address.
lda #EM_ENEMY_1_STATE;Use... whatever number this ends up getting as an immediate value. So A gets whatever value that number is.

The assembler doesn't know that when you use ".rs" you want variables and when you use "= $????" you want constants, so if you want "PLAYER_STATUS_WALK" to be used as a constant you have to precede it with a '#'.

If you want EM_ENEMY_1_STATE to be used as a variable you must NOT precede it with a '#'.

The '#' is the only thing that makes a difference. (At least for what you've posted.)

Edit: So the reason EM_ENEMY_1_STATE ends up as zero in the first example is because at RAM location PLAYER_STATUS_WALK ($0001) was the value #$00 when you loaded it, and then this value (#$00) was stored to EM_ENEMY_1_STATE

_________________
https://kasumi.itch.io/indivisible


Top
 Profile  
 
PostPosted: Sat Sep 15, 2018 2:01 am 
Offline

Joined: Sat May 26, 2018 6:14 am
Posts: 49
Location: Italy
Thanks a lot!


Top
 Profile  
 
PostPosted: Sat Sep 15, 2018 6:28 am 
Offline
Formerly ~J-@D!~
User avatar

Joined: Sun Mar 12, 2006 12:36 am
Posts: 474
Location: Rive nord de Montréal
Code:
    SMALL_NUMBER = $12
    BIG_NUMBER = $3456

SOME_ADDRESS: .res 1

    lda #SMALL_NUMBER       ; SMALL_NUMBER as number
    lda SMALL_NUMBER        ; SMALL_NUMBER as address (in zero page)
    lda (SMALL_NUMBER, x)   ; \ SMALL_NUMBER as address of an address
    lda (SMALL_NUMBER), y   ; / (only possible in zero page)

    lda #<BIG_NUMBER        ; Least significant byte of BIG_NUMBER (A = $56)
    lda #>BIG_NUMBER        ; Most significant byte of BIG_NUMBER (A = $34)
    lda #<SOME_ADDRESS      ; Least significant byte of SOME_ADDRESS (as number)
    lda #>SOME_ADDRESS      ; Most significant byte of SOME_ADDRESS (as number)
                            ; Note: the > and < syntax is assembler specific
    lda SOME_ADDRESS        ; SOME_ADDRESS as address

_________________
((λ (x) (x x)) (λ (x) (x x)))


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

All times are UTC - 7 hours


Who is online

Users browsing this forum: No registered users and 5 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