0% found this document useful (0 votes)
24 views28 pages

Micro Lecture CH 2

The document outlines key concepts in assembly language programming including directives, sample programs, and control transfer instructions. It discusses directives like MODEL and SEGMENT that define memory models and segments. Examples show how to assemble, link, and run programs. Control transfer instructions like conditional jumps, unconditional jumps, and calls are also covered. The document describes data types, directives like DB and DW to define data, and full versus simple segment definitions. Overall it provides an introduction to assembly language concepts for programming on 80x86 microprocessors.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views28 pages

Micro Lecture CH 2

The document outlines key concepts in assembly language programming including directives, sample programs, and control transfer instructions. It discusses directives like MODEL and SEGMENT that define memory models and segments. Examples show how to assemble, link, and run programs. Control transfer instructions like conditional jumps, unconditional jumps, and calls are also covered. The document describes data types, directives like DB and DW to define data, and full versus simple segment definitions. Overall it provides an introduction to assembly language concepts for programming on 80x86 microprocessors.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 28

Chapter (2):

assembly language
Programming

8/26/2022 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

8/26/2022 2
❑ 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
8/26/2022 3
❑ Directives:
➢ MODEL definition or directive: selects the size of the
memory model (SMALL, MEDIUM, COMPACT, LARGE, and
HUGE).
➢ Model directive: write as

➢ Small model: is one of the most widely used.


➢ Small model: uses a maximum of 64K-Bytes of memory for code and
another 64K-Bytes for data.

8/26/2022 4
❑ 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.

8/26/2022 5
❑ Example:

8/26/2022 6
❑ Example:

Directives

Instructions

8/26/2022 7
❑ Three steps to create executable assembly program:

8/26/2022 8
❑ Run a small program by using emulator 8086

8/26/2022 9
❑ 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.

❑ FAR & NEAR:


➢ If control is transferred to a memory location within the current code
segment, it is NEAR. Sometimes called intrasegment (within segment).

➢ If control is transferred to a memory location outside the current code


segment, it is FAR. Sometimes called intersegment (between segment).
➢ In a NEAR jump, the IP is update and CS remains the same.
➢ In a FAR jump, the IP is update and CS also is update.

8/26/2022 10
❑ Conditional Jumps:

8/26/2022 11
❑ 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.

8/26/2022 12
❑ 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:

8/26/2022 13
❑ Conditional Jumps:
➢ In forward jump, the target address = code of operand + IP of the
instruction after the jump.
➢ Example:

Target address= 000CH + 0006H = 0012H

8/26/2022 14
❑ 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:

8/26/2022 15
❑ Call Statements:
➢ Another control transfer instruction. It is used to call a procedure.
➢ It can be FAR or NEAR.

❑ Assembly language subroutines:


➢ In assembly language programming, it is common to have one main
program and many subroutines to be called from the main program.
➢ This allows the programmer to make each subroutine into a separate
module.
➢ Each module can be tested separately and then brought together.

8/26/2022 16
❑ assembly language subroutines:

8/26/2022 17
❑ 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.

8/26/2022 18
❑ Data directives: example:

8/26/2022 19
❑ Data directives:
3) DUP (duplicate): is used to duplicate a given number of characters. This
can avoid a lot of typing. Example:

8/26/2022 20
❑ 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.

8/26/2022 21
❑ Data directives:
5) EQU (equate): is used to define a constant without occupying a
memory location.

8/26/2022 22
❑ Data directives:
6) DD (define double word): is used to allocate memory locations that are
4 bytes (2 words) in size.

8/26/2022 23
❑ 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.

8/26/2022 24
❑ 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”.

8/26/2022 25
❑ Segment definition:

8/26/2022 26
❑ Full Segment definition:
➢ Stack segment definition:

➢ Data segment definition:

➢ Code segment definition:

8/26/2022 27
Any Question?

8/26/2022 28

You might also like