You are on page 1of 27

Chapter 4

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

• In microprocessor, an instruction can be divided


into two parts: Operation code (opcode), and
Operand. 2
• In 8088 microprocessor, instruction size varies from
1 to 6 bytes.

• The opcode is the part of the instruction that


identifies the operation that is to be performed. For
example, move, addition, and subtract. Each opcode
is assigned a unique letter combination called a
mnemonic (MOV, ADD, SUB).
• Operands describe the data that are to be processed
as the microprocessor carries out the operation
specified by the opcode.

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.

2. Accessibility to system hardware


Assembly language have direct control over system hardware.
Examples:
1. Writing an interface program (called Device Driver).

– Drivers may interface with: Printer, Video adapters,


Network cards, Sound card, computer storage
devices such as hard disk, and CD-ROM.
2. The code on a smart card (RFID card).
3. Real time applications.
4. Developing system software (e.g. assembler, linker).
5. Interrupt in an Operating System (BIOS routine). 5
Addressing Modes
 To access the different types of operands, the 8088
is provided with various addressing modes.
 Addressing mode is a method of specifying an
operand.
1 Register operand addressing mode
2 Immediate operand addressing mode
3 Memory operand addressing mode
 Direct addressing mode
 Register indirect addressing mode
 Based addressing mode
 Indexed addressing mode
 Based-indexed addressing mode
6
4 String operand addressing mode
5 Port operand addressing mode
6 Implied operand addressing mode
7 Stack operand addressing mode

7
Addressing Modes
1 Register operand addressing mode
◦ The operand to be accessed is specified as residing in an
internal register of 8088

Internal registers that can be used as a source or destination operand


8
Addressing Modes
 Register operand addressing mode
◦ MOV AX, BX

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)

((ES)0+DI) ((DS)0 + SI)

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

a. Direct port addressing mode

Example:
IN AL, 12 ; Input the data from port 12 to the AL register.

b. Indirect port addressing mode

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 PUSH and POP instructions transfer a word between the


stackand a register or memory location.

• A PUSH immediate instruction is available to place immediate


dataon the stack.

• The PUSHA and POPA instructions transfer AX, CX, DX, BX, BP,
SP, SI, and DI between the stack and these registers.

27

You might also like