When using assembly language, you will store most of your variables in registers. There are only 14 general purpose registers, however, so sometimes you will need to use memory words for other variables. A variable is just a location in memory that is reserved for use as that variable. To use that variable, you will need to first load its value into a register. If the value changes, you will need to write its value back into the memory location if you want to keep it. The variables are declared in assembly language by using a .DATA directive, and using a label to specify a certain word of memory.
Pascal:
VAR
x, y : INTEGER;
BEGIN
x := 10;
y := x;
END;
C++:
main () {
int x, y;
x = 10;
y = x;
}
Assembly:
SET r1, 10 ; set r1 to immediate value 10
STORE X, r1 ; store r1 into variable x
LOAD r1, X ; load variable x into r1
STORE Y, r1 ; store r1 into variable y
.DATA
X: 0 ; declare a memory location for variable x
Y: 0 ; declare a memory location for variable y
No comments:
Post a Comment