[go: up one dir, main page]

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

Micro - Lecture (CH 2)

The document outlines assembly language programming and its components. It discusses directives like MODEL and segment definitions that define memory usage. It also explains how to assemble, link, and run a program. Control transfer instructions like conditional jumps, unconditional jumps, and calls are presented. Different data types and directives to define data like DB, DW, DD are introduced. The document provides examples of full segment definitions using the SEGMENT and ENDS directives.

Uploaded by

Hamza Mohammed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views28 pages

Micro - Lecture (CH 2)

The document outlines assembly language programming and its components. It discusses directives like MODEL and segment definitions that define memory usage. It also explains how to assemble, link, and run a program. Control transfer instructions like conditional jumps, unconditional jumps, and calls are presented. Different data types and directives to define data like DB, DW, DD are introduced. The document provides examples of full segment definitions using the SEGMENT and ENDS directives.

Uploaded by

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

Chapter (2):

assembly language Programming

Presented by
Dr. Mohammed Alolofi

09/14/2023 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

09/14/2023 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
09/14/2023 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

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

09/14/2023 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.

09/14/2023 5
Components of a simple program
 Example:

09/14/2023 6
Components of a simple program
 Example:

Directives

Instructions

09/14/2023 7
How to Run Assembly Program?
 Three steps to create executable assembly program:

09/14/2023 8
How to Run Assembly Program?

 Run a small program by using emulator 8086

09/14/2023 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.

 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.
09/14/2023 10
Control Transfer Instructions
 Conditional Jumps:

09/14/2023 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.

09/14/2023 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:

09/14/2023 13
Control Transfer Instructions
 Conditional Jumps:
 In forward jump, the target address = code of operand + IP of the
instruction after the jump.
 Example:

Target address= 000CH + 0006H = 0012H

09/14/2023 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:

09/14/2023 15
Control Transfer Instructions
 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.

09/14/2023 16
Control Transfer Instructions
 assembly language subroutines:

09/14/2023 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.

09/14/2023 18
Data types & Definition
 Data directives: example:

09/14/2023 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:

09/14/2023 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.

09/14/2023 21
Data types & Definition
 Data directives:
5) EQU (equate): is used to define a constant without occupying a
memory location.

09/14/2023 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.

09/14/2023 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.

09/14/2023 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”.

09/14/2023 25
Full Segment Definition
 Segment definition:

09/14/2023 26
Full Segment Definition
 Full Segment definition:
 Stack segment definition:

 Data segment definition:

 Code segment definition:

09/14/2023 27
Any Question?

09/14/2023 28

You might also like