Jump to content
IGNORED

2 Questions for ASM Literate Lads


Gemintronic

Recommended Posts

1. I heard putting the same values on the same line saves cycles. Does it save ROM?

i.e. player0x = 33 : player0y = 33 : hp = 33

 

2. To be tidy I put a goto between sections of code EVEN IF THEY ARE CALLED sequentially near eachother. Does this waste ROM?

 

i.e.

 

init_game

x = 3

y = 2

goto main_game

 

main_game

..blah

Link to comment
Share on other sites

Loon,

I'm not sure of the answer, but I really like concenating in BASIC and have always wished I could do it in Assembly too :)

 

I've tried using the linefeed character as a concatenation character and it works temporarily but it vanishes (replaced by CR+LF) whenever I reload the file.

 

asm is so vertical - it would be great to code horizontally too with more than just comments!

Link to comment
Share on other sites

Loon,

I'm not sure of the answer, but I really like concenating in BASIC and have always wished I could do it in Assembly too :)

 

I've tried using the linefeed character as a concatenation character and it works temporarily but it vanishes (replaced by CR+LF) whenever I reload the file.

 

asm is so vertical - it would be great to code horizontally too with more than just comments!

 

I used to use it to keep simple groupings of statements together without resorting to using a separate line label. Apparently, batari designed bB such that less code needs to be run fetching the same value and storing it into variables when on the same line.

 

Seems like magic to me!

Link to comment
Share on other sites

1. yes, it saves one byte of rom for every assignment of the same value after the first value assignment.

 

two bytes (lda value)

 

works for variables too

 

assignments with the same value need to be consecutive

 

a = 1 : b = 2 : c = 1 : d = 2

 

saves you nothing

 

a = 1 : c = 1 : d = 2 : b = 2

 

saves four bytes

  • Like 1
Link to comment
Share on other sites

  • 2 weeks later...

If you're curious why, the reason is because Assembly loads a value into a register which it then passes off to memory locations. If the value is already loaded into a register, it can spare the step of loading it again, thus saving that space.

 

This:

 

LDA #$45 ; loads the hex value $45 into the A register
STA temp1 ; stores the hex value $45 into temp1
STA temp2 ; stores the hex value $45 into temp2

 

is the equivalent of:

 

temp1 = $45: temp2 = $45

 

While this:

temp1 = $45
temp2 = $45

 

Looks like this:

 

LDA #$45
STA temp1
LDA #$45
STA temp2

 

Since the "LDA" and the "#$45" are both converted into single-byte instructions, you save a total of two bytes by eliminating them.

Edited by Cybearg
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...