addressing modes&instructions

Post on 05-Apr-2018

228 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 1/122

1

8086 Addressing Modes

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 2/122

2

What is the Addressing Mode

?add dest, source ; dest +source→dest 

add ax,bx ; ax +bx→ax 

The addressing mode means where and how

the CPU gets the operands when theinstruction is executed.

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 3/122

3

• Addressing modes for Sequential Control

Transfer Instructions----These Instructions transfer control to the

next sequential instruction in the program

• Addressing modes for Control TransferInstructions

-----These Instructions transfer control to

some predefined address Ex:INT CALL

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 4/122

4

Addressing modes for Sequential Control

Transfer Instructions Three types of 8086 addressing modes

• Immediate Addressing Mode

---CPU gets the operand from the instruction • Register Addressing Mode

---CPU gets the operand from one of the internal registers

• Memory Addressing Mode---CPU gets the operand from the memory location(s)

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 5/122

5

Exp

MOV AL, 80H

Machine code:B080H

ALB0H

80H

Instruction Queue

MACHINE

CODE

B8

12H

Instruction Queue

AL

MACHINE

CODE

AH

34H

12

3480H

80H

12  34

1. Immediate Addressing Mode

MOV AX, 1234H

Machine Code:B83412H

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 6/122

6

Exp:MOV AX, CX 

89

C1

Memory

AX

CX Machine code

2. Register Addressing

Mode

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 7/1227

• Specify an offset address (effective address) using expressions of the form (different parts of expression are optional):

 –  [ Base Register + Index Register+ Displacement]

• 1) Base Register---BX, BP• 2) Index Register---SI, DI

• 3) Displacement ---constant value

• Example: 1) add ax,[20h] 2) add ax,[bx]

3) add ax,[bx+20h] 4) add ax, [bx+si]5) add ax, [bx+si+20h]

3. Memory Addressing Mode

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 8/1228

⑴ Direct Addressing Mode

Exp: MOV AL, [1064H]

Machine code:A06410H

• The offset address of the operand is provided in theinstruction directly;

• The physical address can be calculated using thecontent of DS and the offset :

PA = (DS)*10H+Offset

3. Memory Addressing Mode

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 9/1229

⑴ Direct Addressing ModeExample: MOV AL, [1064h] ;Assume (DS)=2000H

Machine code: A06410H

21064H

(DS)*10H=20000H

20000H

21064H

AL

A0

64

10

45

… 

Code

Segment

Data

Segment

45

45

+ 1064H

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 10/12210

⑵ Register Indirect Addressing Mode

• The address of memory location is in a register

(SI,DI,or BX only)

• The physical address is calculated using the content of DS

and the register(SI,DI,BX)

PA = (DS)*10H+(SI)/(DI)/(BX)

3. Memory AddressingMode

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 11/12211

50

40

 …  … 

M

AX

⑵ Register Indirect Addressing Mode

ASSUME: (DS)=3000H, (SI)=2000H, (BX)=1000H

30000H

(DS)*10H=30000H

(SI)= 2000H+

32000H

32000H

40  50

50

40

 …  … 64H

M

AL 30000H

(DS)*10h= 30000H

(BX)= 1000H+

31000H

31000H64H

64H

MOV [BX], ALMOV AX, [SI]

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 12/12212

⑶ Register Relative Addressing

EA=

(BX)

(BP)

(DI)

(SI)

+ Displacement

For physical address calculation:DS is used for BX,DI,SI;SS is used for BP

PA=(DS)*10H+(BX)/(DI)/(SI)+Disp

ORPA=(SS)*10H+(BP)+Disp

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 13/12213

⑶ Register Relative AddressingMOV CL, [BX+1064H] ;assume: (DS)=2000h, (bx)=1000h

;Machine Code: 8A8F6410

22064H

22064H

8F

64

10

45

… 

CodeSegment

Data

Segment

8A

… 

CL

45

45 21000H

(BX)= 1000H

(DS)*10h= 20000H

20000H

+ 1064H

PA=(ds)*10h+(bx)+1064h

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 14/12214

⑷ Based Indexed Addressing

EA=(BX)(BP)

+(DI)(SI)

• Base register(bx or bp) determines which segment(data or

stack) the operand is stored;• if using BX, the operand is defaultly located in Datasegment,then:

PA=(DS)*10H+(BX)+(DI)/(SI)

• if using BP, the operand is defaultly located in stack segment,then: 

PA=(SS)*10H+(BP)+(DI)/(SI)

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 15/12215

⑷ Based Indexed Addressing

Example: MOV AH, [BP][SI];Assume(ss)=4000h,(bp)=2000h,(si)=1200h

56H

 … 

 … 

M

AH 40000H

(SS)*10H= 40000H

(BP)= 2000H+

43200H

43200H

(SI)= 1200H

56H

56H

PA=(ss)*10h+(bp)+(si)

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 16/12216

⑸ Based Indexed Relative Addressing

EA= (BX)(BP)

+ (DI)(SI)

+ Displacement

if using BX, the operand is defaultly located in Datasegment,then:

PA=(DS)*10H+(BX)+(DI)/(SI)+disp

if using BP, the operand is defaultly located in stack segment,then: 

PA=(SS)*10H+(BP)+(DI)/(SI)+disp

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 17/12217

⑸ Based Indexed Relative Addressing

MOV [BX+DI+1234H], AH;assume (ds)=4000h,(bx)=0200h,(di)=0010h

;machine code:88A13412hA1

34

12

… 

Code

segment

Data

segment

88

… 

45AH

40000H

(DS)*10H=40000H

(BX)= 0200H

+(DI)= 0010H

1234H

45

45

41444H

41444H

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 18/12218

Summary on the 8086 memory addressing modes 

operand offset address Default Overridden

(effective address)  Segment Register Segment Register 

3. Register [SI/DI/BX/BP+disp] (SI)/(DI)/(BX)/(BP)+disp  DS CS ES SS

Relative Addressing

2. Register [BX]/[SI] /[DI] Content of the R DS CS ES SS

Indirect Addressing 

1. Direct Addressing [disp] disp DS CS ES SS

4. Based Indexed [BX+SI/DI] (BX)+disp  DS CS ES SS

Addressing [BP+SI/DI] (BP)+disp  SS CS ES DS

5. Based Indexed [BX+SI/DI+disp] (BX)+(SI)/(DI)+disp  DS CS ES SS

Relative Addressing [BP+SI/DI+disp] (BP)+(SI)/(DI)+disp  SS CS ES DS

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 19/12219

Examples:

Assume: (BX)=6000H, (BP)=4000H, (SI)=2000H,(DS)=3000H, (ES)=3500H, (SS)=5000H

3000:0520 30520HDirect Addressing

2. MOV AX, [BX]

1. MOV AX, [0520H]

5. MOV AX, ES: [BX+SI+0050H]

4. MOV AX, [BP+6060H]

Register Indirect Addressing 3000:6000 36000H

Register Relative Addressing 

Register Relative Addressing

3. MOV AX, [SI+1000H] 3000:3000 33000H

5000:A060 5A060H

3500:8050 3D050HBased Indexed Relative

Addressing

Instruction addressing  logical physicalmode  address address

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 20/12220

•Addressing modes for Control Transfer

Instructions

Modes for ControlTransfer Instructions

Inter-segment

Intra-segment

Inter-segment-In Direct

Inter-segment-Direct

Intra-segment Direct

Intra-segment Indirect

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 21/122

21

Inter-segment-Direct Addressing ModeThe address to which control is to be transferred lies in the different

segment and appears directly In the instruction as an immediatedisplacement value w.r.t IP If the displacement is8-bits(-128<d<+127)(short) If the displacement is16-bits(-32768<d<+32767)(Long)

Ex: CALL 0020:0010H

segment1

CS

Assume CS=2000h,IP=0000h

After JMP,CS= 0020h,IP=0010h

segment2

IP

20

00

10

Sub-routine

… 

00

… 

0020

Op-code for CALL

0010

2000hCS

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 22/122

22

Inter-segment-IN-Direct Addressing ModeThe address to which control is to betransferred

lies in the different \segment and it ispassed to theinstruction indirectly i.e contents of amemory blockcontaining four bytesIP(LSB),IP(MSB),CS(LSB),CS(MSB)

Ex: CALL [BX]

IP(LSB)10

IP(MSB)00 

CS(LSB)20 

Sub-routine

… 

segment1

… 

0020CS

Before JMP,Assume BX=100h, CS=3000h,IP=200h

Op-code for CALL

After JMP,CS= 0020h,IP=0010h

segment2

0010IP

3000hCS

CS(MSB)00 

0010IP

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 23/122

23

Intra-segment-Direct Addressing ModeThe address to which control is to be transferred lies in the samesegment and appears directly In the instruction as an immediate

displacement value w.r.t IP If the displacement is8-bits(-128<d<+127)(short) If the displacement is16-bits(-32768<d<+32767)(Long)

Ex: CALL 500h

CodeSegment

Assume CS=2000h,IP=0000h

After CALL,CS= 2000h,IP=IP+500h

IP

00

05

Op-code for CALL2000hCS

0500Sub-routine

0000IP

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 24/122

24

IP

Intra-segment-In-Direct Addressing ModeIn this mode the displacement to which control is to be transferred,Is in the same segment in which the control transfer instruction lies

But it is passed to the instruction indirectly

Ex: CALL [BX]

CodeSegment

Assume CS=2000h,IP=0000h , BX=800h

After CALL,CS= 2000h,IP=IP+800h

IP

00

05

Op-code for CALL2000hCS

0800Sub-routine

0000IP

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 25/122

25

Example:The Contents of different registers are given below. Form effective addresses fordifferent addressing modes

Offset(displacement)= 5000HAX=1000H,BX=2000H,SI=3000H,DI=4000H,BP=5000H,SP=6000H,CS=0000H,DS=1000HSS=2000H,IP=7000HShifting a number four times is equivalent to multiplying it by 16D or 10H 

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 26/122

26

Instruction Set

&Assembler Directives

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 27/122

27

Programming in 8088/8086 Three levels of languages available to program a microprocessor:

Machine Languages , Assembly Languages , and High-level 

Languages .

Machine Language

A sequence of binary codes for the instruction to be executed by

microcomputers.

Long binary bits can be simplified by using Hexadecimal format

It is difficult to program and error prone.

Different uP (micro-processor) uses different machine codes.

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 28/122

28

Programming in 8088/8086 (cont.)

Assembly Language

To simplify the programming, assembly language (instead of machine language) isused.

Assembly language uses 2- to 4-letter mnemonics to represent each instructiontype. E.g. “Subtraction” is represented by SUB

Four fields in assembly language statement:

Label , OP Code , Operand and Comment fields.

Programs will be „translated‟ into machine language, by Assembler, so it can beloaded into memory for execution.

High-Level Language

High level languages, like C , Basic or Pascal , can also be used to program

microcomputers.

An interpreter or a compiler is used to „translate‟ high level language statement tomachine code. High level language is easier to read by human and is more suitablewhen the programs involves complex data structures.

Assemblers

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 29/122

29

Assemblers

Programming the instructions directly in machine code is possible butevery machine codes depending on how the data is stored.

The process of converting the microprocessor instructions to thebinary machine code can be performed automatically by a computerprogram, called an ASSEMBLER. Popular assemblers include IBMmacro Assembler, Microsoft Macro Assembler (MASM) and BorlandTurbo Assembler(installed on IE NT Network).

Most assemblers accept an input text file containing lines with arigorously defined syntax split into four fields.

Not all fields need to be present in a line. Eg. A line can be just acomment line if it starts with semicolon;

Source Codes Object Codes and Linking

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 30/122

30

Source Codes, Object Codes and Linking

Source code is the text written by the programmerin assembly language

(or any other programming language)

 Object code is the binary code obtained afterrunning the assembler (

Or compiler if the source is in a high level language).

 Modules of a program may be written separatelyand linked together to

form a executable program using a linker.

 The linker joins the object code of the different

modules into one largeobject file which is executable. Most assemblers onIBM PCs produce

object files which must be linked ( even if there areno separate modules).

Source Codes, Object Codes and Linking(Contd.,)

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 31/122

31

Source Codes, Object Codes and Linking(Contd.,)

Fields in Assembler

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 32/122

32

Fields in Assembler  

<label> <Mnemonic or directive> <operands> <;comment>

Comment field contains internal program documentation to improve

human readability -use meaningful comments

Operand field contains data or address used by the instruction.

The following conventions typically apply:

Fields in Assembler (Contd )

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 33/122

33

Fields in Assembler (Contd.,) 

<label> <Mnemonic or directive> <operands><;comment>

Mnemonic/directive field contains the abbreviation forthe processor instruction (eg. MOV) or an assemblerDIRECTIVE. Adirective produces no object code but isused to control how the assembler operates.

Examples of directives include:

END -indicate the end of a program listing,

FRED LABEL NEAR - define “FRED” as a near label

TOM EQU 1000H -define “TOM” as the number 1000H

Label field contains a label which is assigned a valueequal to the address where the label appears.

Why Program in Assembler?

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 34/122

34

Why Program in Assembler? 

Assembler language instruction has a one-to-onecorrespondence with the binary machine code: theprogrammer controls precisely all the operations performedby the processor (a high level language relies on a compileror interpreter to generate the instructions).

 Assembler can generate faster and more compactprograms

 Assembler language allows direct access and full controlof input/output operations

 However, high-level language programs are easier towrite and develop than assembler language programs

Advantages of High-level languages

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 35/122

35

Advantages of High level languages 

Block structure code: programs are most readable when

they arebroken into “logical blocks” that perform specific function.

Productivity: easier to program

Level of complexity: no need to know the hardware details

Simple mathematics formula statement

Portability: only need to change the compiler when it isported to other machine

Abstract data types: different data types like floating-pointvalue,

record and array, and high precision value.

Readabilit

Intel 8086 Instruction Set Overview

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 36/122

36

Intel 8086 Instruction Set Overview

Intel 8088 has ninety basic ( ie not counting

addressing mode

variants) instructions

Instructions belong to one of the following groups:data

transfer, arithmetic, logic, string manipulation,control

transfer and processor control.

C i A bl L I i

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 37/122

37

Converting Assembly Language Instructions to

Machine Code

• An instruction can be coded with 1 to 6 bytes

• Byte 1 contains three kinds of information – Opcode field (6 bits) specifies the operation (add, subtract, move)

 – Register Direction Bit (D bit) Tells the register operand in REG field in byte

2 is source or destination operand1: destination 0: source

-Data Size Bit (W bit) Specifies whether the operation will be performed on 8-

bit or 16-bit data

0: 8 bits 1: 16 bits

• Byte 2 has three fields

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 38/122

38

• Byte 2 has three fields

 –  Mode field (MOD)

 – Register field (REG) used to identify the register for the first operand 

 – Register/memory field (R/M field) 

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 39/122

39

2-bit MOD field and 3-bit R/M field together

specify the second operand

Mode Field encoding

Register/memory (R/M) Field Encoding

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 40/122

40

Examples 

MOV BL,AL (88C316)

Opcode for MOV = 100010

D = 0 (AL source operand)

W bit = 0 (8-bits)

Therefore byte 1 is 100010002=8816

• MOD = 11 (register mode) 

• REG = 000 (code for AL) 

• R/M = 011 (destination is BL) 

Therefore Byte 2 is 110000112=C316

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 41/122

41

Examples:

MOV BL, AL = 10001000 11000011 = 88 C3h

ADD AX, [SI] = 00000011 00000100 = 03 04 h

ADD [BX] [DI] + 1234h, AX = 00000001 10000001 __ __ h =

01 81 34 12 h

Intel 8086 Instruction Set Overview

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 42/122

42

I. Data Movement Instructions (14)

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 43/122

43

(abbreviations below: d=destination, s=source)

General Data Movement Instructions

MOV d,s - moves byte or word; most commonly used instructionPUSH s - stores a word (register or memory) onto the stack

POP d - removes a word from the stack

XCHG d,s - exchanges data, reg.-reg. Or memory to register

XLAT - translates a byte using a lookup table (has no operands)

IN d,s - moves data (byte or word) from I/O port to AX or AL

OUT d,s - moves data (byte or word) from AX or AL to I/O port

LEA d,s - loads effective address (not data at address) into register

LDS d,s - loads 4 bytes (starting at s) to pointer (d) and DS

LES d,s - loads 4 bytes (starting at s) to pointer (d) and ES

LAHF - loads the low-order bytes of the FLAGS register to AH

SAHF - stores AH into the low-order byte of FLAGS

PUSHF - copies the FLAGS register to the stack

POPF - copies a word from the stack to the FLAGS register

( )

Instructions for moving strings

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 44/122

44

g g

String instructions are repeated when prefixed by the REP mnemonic (CXcontains the repetition count)

MOVS d,s - (MOVSB, MOVSW) memory to memory data transfer

LODS s - (LODSB and LODSW) copies data into AX or AH

STOS d - (STOSB, STOSW) stores data from AH or AX

Data movement using MOV 

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 45/122

45

g

MOV d, s

d=destination (register or effective memory address),

s=source (immediate data, register or memory address) MOV can transfer data from:

any register to any register (except CS register)

memory to any register (except CS)

immediate operand to any register (except CS)

any register to a memory location

immediate operand to memory

MOV cannot perform memory to memory transfers (must use a register as anintermediate storage).

MOV moves a word or byte depending on the operand bit-lengths; the source

and destination operands must have the same bit length.

MOV cannot be used to transfer data directly into the CS register.

The stack The stack

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 46/122

46

The stack is a block of memory reserved for temporary

storage of data and registers. Access is LAST-IN, FIRSTOUT (LIFO)

The last memory location used in the stack is given by theeffective

address calculated from the SP register and the SS register:

Example:

The stack

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 47/122

47

Data may be stored onto the stack using the PUSH

instruction  –this automatically decrements SP by 2 (allstack operations involve words).

The POP instruction removes data from the stack (andincrements SP by 2).

The stack may be up to 64K-bytes in length.

PUSH and POP instructions

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 48/122

48

Examples:

PUSH AX ;stores AX onto the stack

POP AX ;removes a word from the stack and loads it into AX

PUSHF ;stores the FLAGS register onto the stack

POPF ; removes a word from the stack and loads it into FLAGS

PUSH may be used with any register to save a word (the register 

contents) onto the stack. The usual order (e.g. as with MOV) of storing the lower order byte in the lower memory location is used.

PUSH may also be used with immediate data, or data in memory.

 POP is the inverse of the PUSH instruction; it removes a word

from the top of the stack. Any memory location or 16-bit register 

(except CS) may be used as the destination of a POP instruction.

PUSHF and POPF saves and loads the FLAGS register to/from the

stack,respectively.

Exchange Instruction (XCHG) 

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 49/122

49

XCHG exchanges the contents of two registers or a registerand memory. Both byte and word sized exchanges are

possible.

Examples:

XCHG AX,BX; exchange the contents of AX and BX

XCHG CL,BL; exchange CL and BL contents

XCHG DX,FRED; exchanges content of DX and memory

DS:FRED

 Memory to Memory exchanges using XCHG are NOT allowed.

Translate Instruction (XLAT)

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 50/122

50

Many applications need to quickly convert byte sized codes to other valuesmapping one byte value to another (e.g. mapping keyboard binary codes to ASCIIcode)

 XLAT can perform a byte translation using a look-up table containing up to 256elements

XLAT assumes that the 256-byte table starts at the address given by DS:BX (i.e.effective address formed by the DS and BX registers). AL is used as an index topoint to the required element in the table prior to the execution of XLAT. The resultof XLAT instruction is returned in the same register (AL).

Address Data Table

LEA &LDS

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 51/122

51

LEA loads the offset of a memory address into a 16-bit register. The offset addressmay be specified by any of the addressing modes.

Examples (with BP=1000H):

LEA AX,[BP+40H];=>SS:[1000H+40H] =SS:[1040H];load 1040H into AX

LEA BX,FRED; load the offset of FRED (in data segment) to BX

LEA CX,ES:FRED; loads the offset of FRED (in extra segment) to CX

LDS -Load data and DSLDS reads two words from the consecutive memory locations and loads them into thespecified register and the DS segment registers.

Examples (DS=1000H initially)

LDS BX,[2222H]; copies content of 12222H to BL, 12223H to BH, and 12224 and12225 to DS register

LDS is useful for initializing the SI and DS registers before a string operation. E.g.LDS SI, sting_pointer

The source for LDS can be displacement, index or pointer register (except SP).

LES -Load data and ES 

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 52/122

52

LES reads two words from memory and is very similar to LDS

except that the second word is stored in ES instead of DS.

LES is useful for initializing that DI and ES registers for stringsoperation.

Example (with DS=1000H):

LES DI, [2222H]; loads DI with contents stored at 12222H and12223H and loads ES with contents at 12224 and 12225H

LAHF, SAHF 

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 53/122

53

LAHF (load AH with the low-order byte of the FLAGSregister) and SAHF (Store AH into the low-order byte of theFLAG register)

very rarely used instructions -originally present to allowtranslation of 8085 programs to 8086.

IN, OUT

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 54/122

54

Examples:

IN AX, 0C8h ;reads port address at C8h (8 bit address) and loads into AX

IN AL, DX ;reads the port address given by DX and loads into AL

OUT p8 ,AX ;sends the data in AX to port p8

OUT DL, AX ; sends the data in AX to port given by DL

IN reads data from the specified IO port (8-bit or 16-bit wide) to the accumulator (

AL or AX).

 The IO port can be an immediate address (8-bit only) or specified by a variable

or register (8 or 16-bit address). (Seems only DX can be used.)

OUT sends data from the accumulator register to the specified I/O port. Both byte andword sized data may be sent using IN and OUT.

II. Arithmetic Instructions(20)

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 55/122

55

Intel 8088 has 20 instructions for performing integer addition,Subtraction , multiplication, division, and conversions from binary codeddecimal to binary.

Arithmetic Instructions (cont.)

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 56/122

56

Addition

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 57/122

57

Binary addition of two bytes or two words are performed using:

ADD d,s

ADD adds bytes or words in d and s and stores result in d.The operands d and s can use the same addressing modes as in

MOV.

Addition of double-word is achieved by using the carry bit in the

FLAGS register. The instruction

ADC d,s

automatically includes the carry flag, and is used to add the

more significant word in a double-word addition.

Addition

Example: addition of two double words stored at [x] and [y]MOV AX, [x] ; Loads AX with the word stored at location [x]MOV DX, [x+2] ; Loads the high order wordADD AX, [y] ; Adds the low order word at [y]ADC DX, [y+2] ; Add including the carry from the low order words

Addition (cont.)

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 58/122

58

Example: addition of two double words stored at [x] and [y]

Addition of binary coded decimal numbers (BCD) can be performedby using ADD or ADC followed by the DAA instruction to convert thenumber in register AL to a BCD representation. (see example)

Addition of numbers in their ASCII form is achieved by using AAA(ascii adjust after addition).

ASCII adjust for Addition (AAA)

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 59/122

59

ASCII codes for the numbers 0 to 9 are 30H to 39H respectively. The ascii adjust instructions convert the sum stored in AL to two-byte unpackBCD number which are placed in AX.

When 30H is added to each byte, the result is the ASCII codes of the digitsrepresenting the decimal for the original number in AL.Example: Register AL contains 31H (the ASCII code for 1), BL contains 39H (theASCII code for 9).ADD AL, BL ; produces the result 6AH which is kept in AL.AAA ; converts 6AH in AL to 0100H in AX

Addition of 30H to each byte of AX produces the result 3130H (the ASCII codefor 10 which is the result of 1+9)

Subtraction

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 60/122

60

Multiplication

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 61/122

61

Division

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 62/122

62

SIGN EXTENDED INSTRUCTIONS

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 63/122

63

Other Arithmetic Instructions

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 64/122

64

III. Logic and bit MANIPULATION Instructions (12)

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 65/122

65

III. Logic and bit MANIPULATION Instructions (12) (Contd)

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 66/122

66

Shift and Rotate

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 67/122

67

Shift and Rotate(Contd)

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 68/122

68

packed BCD from two ASCII characters

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 69/122

69

IV. Strings Instruction (6)

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 70/122

70

IV. Instruction for moving strings(Contd)

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 71/122

72

REP prefix

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 72/122

73

LODS and STOS string instructions

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 73/122

74

LODS and STOS string instructions(Contd)

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 74/122

75

CMPS and SCAS string instructions

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 75/122

76

V. Program Flow Instruction

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 76/122

77

Program Flow Instruction

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 77/122

78

Unconditional JUMP

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 78/122

79

Unconditional JUMP (cont.)

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 79/122

80

List file of program Demonstrating “backward” JMP 

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 80/122

81

List file of program demonstrating “forward” JMP 

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 81/122

82

Conditional Jumps

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 82/122

83

8086 Conditional Jump Instructions

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 83/122

84

Ex.: Reading ASCII code when a strobe is present

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 84/122

85

Assembly language for Reading ASCII code when a strobe is present

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 85/122

86

Loops

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 86/122

87

Procedures and modular Programming

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 87/122

88

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 88/122

89

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 89/122

90

Procedures and modular Programming (Contd)

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 90/122

91

Procedures

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 91/122

92

Stack Diagram

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 92/122

93

Using PUSH and POP instructions

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 93/122

94

Interrupt Instructions

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 94/122

95

Interrupt Instructions

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 95/122

96

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 96/122

97

Program Data and Storage

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 97/122

98

• Assembler directives for data storage

 – DB - byte(s) – DW - word(s)

 – DD - doubleword(s)

 – DQ - quadword(s) – DT - tenbyte(s)

Arrays

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 98/122

99

• Any consecutive storage locations of the

same size can be called an array

X DW 40CH,10B,-13,0

Y DB 'This is an array'

Z DD -109236, FFFFFFFFH, -1, 100B

• Components of X are at X, X+2, X+4, X+8

• Components of Y are at Y, Y+1, …, Y+15 

• Components of Z are at Z, Z+4, Z+8, Z+12

DUPll f l i b

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 99/122

100

• Allows a sequence of storage locations to be

defined or reserved

• Only used as an operand of a define

directive

DB 40 DUP (?)

DW 10h DUP (0)

DB 3 dup ("ABC")

db 4 dup(3 dup (0,1), 2 dup('$')) 

Word Storage• Word doubleword and quadword data are

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 100/122

101

• Word, doubleword, and quadword data are

stored in reverse byte order (in memory)

Directive Bytes in Storage

DW 256 00 01

DD 1234567H 67 45 23 01

DQ 10 0A 00 00 00 00 00 00 00X DW 35DAh DA 35

Low byte of X is at X, high byte of X is at X+1

EQU Directive• name EQU expression

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 101/122

102

• name EQU expression

 – expression can be string or numeric

 – Use < and > to specify a string EQU

 – these symbols cannot be redefined later in the

program

sample EQU 7FhaString EQU <1.234> 

 message EQU <This is a message> 

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 102/122

103

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 103/122

104

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 104/122

105

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 105/122

106

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 106/122

107

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 107/122

108

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 108/122

109

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 109/122

110

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 110/122

111

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 111/122

112

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 112/122

113

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 113/122

114

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 114/122

115

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 115/122

116

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 116/122

117

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 117/122

118

Macro definition:

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 118/122

119

Macro definition:

name MACRO [parameters,...]

<instructions>

ENDMMyMacro MACRO p1, p2, p3

MOV AX, p1MOV BX, p2MOV CX, p3

ENDM

ORG 100h

MyMacro 1, 2, 3

MyMacro 4, 5, DX

RET

The syntax for procedure declaration:

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 119/122

120

The syntax for procedure declaration:name PROC

; here goes the code; of the procedure ...

RET

name ENDP

ORG 100h

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 120/122

121

ORG 100h

CALL m1

MOV AX, 2

RET ; return to Main Program.

m1 PROCMOV BX, 5RET ; return to caller.

m1 ENDP

END

ORG 100h

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 121/122

122

MOV AL, 1MOV BL, 2

CALL m2CALL m2CALL m2CALL m2

RET ; return to operating system.

m2 PROCMUL BL ; AX = AL * BL.

RET ; return to caller.m2 ENDP

END

8/2/2019 Addressing Modes&Instructions

http://slidepdf.com/reader/full/addressing-modesinstructions 122/122

top related