Micro - Lecture CH 2
Micro - Lecture CH 2
07/23/2024 1
Chapter (2):
Outlines:
Directives & A sample program
Assemble, link, and run a program
Examples of assembly programs
Control transfer instructions
Data types and definitions
Others
07/23/2024 2
Components of a simple program
Assembly language program consists of:
instructions such as MOV, ADD, INC
Directives (also called pseudo-instructions): statements give
directions to the assembler about how it should translate the assembly
instructions into machine code
Instructions:
Instruction consists of four fields:
Label: instruction operands ;comments
Label field: (optional) refer to a line of code by name.
The label field can not exceed 31 characters.
Labels for directives do not need to end with a colon “:”.
Instruction & Operands fields: perform the real work of
program.
Comments field: (optional) begin by “;” at the end of line
07/23/2024 3
Components of a simple program
Directives:
MODEL definition or directive: selects the size of the
memory model (SMALL, MEDIUM, COMPACT, LARGE, and
HUGE).
Model directive: write as
07/23/2024 4
Components of a simple program
Directives:
Segment definition or directive: uses three directives
(.CODE & .DATA & .STACK).
Every line in the assembly program must be correspond to
one of these segments.
Stack segment defines storage for the stack. Ex. (.STACK 64)
Data segment defines the data that the program will use.
Code segment contains the assembly instructions.
07/23/2024 5
Components of a simple program
Example:
07/23/2024 6
Components of a simple program
Example:
Directives
Instructions
07/23/2024 7
How to Run Assembly Program?
Three steps to create executable assembly program:
07/23/2024 8
How to Run Assembly Program?
07/23/2024 9
Control Transfer Instructions
When the assembly program is executed, its often necessary to transfer control
program to a different locations by control transfer instructions.
Before illustrate these instructions, its necessary to explain the concept of FAR
& NEAR.
07/23/2024 11
Control Transfer Instructions
Conditional Jumps:
All conditional jumps are short jumps.
In short jump, the address of the target must be with -128 to +127 bytes,
means the conditional jump is 2 bytes instruction. One byte is the opcode
of the J condition and the second byte is offset range between (00 – FF)
gives 256 possible addresses.
Backward jumps (to -128)
Forward jumps (to +127)
In backward jump, the target address = second byte (2’S complement of the
displacement value) + IP of the instruction after the jump.
07/23/2024 12
Control Transfer Instructions
Conditional Jumps:
In backward jump, the target address = second byte (2’S complement of the
displacement value) + IP of the instruction after the jump.
Example:
07/23/2024 13
Control Transfer Instructions
Conditional Jumps:
In forward jump, the target address = code of operand + IP of the
instruction after the jump.
Example:
07/23/2024 14
Control Transfer Instructions
Unconditional Jumps:
1. Unconditional jump used instruction “JMP LABEL”, and can take the
following forms:
2. SHORT jump: take the format “JMP SHORT LABEL”, target address (-128 to
+127) bytes.
3. NEAR jump: take the format “JMP LABEL”, target address can be direct,
register, register indirect, memory indirect.
A. Direct JUMP: same SHORT jump, target address (+32767 to -32768)
B. Register indirect JUMP: target address is in a register
C. Memory indirect JMP: target address is a location in memory.
4. FAR jump:
07/23/2024 15
Control Transfer Instructions
Call Statements:
Another control transfer instruction. It is used to call a procedure.
It can be FAR or NEAR.
07/23/2024 16
Control Transfer Instructions
assembly language subroutines:
07/23/2024 17
Data types & Definition
Data types:
The data types used in 80x86 can be 8-bits or 16-bits, positive or negative.
Data directives:
Use the data directives to define the data types for 80x86 microprocessors.
Many types of data directives can be use:
1) ORG (Origin): is used to indicate the beginning of the offset address,
the number come following the ORG may be hex or decimal.
2) DB (define byte): is one of the most widely used data directives. DB can
be used to define the number in decimal, binary, hex, ASCII.
07/23/2024 18
Data types & Definition
Data directives: example:
07/23/2024 19
Data types & Definition
Data directives:
3) DUP (duplicate): is used to duplicate a given number of characters. This
can avoid a lot of typing. Example:
07/23/2024 20
Data types & Definition
Data directives:
4) DW (define word): is used to allocate memory 2 bytes (1 word) at a
time. It is used widely in the 80x86 because the registers are 16-bits.
07/23/2024 21
Data types & Definition
Data directives:
5) EQU (equate): is used to define a constant without occupying a
memory location.
07/23/2024 22
Data types & Definition
Data directives:
6) DD (define double word): is used to allocate memory locations that are
4 bytes (2 words) in size.
07/23/2024 23
Data types & Definition
Data directives:
7) DQ (define qaudword): is used to allocate memory locations that are 8
bytes (4 words) in size.
8) DT (define ten bytes): is used to allocate memory locations that are 10
bytes in size.
07/23/2024 24
Full Segment Definition
Segment definition: two types can be used:
1) Simple segment definition: Illustrate before. Used the .MODEL & .CODE
& .DATA & .STACK
2) Full segment definition: used two directives “SEGMENT” & “ENDS”.
07/23/2024 25
Full Segment Definition
Segment definition:
07/23/2024 26
Full Segment Definition
Full Segment definition:
Stack segment definition:
07/23/2024 27
Any Question?
07/23/2024 28