Assembly Language Programming and Addressing Modes
Assembly Language Programming and Addressing Modes
Assembly Language Programming and Addressing Modes
1
Assembly Language Programming
• The native language of the computer is the machine
language of the microprocessor.
• A program written in machine language is often
referred to as machine code.
• The microprocessor understands only machine code,
it is almost impossible to write program directly in
machine language. For this reason, programs are
normally written in other languages, such as assembly
language or high-level language such as C++.
3
• Assembly language program cannot be directly run on
the processor. They must still be translated to an
equivalent machine language program for execution by
the processor. This conversion is done automatically
by running the source program through a program
known as an assembler.
• The machine language output produced by the
assembler is called object code.
• Compiler is a program that converts high-level
language statements such as (for, do, while, if) to
machine code instructions.
4
Why programming is still done in assembly language?
1. Efficiency
–Space-efficiency refers to the memory requirements of a program
(i. e., the size of the code).
– Time-efficiency refers to the time taken to execute a program.
7
Addressing Modes
1 Register operand addressing mode
◦ The operand to be accessed is specified as residing in an
internal register of 8088
9
Addressing Modes
2 Immediate operand addressing mode
◦ If an operand is part of the instruction instead of the
contents of a register or memory location, it represents
what is called an immediate operand.
◦ Immediate operands normally represent constant data.
10
Addressing Modes
Immediate operand addressing mode
◦ MOV AL, 15H
11
Addressing Modes
3 Memory addressing modes
◦ To reference an operand in memory, 8088 must calculate
the physical address (PA) of the operand and then initiate
a read or write operation to this storage location.
12
Addressing Modes
Memory addressing modes
◦ Direct addressing mode
◦ Register indirect addressing mode
◦ Based addressing mode
◦ Indexed addressing mode
◦ Based-indexed addressing mode
13
Addressing Modes
Memory addressing modes
Direct addressing mode
◦ It is similar to immediate addressing in that information is
encoded directly into the instruction.
◦ However, the instruction opcode is followed by an
effective address, instead of the data.
14
Addressing Modes
Memory addressing modes
Direct addressing mode
◦ MOV CX, [1234H]
◦ PA = 0200016 +123416= 0323416
15
Addressing Modes
Memory addressing modes
Register indirect addressing mode
◦ It is similar to direct addressing in that an effective
address is combined with the contents of DS to obtain a
physical address.
◦ However, it differs in the way the offset is specified.
16
Addressing Modes
Memory addressing modes
Register indirect addressing mode
◦ MOV AX, [SI]
◦ PA = 0200016+123416 = 0323416
17
Addressing Modes
Memory addressing modes
Based addressing mode
◦ Effective address of the
operand is obtained by
adding a direct or indirect
displacement to the contents
of either base register BX or
base pointer register BP.
18
Addressing Modes
Memory addressing modes
Based addressing mode
◦ MOV [BX]+1234H, AL
◦ PA = 0200016 + 100016+ 123416 = 0423416
19
Addressing Modes
Memory addressing modes
Indexed addressing mode
◦ Similar to the based addressing
mode.
◦ Indexed addressing mode uses
the value of the displacement
as a pointer to the starting
point.
20
Addressing Modes
Memory addressing modes
Indexed addressing mode
◦ MOV AL, [SI]+1234H
◦ PA = 0200016 + 200016+ 123416 = 0523416
21
Addressing Modes
Memory addressing modes
Based-indexed addressing mode
◦ Combining the based
addressing mode and
the indexed addressing
mode.
◦ It can be used to access
complex data structures
such as 2D arrays.
22
Addressing Modes
Memory addressing modes
Based-indexed addressing mode
◦ MOV AL, [BX][SI]+1234H
◦ PA = 0200016 + 100016 200016 + 123416 = 0623416
23
Addressing Modes
4 String addressing mode
It automatically uses the source and destination registers to specify the effective
address of the source and destination operands, respectively.
Examples:
MOVSB (Move String Byte)
MOVSW (Move String Word)
SI SI ± 1 or 2
DI DI ± 1 or 2
MOVSB
Before execution DS=A000H, ES=1000H, SI=100H, and DI=200H
After execution
(10000+0200) (A0000+0100)
SI=101
DI=201
24
Addressing Modes
5 Port addressing modes
Example:
IN AL, 12 ; Input the data from port 12 to the AL register.
Example:
OUT AL, DX ; Output the content AL by the port whose address is
specified by the DX register.
25
Addressing Modes
6 Implied addressing mode
• In this mode, the operands are implied and are hence not
specified in the instruction.
Examples:
STC ; This set the carry flag.
CLC ; This clear the carry flag.
26
Addressing Modes
7 Stack memory-addressing mode
• The PUSHA and POPA instructions transfer AX, CX, DX, BX, BP,
SP, SI, and DI between the stack and these registers.
27