Michael Geer

ASM v. C - Round 2:  Variables and Cycle Count

Discussion created by Michael Geer on Aug 20, 2012
Latest reply on Aug 22, 2012 by Michael Geer




byte TEST;TEST = 0;void main(void){    TEST++;}

 The C code SINGLE LINE "TEST++;" disassembles to:


 In ASM "INC TEST" is 5 cycle counts

In the disassembled C, "LDHX #TEST  INC ,X" is 3 + 4 (7) cycle counts.




I believe it has something to do with the variable type of TEST (byte), but I tried int, unsugned short, word and get the SAME disassembled code.


First:  in ASM what does adiing the "#" in front of TEST in "LDHX #TEST"??  Something to do with direct page RAM or something?


NEXT:  It seems odd you can Load HX with a variable, then INC ,X and it actually updates the variable.  Brings me back to the first question maybe the "#" is a pointer?


3rd:  WHAT CODE in C would DISASSEMBLE to the first example ASM code I gave.

In other words, I want "my_variable++;" to disassemble to "INC my_variable".


I posted before about the difference between a "REGISTER" in ASM and a "variable" in C, with no good explanation.  It seems this problem is bigger than I thought.


Finally, in my 30 pages (printed out - small font - meaning 100s of lines) ASM code I have 50+ REGISTERS (variables; single bytes allocated in memory) that I use (knowing they cant exceed 255) to store numbers like 4, 13, and 182 and update and manipulate them, do math ya know.  If I created this program in C, it would seems the "dissasembled" version would be full of "LDHX #my_var .. INC ,X" and the cycle counts of my code/program/routines would all be WAY WAY higher.  Again, THIS IS VERY BAD!


Any comments, answers, pointers, explanations would be great :smileyhappy:


Thanks in advance,