Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
04/07/02 19:03
Read: times


 
#21525 - RE: quick question on ASM variables
Hal Albach wrote:
-------------------------------
First and foremost, you cannot define a variable with DB, that defines a byte in Code Memory and you will not be able to write to that location.

Absolutely right Hal!

To define a variable you need to use EQU such as VAR1: EQU 50h

A better way of defining a var in ASM is this:
Declare a relocatable datasegment:
MyDataSegment SEGMENT DATA
Select the datasegment:
RSEG MyDataSegment
Then declare your variables:
VAR1: DS 1 ; Reserves one byte for a var
VAR2: DS 1 ; Another one-byte var
VAR3: DS 2 ; Reserves two bytes for the var
VAR4: DS 4 ; Reserves four bytes... You get the picture

Your assembler will now sort out the addresses for you, which is nice.... ;o)

When defining variables be careful to stay away from IRAM used by the Stack.

Again: absolutely true.

I usually set the Stack Pointer to 30h and start defining variables at 50h.

Very dangerous indeed! Although 32 bytes should be plenty for your stack requirements, there is always the posibility that more is needed and your stack will overwrite some of your variables!
Better to define your stack in the top part of the memory. The easiest way to do that is, using the method described above, declare a var "STACK" as the last variable in your list:
VAR4: DS 4
STACK: DS 1

Then in your code set the stackpointer:
MOV SP,#STACK
As long as you keep the "STACK" declaration in the last position, you are assured that the stack can never flow over into your variable space.

Also, be aware that in 8052 Assembler a variable is one bit or one byte. If a larger variable is needed you need to define each byte and manage the larger varible yourself. There are no double byte or double word variables.

See the above for a solution to this.

Best regards,
Rob.

List of 16 messages in thread
TopicAuthorDate
quick question on ASM variables            01/01/70 00:00      
RE: quick question on ASM variables            01/01/70 00:00      
RE: quick question on ASM variables            01/01/70 00:00      
RE: quick question on ASM variables            01/01/70 00:00      
RE: quick question on ASM variables            01/01/70 00:00      
RE: ASM variables, moving thru it            01/01/70 00:00      
RE: ASM variables, moving thru it            01/01/70 00:00      
RE: quick question on ASM variables            01/01/70 00:00      
RE: quick question on ASM variables, Rob            01/01/70 00:00      
RE: quick question on ASM variables, Rob            01/01/70 00:00      
RE: quick question on ASM variables            01/01/70 00:00      
RE: data segment variables wont work?            01/01/70 00:00      
RE: quick question on ASM variables            01/01/70 00:00      
RE: data segment variables wont work?            01/01/70 00:00      
RE: Thanks!!            01/01/70 00:00      
RE: Thanks!!            01/01/70 00:00      

Back to Subject List