0% found this document useful (0 votes)
169 views

8086 Lecture Notes 3

The document describes the process of developing an assembly language program on a PC. It involves planning the solution with a flowchart, coding the solution in assembly language using instructions and directives, assembling the source code into an object module, linking the object module to produce an executable run module, and debugging the run module. Key files involved include the source code file, object module, map file, and executable run module. Key development tools are an editor, assembler, linker, and debugger.

Uploaded by

sai420
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
169 views

8086 Lecture Notes 3

The document describes the process of developing an assembly language program on a PC. It involves planning the solution with a flowchart, coding the solution in assembly language using instructions and directives, assembling the source code into an object module, linking the object module to produce an executable run module, and debugging the run module. Key files involved include the source code file, object module, map file, and executable run module. Key development tools are an editor, assembler, linker, and debugger.

Uploaded by

sai420
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

3.

1 Software : The Microcomputer


Program
An instruction can be divided into two parts:

ASSEMBLY LANGUAGE
PROGRAMMING

Operation code (opcode) one- to five-letter


mnemonic
Operands
Destination Operand
Opcode

Source Operand

ADD AX, BX
Format of an assembly statement:

LABEL: INSTRUCTION
e.g.

START: MOV AX, BX

; COMMENT
; Copy BX into AX

611 37100 Lecture 03-4

3.1 Software : The Microcomputer


Program

ASSEMBLY LANGUAGE
PROGRAMMING

Assembly source program


TITLE BLOCK-MOVE PROGRAM

3.1 Software: The Microcomputer Program


3.2 Assembly Language Programming
Development on the PC
3.3 The Instruction Set
3.4 The MOV Instruction
3.5 Addressing Modes

611 37100 Lecture 03-2

3.1 Software : The Microcomputer


Program
The sequence of commands used to tell a

microcomputer what to do is called a program. Each


command in a program is an instruction.
The 8088 microprocessor performs operations for
117 basic instructions.
Programs must be coded in machine language
before they can be run by the 8088. However,
programs are normally written in 8088 assembly
language or a high-level language such as C.
A single machine language instruction can take one
to six bytes of code.

611 37100 Lecture 03-3

PAGE

,132

COMMENT *This program moves a block of specified number of bytes


from one place to another place*
;Define constants used in this program
N
=
16
BLK1ADDR=
100H
BLK2ADDR=
120H
DATASEGADDR= 2000H
STACK_SEG
DB
STACK_SEG

SEGMENT
64 DUP(?)
ENDS

;Bytes to be moved
;Source block offset address
;Destination block offset addr
;Data segment start address
STACK 'STACK'

CODE_SEG
SEGMENT
'CODE'
BLOCK
PROC
FAR
ASSUME CS:CODE_SEG,SS:STACK_SEG

611 37100 Lecture 03-5

3.1 Software : The Microcomputer


Program
Assembly source program (continued)
;To return to DEBUG program put return address on the stack
PUSH DS
MOV AX, 0
PUSH AX
;Set up the data segment address
MOV AX, DATASEGADDR
MOV DS, AX
;Set up the source and destination offset adresses
MOV SI, BLK1ADDR
MOV DI, BLK2ADDR
;Set up the count of bytes to be moved
MOV CX, N
;Copy source block to destination block
NXTPT: MOV AH, [SI]
;Move a byte
MOV [DI], AH
INC
SI
;Update pointers
INC
DI
DEC CX
;Update byte counter
JNZ NXTPT
;Repeat for next byte
RET
;Return to DEBUG program
BLOCK
ENDP
CODE_SEG ENDS
END BLOCK
;End of program

611 37100 Lecture 03-6

3.1 Software : The Microcomputer


Program
Assembly language must be converted by an

3.1 Software : The Microcomputer


Program
Listing of an assembled program
Microsoft (R) Macro Assembler Version 6.11
BLOCK-MOVE PROGRAM

assembler to an equivalent machine language


program for execution by the 8088.
A directive is a statement that is used to control the
translation process of the assembler.
e.g.

Segments and Groups:


Name

The machine language output produced by the

assembler is called object code.


Listing of the assembled program
0013 8A 24 NXTPT: MOV AH, [SI] ; Move a byte

611 37100 Lecture 03-7

3.1 Software : The Microcomputer


Program
Listing of an assembled program
microsoft (R) Macro Assembler Version 6.11
12/14/02 15:10:26
BLOCK-MOVE PROGRAM
Page 1 - 1
TITLE BLOCK-MOVE PROGRAM
PAGE ,132
COMMENT *This program moves a block of specified number of bytes
from one place to another place*
;Define constants used in this program
= 0010
N
=
16
;Bytes to be moved
= 0100
BLK1ADDR=
100H
;Source block offset address
= 0120
BLK2ADDR=
120H
;Destination block offset addr
= 2000
DATASEGADDR= 2000H
;Data segment start address
0000
0000 0040 [
00

STACK_SEG
SEGMENT
DB
64 DUP(?)

3.1 Software : The Microcomputer


Program
Listing of an assembled program
0000 1E
0001 B8 0000
0004 50
0005 B8 2000
0008 8E D8
000A BE 0100
000D BF 0120
0010 B9 0010
0013
0015
0017
0018
0019
001A
001C
001D
001D

8A 24
88 25
46
47
49
75 F7
CB

;To return to DEBUG program put return address on the stack


PUSH DS
MOV AX, 0
PUSH AX
;Set up the data segment address
MOV AX, DATASEGADDR
MOV DS, AX
;Set up the source and destination offset adresses
MOV SI, BLK1ADDR
MOV DI, BLK2ADDR
;Set up the count of bytes to be moved
MOV CX, N
;Copy source block to destination block
NXTPT:
MOV AH, [SI]
;Move a byte
MOV [DI], AH
INC SI
;Update pointers
INC DI
DEC CX
;Update byte counter
JNZ NXTPT
;Repeat for next byte
RET
;Return to DEBUG program
BLOCK
ENDP
CODE_SEG
ENDS
END BLOCK
;End of program

611 37100 Lecture 03-9

Attr
0100h
0120h
2000h
0013
0010h

Private 'CODE'
Stack
'STACK'

CODE_SEG

Length= 001D

CODE_SEG

Assembly language versus high-level language

It is easier to write program with high-level


language.
Program written in assembly language usually
takes up less memory space and executes much
faster.
Device service routines are usually written in
assembly language.
Assembly language is used to write those parts of
the application that must perform real-time
operations, and high-level language is used to
write those parts that are not time critical.

STACK 'STACK'

Attr
0000

Combine Class

3.1 Software : The Microcomputer


Program

STACK_SEG
ENDS
CODE_SEG
SEGMENT
'CODE'
BLOCK
PROC
FAR
ASSUME CS:CODE_SEG,SS:STACK_SEG

611 37100 Lecture 03-8

Para
Para

611 37100 Lecture 03-10

]
0040
0000
0000

Length Align

CODE_SEG . . . . . . . . . . . .16 Bit 001D


STACK_SEG . . . . . . . . . . 16 Bit 0040
Procedures, parameters and locals:
Name
Type Value
BLOCK . . . . . . . . . . . . .
P Far
Private
Symbols:
Name
Type Value
BLK1ADDR . . . . . . . . . . . .
Number
BLK2ADDR . . . . . . . . . . . .
Number
DATASEGADDR . . . . . . . . . . Number
NXTPT . . . . . . . . . . . . .
L Near
N ...............
Number
0 Warnings
0 Errors

DB 64 DUP(?)

e.g.

Size

12/14/02 15:10:26
Symbols 2 - 1

611 37100 Lecture 03-11

3.2 Assembly Language Programming


Development on the PC

Describing the problem


Planning the solution
Coding the solution with assembly language
Creating the source program
Assembling the source program into an
object module
Producing a run module
Verifying the solution
Programs and files involved in the program
development cycle
611 37100 Lecture 03-12

3.2 Assembly Language Programming


Development on the PC

3.2 Assembly Language Programming


Development on the PC
Begin
(Enter block move)

Program development cycle


Given problem

Establish data segment,


Source and destination
Pointers, and count of bytes

Describe problem
Move an element from
source to destination block

Plan steps of
solution
Flowchart

Increment source and


destination pointer,
decrement count

Implement flowchart
using assembler language
Hand-written source program
No

Enter/edit source program


using the editor

611 37100 Lecture 03-13

3.2 Assembly Language Programming


Development on the PC

All elements
Moved?
Yes

Assembler source program file


Assemble the program
using the assembler

End
(Return to DEBUG)

Flow chart of a block-move program


611 37100 Lecture 03-16

3.2 Assembly Language Programming


Development on the PC

Program development cycle


Begin/end
Subroutine
Yes
Syntax errors?
Input/output
No

Object module
Connection
within
a flowchart

Link the program


using LINK
Executable run module

Process

Execute and debug


using DEBUG

Connection
to another
flowchart

Decision

Yes
Logic errors?
No

Commonly used flowchart symbols


Solution to problem

611 37100 Lecture 03-14

611 37100 Lecture 03-17

3.2 Assembly Language Programming


Development on the PC

3.2 Assembly Language Programming


Development on the PC

Describing the problem


Most applications are described with a written
document called an application specification.

Coding the solution with assembly language


Two types of statements are used in the source
program

Planning the solution


A flow chart is an outline that both documents the
operations that must be performed by software to
implement the planned solution and shows the
sequence in which they are performed.

611 37100 Lecture 03-15

The assembly language instructions


The directives

The assembly language instructions are used


to tell the microprocessor what operations are to
be performed to implement the application.
A directive is the instruction to the assembler
program used to convert the assembly language
program into machine code.

611 37100 Lecture 03-18

3.2 Assembly Language Programming


Development on the PC

3.2 Assembly Language Programming


Development on the PC

Coding the solution with assembly language


The assembly language instructions
[Example]
MOV
MOV
MOV
MOV
MOV

Handwritten
source program
EDIT
Editor program
PROG1.ASM

AX, DATASEGMENT
DS, AX
SI, BLK1ADDR
DI, BLK2ADDR
CX, N

MASM
Assembler program
PROG1.OBJ
Libraries

The directive
[Example]

LINK
linker program

PROG1.LST
Other.OBJ files

PROG1.EXE
DEBUG
Debug program

BLOCK

PROC

BLOCK

ENDP

FAR

Final debugged
run module

or

611 37100 Lecture 03-19

The development programs and users files

3.2 Assembly Language Programming


Development on the PC
Creating the source program
The EDIT editor
The Notepad editor in Windows
The Microsoft PWB (Programmers Work Bench)
Assembling the source program into an

object module
The Microsoft MASM assembler
The Microsoft PWB (Programmers Work Bench)
The assembler source file and the object
module

611 37100 Lecture 03-20

PROG1.MAP

3.2 Assembly Language Programming


Development on the PC
Producing a run module
The object module must be processed by the
LINK program to produce an executable run
module.
Verifying the solution
Programs and files involved in the program

611 37100 Lecture 03-22

3.3 The Instruction Set


The instruction set of a microprocessor defines the

basic operations that a programmer can specify to


the device to perform
Instruction set groups
Data transfer instructions
Arithmetic instructions
Logic instructions
String manipulation instructions
Control transfer instructions
Processor control instructions

611 37100 Lecture 03-23

3.3 The Instruction Set


Data transfer instructions

development cycle
PROG1.ASM
PROG1.OBJ
PROG1.LST
PROG1.EXE
PROG1.MAP

(Editor)
(Assembler)
(Assembler)
(Linker)
(Linker)

611 37100 Lecture 03-21

611 37100 Lecture 03-24

3.3 The Instruction Set

3.3 The Instruction Set

Data transfer instructions

Logic instructions

611 37100 Lecture 03-25

611 37100 Lecture 03-28

3.3 The Instruction Set

3.3 The Instruction Set

Arithmetic instructions

String manipulation instructions

611 37100 Lecture 03-26

611 37100 Lecture 03-29

3.3 The Instruction Set

3.3 The Instruction Set

Arithmetic instructions

Control transfer instructions

611 37100 Lecture 03-27

611 37100 Lecture 03-30

3.3 The Instruction Set

3.4 The MOV Instruction

Control transfer instructions

The move (MOV) instruction is used to transfer a byte

or a word of data from a source operand to a


destination operand.
Mnemonic

Meaning

Format

Operation

Flags affected

MOV

Move

MOV D, S

(S) (D)

None

e.g.

MOV DX, CS
MOV [SUM], AX

611 37100 Lecture 03-31

611 37100 Lecture 03-34

3.3 The Instruction Set

3.4 The MOV Instruction

Control transfer instructions

Note that the MOV instruction cannot transfer data

directly between external memory.


Destination

Source

Memory

Accumulator

Accumulator

Memory

Register

Register

Register

Memory

Memory

Register

Register

Immediate

Memory

Immediate

Seg-reg

Reg16

Seg-reg

Mem16

Reg16

Seg-reg

Memory

Seg-reg

Allowed operands for MOV instruction

611 37100 Lecture 03-32

3.3 The Instruction Set

611 37100 Lecture 03-35

3.4 The MOV Instruction


MOV DX, CS

Process control instructions


0100

IP

0100
0200

CS
DS
SS
ES

XXXX

AX
BX
CX
DX

Address Memory
Content
01100
01101
01102

8C
CA
XX

02000
02001

XX
XX

Instruction

MOV DX, CS
Next instruction

SP
BP
SI
DI

8088/8086 MPU
Before execution

611 37100 Lecture 03-33

611 37100 Lecture 03-36

3.4 The MOV Instruction

3.5 Addressing Modes


Register operand addressing mode

MOV DX, CS

Address

0102

IP

0100
0200

CS
DS
SS
ES
AX
BX
CX
DX

0100

Address Memory
Content
01100
01101
01102

8C
CA
XX

02000
02001

XX
XX

Instruction

MOV DX, CS

0000
0100

Next instruction

XXXX
ABCD

SP
BP
SI
DI

IP
CS
DS
SS
ES

01000
01001
01002

Memory
Content
8B
C3
XX

Instruction

MOV AX, BX
Next instruction

AX
BX
CX
DX
SP
BP
SI
DI

8088/8086 MPU

8088/8086 MPU

After execution

611 37100 Lecture 03-37

3.5 Addressing Modes

Before execution

611 37100 Lecture 03-40

3.5 Addressing Modes


Register operand addressing mode

Register operand addressing mode


Immediate operand addressing mode
Memory operand addressing mode
Direct addressing mode
Register indirect addressing mode
Based addressing mode
Indexed addressing mode
Based-indexed addressing mode

Address

0002

IP

0100

CS
DS
SS
ES

ABCD
ABCD

01000
01001
01002

Memory
Content
8B
C3
XX

Instruction

MOV AX, BX
Next instruction

AX
BX
CX
DX
SP
BP
SI
DI

8088/8086 MPU

611 37100 Lecture 03-38

After execution

611 37100 Lecture 03-41

3.5 Addressing Modes

3.5 Addressing Modes

Register operand addressing mode

Immediate operand addressing mode

The operand to be accessed is specified as residing in an


internal register of 8088.
e.g.
MOV AX, BX
Register

0100

Operand Sizes
Byte (Reg 8)

Word (Reg 16)

Accumulator

AL, AH

AX

Base

BL, BH

BX

Count

CL, CH

CX

Data

DL, DH

DX

Stack pointer

SP

Base pointer

BP

Source index

Destination index

DI

Code segment

CS

Data segment

DS

Stack segment

SS

Extra segment

ES

611 37100 Lecture 03-39

Address

0000

SI

XX

IP
CS
DS
SS
ES

01000
01001
01002
01003

Memory
Content
B0
15
XX
XX

Instruction

MOV AL, 15H


Next instruction

AX
BX
CX
DX
SP
BP
SI
DI

8088/8086 MPU
Before execution
611 37100 Lecture 03-42

3.5 Addressing Modes

3.5 Addressing Modes

Immediate operand addressing mode


Address

0002

IP

0100

15

0000
MOV AL, 15H
Next instruction

AX
BX
CX
DX

0100
0200

XXXX

SP
BP
SI
DI

Instruction

8B
0E
34
12
XX

MOV CX, [1234H]

02000
02001
.
.
.
.
03234
03235

XX
XX

IP
CS
DS
SS
ES
AX
BX
CX
DX
SP
BP
SI
DI

8088/8086 MPU

Memory
Content

01000
01001
01002
01003
01004

Address

Instruction

B0
15
XX
XX

01000
01001
01002
01003

CS
DS
SS
ES

Memory addressing modes - Direct addressing mode

Memory
Content

Next instruction

ED
BE

Source operand

8088/8086 MPU

After execution

611 37100 Lecture 03-43

Before execution

611 37100 Lecture 03-46

3.5 Addressing Modes

3.5 Addressing Modes

Memory addressing modes

Memory addressing modes - Direct addressing mode

To reference an operand in memory, the 8088 must calculate


the physical address (PA) of the operand and then initiate a
read or write operation to this storage location.
Physical Address (PA) = Segment Base Address (SBA) + Effective Address (EA)

IP

0100
0200

CS
DS
SS
ES

PA = Segment Base : Base + Index + Displacement

CS
SS
PA= DS
ES

BX
BP

SI
DI

8-bit displacement
16-bit displacement

EA = Base + Index + Displacement


Physical and effective address computation for memory operands

611 37100 Lecture 03-44

Memory
Content

Instruction

01000
01001
01002
01003
01004

8B
0E
34
12
XX

MOV CX, [1234H]

02000
02001
.
.
.
.
03234
03235

XX
XX

Address

0004

BEED

AX
BX
CX
DX
SP
BP
SI
DI

Next instruction

ED
BE

Source operand

8088/8086 MPU
After execution

611 37100 Lecture 03-47

3.5 Addressing Modes

3.5 Addressing Modes

Memory addressing modes - Direct addressing mode

Memory addressing modes Register indirect addressing mode

PA = Segment Base : Direct Address

PA = Segment Base : Direct Address

CS
SS
PA= DS
ES

SS
BP
PA= DS : SI

CS

: Direct address

BX

ES

DI

The default segment register is DS

The default segment register is DS

Computation of a direct memory address

Computation of an indirect memory address

e.g.

MOV AX, [1234H]

611 37100 Lecture 03-45

e.g.

MOV AX, [SI]

611 37100 Lecture 03-48

3.5 Addressing Modes

3.5 Addressing Modes

Memory addressing modes - Register indirect addressing mode

Memory addressing modes - Based addressing mode

PA = 0200016 + 123416 = 0323416


0000

IP

0100
0200

CS
DS
SS
ES

XXXX

AX
BX
CX
DX

01000
01001
01002

02000
02001
.
.
.
.
03234
03235

SP
BP
SI
DI

1234

PA = 0200016 + 100016 + 123416 = 0423416

Address Memory
Content
8B
04
XX

0000
MOV AX, [SI]
Next instruction

IP

0100
0200

CS
DS
SS
ES

BE ED
1000

AX
BX
CX
DX

XX
XX

ED
BE

Address Memory
Content

Instruction

SP
BP
SI
DI

Source operand

8088/8086 MPU

8088/8086 MPU

Before execution

611 37100 Lecture 03-49

01000
01001
01002
01003
01004

88
87
34
12
XX

02000
02001
.
.
.
.
04234
04235

XX
XX

XX
XX

Before execution

Instruction

MOV [BX]+1234H, AL

Next instruction

Destination operand

611 37100 Lecture 03-52

3.5 Addressing Modes

3.5 Addressing Modes

Memory addressing modes - Register indirect addressing mode

Memory addressing modes - Based addressing mode

PA = 0200016 + 123416 = 0323416


0002

IP

0100
0200

CS
DS
SS
ES

BEED

AX
BX
CX
DX

01000
01001
01002

02000
02001
.
.
.
.
03234
03235

SP
BP
SI
DI

1234

PA = 0200016 + 100016 + 123416 = 0423416

Address Memory
Content
8B
04
XX

0004
MOV AX, [SI]
Next instruction

IP

0100
0200

CS
DS
SS
ES

BE ED
1000

AX
BX
CX
DX

XX
XX

ED
BE

Address Memory
Content

Instruction

SP
BP
SI
DI

Source operand

8088/8086 MPU

8088/8086 MPU

After execution

611 37100 Lecture 03-50

01000
01001
01002
01003
01004

88
87
34
12
XX

02000
02001
.
.
.
.
04234
04235

XX
XX

ED
XX

After execution

Instruction

MOV [BX]+1234H, AL

Next instruction

Destination operand

611 37100 Lecture 03-53

3.5 Addressing Modes

3.5 Addressing Modes

Memory addressing modes - Based addressing mode

Memory addressing modes - Indexed addressing mode


PA = Segment Base : Index + Displacement

CS
SS
PA= DS
ES

: BX
BP

8-bit displacement
+ 16-bit displacement

CS
SS
SI
PA= DS : DI
ES

Memory

Memory

Element n
Element
n-1

Element n
Element n-1

Displacement

Array of data

Element
2
Element 1
Element 0

Displacement

Array of data

Element 2
Element 1
Element 0

Base register

Index register

Computation of a based address

e.g.

8-bit displacement

+ 16-bit displacement

Computation of an indexed address

MOV [BX]+1234H, AL

611 37100 Lecture 03-51

e.g.

MOV AL, [SI]+1234H

611 37100 Lecture 03-54

3.5 Addressing Modes

3.5 Addressing Modes

Memory addressing modes - Indexed addressing mode

Memory addressing modes - Based-indexed addressing mode

PA = 0200016 + 200016 + 123416 = 0523416


0000

IP

0100
0200

AX
BX
CX
DX

Instruction

0000
MOV AL, [SI]+1234H

CS
DS
SS
ES

XX XX
1000

AX
BX
CX
DX

2000
BE

Source operand

8088/8086 MPU

IP

0100
0200

Next instruction

XX
XX

02000
02001
.
.
.
.
05234

SP
BP
SI
DI

2000

8A
84
34
12
XX

01000
01001
01002
01003
01004

CS
DS
SS
ES

XX XX

PA = 0200016 + 100016 + 200016 + 123416 = 0623416

Address Memory
Content

SP
BP
SI
DI

Address Memory
Content
01000
01001
01002
01003
01004

8A
A0
34
12
XX

02000
02001
.
.
.
.
06234

XX
XX

BE

Instruction

MOV AH,
[BX][SI]+1234H

Next instruction

Source operand

8088/8086 MPU

Before execution

611 37100 Lecture 03-55

Before execution

611 37100 Lecture 03-58

3.5 Addressing Modes

3.5 Addressing Modes

Memory addressing modes - Indexed addressing mode

Memory addressing modes - Based-indexed addressing mode

PA = 0200016 + 200016 + 123416 = 0523416


0004

IP

0100
0200

CS
DS
SS
ES

XX BE

AX
BX
CX
DX

8A
84
34
12
XX

01000
01001
01002
01003
01004

Instruction

0004
MOV AL, [SI]+1234H

CS
DS
SS
ES

BE XX
1000

AX
BX
CX
DX

Next instruction

2000
BE

Source operand

8088/8086 MPU

IP

0100
0200

XX
XX

02000
02001
.
.
.
.
05234

SP
BP
SI
DI

2000

PA = 0200016 + 100016 + 200016 + 123416 = 0623416

Address Memory
Content

SP
BP
SI
DI

Address Memory
Content
01000
01001
01002
01003
01004

8A
A0
34
12
XX

02000
02001
.
.
.
.
06234

XX
XX

BE

Instruction

MOV AH,
[BX][SI]+1234H

Next instruction

Source operand

8088/8086 MPU

After execution

611 37100 Lecture 03-56

After execution
611 37100 Lecture 03-59

3.5 Addressing Modes


Memory addressing modes -

Based-indexed addressing mode

PA = Segment Base : Base + Index + Displacement


CS
SS
DS
ES

PA=

BX

SI

: BP

+ DI

8-bit displacement
16-bit displacement

Memory
Element (m,n)

Element (m,1)
Element (m,0)

Element (1,1)
Element (1,0)
Element (0,n)

Element (0,1)
Element (0,0)

Index register
+
Base register
+
Displacement

Two dimensional
Array of data

Computation of an indexed address

e.g.

MOV AH, [BX][SI]+1234H

611 37100 Lecture 03-57

10

You might also like