+Gemintronic Posted May 16, 2013 Share Posted May 16, 2013 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 Quote Link to comment Share on other sites More sharing options...
Mr SQL Posted May 16, 2013 Share Posted May 16, 2013 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! Quote Link to comment Share on other sites More sharing options...
+Gemintronic Posted May 16, 2013 Author Share Posted May 16, 2013 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! Quote Link to comment Share on other sites More sharing options...
RevEng Posted May 16, 2013 Share Posted May 16, 2013 1. yes, it saves one two bytes of rom for every assignment of the same value after the first value assignment. [edit - thanks for the correction, bogax] 2. yes, it wastes 3 bytes of rom every time you do it. 1 Quote Link to comment Share on other sites More sharing options...
bogax Posted May 16, 2013 Share Posted May 16, 2013 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 1 Quote Link to comment Share on other sites More sharing options...
Cybearg Posted May 25, 2013 Share Posted May 25, 2013 (edited) 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 May 25, 2013 by Cybearg Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.