Author: JamesV
Posted: 05 Apr 2013 08:05:28 pm (GMT -5)
In assembly, setting up variables is really just allocating bits of memory to store data. eg:
Code:
What that means is that you can reference this alias called "xpos" and store data there, so if you did the following:
Code:
That would load the decimal value of 5000 into the register HL, and then load the value in register HL into the memory location referenced by "xpos", which in this case has been defined as the address $9872.
You can also use the #define instruction to define a constant for use throughout your program, eg:
Code:
This would load the value of 96 into the register A.
Essentially, if you define something with the #define instruction, when you assemble your program, anywhere in the code that contains that defined alias (ie. "xpos" or "WIDTH" as defined above), will be replaced with the value that you've given it (ie. $9872 or 96 as above).
You also asked about the .dw instruction. That's used to store data in your code, so extending on what you wrote:
Code:
There are two references to "Var_X" here. The register HL will be set to the value stored at the memory location of Var_X, ie. HL will now equal 1000. The register DE will be set to the value of Var_X itself. In the above code, Var_X is a location in memory, which in the above case would be $8007.
Finally, the .equ instruction works very similar to the #define instruction. The following two instructions do exactly the same thing:
Code:
They both tell the assembler that the alias "trash" should be replaced with "AppBackUpScreen".
_________________
"This is International Rescue... Thunderbirds are go!"
Posted: 05 Apr 2013 08:05:28 pm (GMT -5)
In assembly, setting up variables is really just allocating bits of memory to store data. eg:
Code:
#define xpos $9872
What that means is that you can reference this alias called "xpos" and store data there, so if you did the following:
Code:
ld hl,5000
ld (xpos),hl
You can also use the #define instruction to define a constant for use throughout your program, eg:
Code:
#define WIDTH 96
ld a,WIDTH
Essentially, if you define something with the #define instruction, when you assemble your program, anywhere in the code that contains that defined alias (ie. "xpos" or "WIDTH" as defined above), will be replaced with the value that you've given it (ie. $9872 or 96 as above).
You also asked about the .dw instruction. That's used to store data in your code, so extending on what you wrote:
Code:
.org $8000
ld hl,(Var_X)
ld de,Var_X
ret
Var_X: .dw 1000
Finally, the .equ instruction works very similar to the #define instruction. The following two instructions do exactly the same thing:
Code:
#define trash AppBackUpScreen
trash .equ AppBackUpScreen
_________________
"This is International Rescue... Thunderbirds are go!"