Jump to content

Photo

Constants place in assembler code?

Constants place in assembler

4 replies to this topic

#1 zilog_z80a OFFLINE  

zilog_z80a

    Chopper Commander

  • 102 posts

Posted Thu Mar 1, 2018 3:27 PM

Hi, this is a humble post to know where is the correct place to put in code our constants, i found this code (below) time ago...

 

and i think that constant data should go after ORG $F000

 

Please can somebody correct me if i'm not right?

 

cheers!! ty in advance.

 

 

 

                processor 6502
                include "vcs.h"
                include "macro.h"
                
SPRITE_HEIGHT0 equ 37
Joy0Right equ 128
Joy0Left equ 64
Joy0Down equ 32
Joy0Up equ 16
 
                
                SEG.U RAM
                ORG $80
Player0X ds 1
Player0Y ds 1
Player0PTR ds 2
time_of_jump ds 1
 
                SEG ROM
                ORG $F000
Reset
                CLEAN_START
 
    lda #%00001000
    sta REFP0
 
;SHALA LALALALALALA....... FOO FOO FOO.... TONS OF CODE FROM HERE.... YEH! 

Edited by zilog_z80a, Thu Mar 1, 2018 8:29 PM.


#2 RevEng OFFLINE  

RevEng

    River Patroller

  • 4,972 posts
  • Bitnik
  • Location:bottom of the stack

Posted Thu Mar 1, 2018 6:01 PM

Functionally, it doesn't really matter where they go, since the generated code will be the same. Ideally you'll place them prior to being referenced, to save the assembler a pass.

Aesthetically, I tend to gather them all at the top, just before or after the RAM definitions. It works better for me to have most symbol definitions in one place, so I know immediately where to go to change them. (the exception being labels, of coure.) If some symbols are very local in scope, I might consider placing their definition close to where they're used, though truthfully I can't recall having done so.

In a similar vein, just above any semi-complex routine that uses temp memory locations, I'll redefine a symbol for temp locations to give them more meaningful names. e.g. "deltax = temp3"

#3 zilog_z80a OFFLINE  

zilog_z80a

    Chopper Commander

  • Topic Starter
  • 102 posts

Posted Thu Mar 1, 2018 8:26 PM

Functionally, it doesn't really matter where they go, since the generated code will be the same. Ideally you'll place them prior to being referenced, to save the assembler a pass.

Aesthetically, I tend to gather them all at the top, just before or after the RAM definitions. It works better for me to have most symbol definitions in one place, so I know immediately where to go to change them. (the exception being labels, of coure.) If some symbols are very local in scope, I might consider placing their definition close to where they're used, though truthfully I can't recall having done so.

In a similar vein, just above any semi-complex routine that uses temp memory locations, I'll redefine a symbol for temp locations to give them more meaningful names. e.g. "deltax = temp3"

 

 
tnx RevEng, this text now is a reference and a guide for me, and tnx for your time to write and explain.
 
cheers!!


#4 Thomas Jentzsch OFFLINE  

Thomas Jentzsch

    Thrust, Jammed, SWOOPS!, Boulder Dash, THREE·S, Star Castle

  • 23,562 posts
  • Always left from right here!
  • Location:Düsseldorf, Germany, Europe, Earth

Posted Fri Mar 2, 2018 1:59 AM

A good idea is also to separate game specific constants (e.g. SPRITE_HEIGHT) which may change and general Atari 2600 constants (e.g. Joy0Right), which have a fixed value.

 

Also it is a best practice to use all UPPER_CASE for constants (BTW: GRP0, HMOVE etc. are all just general Atari 2600 constants too).



#5 zilog_z80a OFFLINE  

zilog_z80a

    Chopper Commander

  • Topic Starter
  • 102 posts

Posted Fri Mar 2, 2018 9:44 AM

A good idea is also to separate game specific constants (e.g. SPRITE_HEIGHT) which may change and general Atari 2600 constants (e.g. Joy0Right), which have a fixed value.

 

Also it is a best practice to use all UPPER_CASE for constants (BTW: GRP0, HMOVE etc. are all just general Atari 2600 constants too).

 

ty Thomas, great, always wanted to know about constants spots and all related, will take note about this too.

 

if somebody else wants to add something about constants is really really welcome.

 

cheers!






0 user(s) are browsing this forum

0 members, 0 guests, 0 anonymous users