Lab2 Compiling and Testing Assembly Codesdata Storage and Variables
Lab2 Compiling and Testing Assembly Codesdata Storage and Variables
both operands must be the same size, which can be a byte or a word.
MOV SREG, memory MOV memory, SREG MOV REG, SREG MOV SREG, REG
SREG: DS, ES, SS, and only as second operand: CS.
REG: AX, BX, CX, DX, AH, AL, BL, BH, CH, CL, DH, DL, DI, SI, BP, SP.
Here is a short program that demonstrates the use of MOV instruction: #MAKE_COM# ;
instruct compiler to make COM file.
Assembler Directives
Assembler directives are predefined alphabetical strings that are hints given to the assembler which
converts assembly language to machine language. Some commonly used assembler directives are:
DB (Define Byte) : It is used to reserve byte(s) of memory locations in the memory available.
DW (Define Word) : It is used to reserve word(s) of memory locations in the memory available.
DQ (Define Quad Word) : It is used to reserve 64 bits of memory locations in the memory available.
DT (Define Ten Bytes) : It is used to reserve 10 bytes of memory locations in the memory available.
ASSUME : It informs assembler, name of logical segments to be assumed for different segments in the
program.
END : It represents the end of a program.
ENDP : It represents the end of a procedure (like a function in C).
ENDS : It represents the end of a segment.
EQU : It assigns a value to a label.
PROC : It represents the start of a procedure.
Also, + and - operators can be directly used to represent arithmetic addition and subtraction.
Variables
Variable is a memory location. For a programmer it is much easier to have some value be kept in a
variable named "var1" then at the address 5A73:235B, especially when you have 10 or more
variables.
Our compiler supports two types of variables: BYTE and WORD.
name - can be any letter or digit combination, though it should start with a letter. It's possible to declare unnamed
variables by not specifying the name (this variable will have an address but no name).
value - can be any numeric value in any supported numbering system (hexadecimal, binary, or decimal), or "?" symbol for
variables that are not initialized.
As you probably know from part 2 of this tutorial, MOV instruction is used to copy values from
source to destination.
Let's see another example with MOV instruction using variable:
ORG 100h
VAR1 DB 7
var2 DW 1234h
Copy the above code to emu8086 source editor, and press F5 key to compile and load it in the
emulator. You should get something like:
variables are replaced with actual memory locations. When compiler makes machine code, it
automatically replaces all variable names with their offsets. By default segment is loaded in DS
register (when COM files is loaded the value of DS register is set to the same value as CS register
- code segment).
In memory list first row is an offset, second row is a hexadecimal value, third row is decimal
value, and last row is an ASCII character value.
Compiler is not case sensitive, so "VAR1" and "var1" refer to the same variable.
The offset of VAR1 is 0108h, and full address is 0B56:0108.
The offset of var2 is 0109h, and full address is 0B56:0109, this variable is a WORD so it
occupies 2 BYTES. It is assumed that low byte is stored at lower address, so 34h is located before
12h.
You can see that there are some other instructions after the RET instruction, this happens because
disassembler has no idea about where the data starts, it just processes the values in memory and it
understands them as valid 8086 instructions (we will learn them later).