0% found this document useful (0 votes)
33 views

Lab2 Compiling and Testing Assembly Codesdata Storage and Variables

The MOV instruction copies the value of the source operand to the destination operand. The source can be an immediate value, register, or memory location, while the destination can be a register or memory location. Both operands must be the same size (byte or word). Common registers used are AX, BX, CX, DX, and segment registers like DS, ES, SS. Memory operands specify an address like [BX] or [BX+SI+7]. The example program uses MOV to initialize registers with values and copy the contents of CX to memory at address B800:015E.

Uploaded by

Olana Teressa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views

Lab2 Compiling and Testing Assembly Codesdata Storage and Variables

The MOV instruction copies the value of the source operand to the destination operand. The source can be an immediate value, register, or memory location, while the destination can be a register or memory location. Both operands must be the same size (byte or word). Common registers used are AX, BX, CX, DX, and segment registers like DS, ES, SS. Memory operands specify an address like [BX] or [BX+SI+7]. The example program uses MOV to initialize registers with values and copy the contents of CX to memory at address B800:015E.

Uploaded by

Olana Teressa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

MOV instruction

 copies the second operand (source) to the first operand (destination).

 the source operand can be an immediate value, general-purpose register or memory


location.

 the destination register can be a general-purpose register, or memory location.

 both operands must be the same size, which can be a byte or a word.

these types of operands are supported:

MOV REG, memory MOV memory, REG MOV REG, REG


MOV memory, immediate MOV REG, immediate
REG: AX, BX, CX, DX, AH, AL, BL, BH, CH, CL, DH, DL, DI, SI, BP, SP.

memory: [BX], [BX+SI+7], variable, etc...

immediate: 5, -24, 3Fh, 10001101b, etc...

for segment registers only these types of MOV are supported:

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.

memory: [BX], [BX+SI+7], variable, etc...

Here is a short program that demonstrates the use of MOV instruction: #MAKE_COM# ;
instruct compiler to make COM file.

ORG 100h ; directive required for a COM program.

MOV AX, 0B800h ; set AX to hexadecimal value of B800h.

MOV DS, AX ; copy value of AX to DS.

MOV CL, 'A' ; set CL to ASCII code of 'A', it is 41h.

MOV CH, 01011111b ; set CH to binary value.


MOV BX, 15Eh ; set BX to 15Eh.

MOV [BX], CX ; copy contents of CX to memory at B800:015E

RET ; returns to operating system.

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.

Syntax for a variable declaration:

name DB value name DW value


DB - stays for Define Byte.
DW - stays for Define 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

MOV AL, var1 MOV BX, var2

RET; stops the program.

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).

You might also like