You are on page 1of 33

8088/86 Programming Integer instructions and computations

Types of Instructions
Data transfer Instructions Arithmetic Instructions Logic Instructions Shift Instructions Rotate Instructions

Data Transfer Instructions


Move byte or word instruction (MOV) Exchange byte or word instruction (XCHG) Translate byte instruction (XLAT) Load effective address instruction (LEA) Load data segment instruction (LDS) Load extra segment instruction (LES)

The MOV Instruction

Example 1 MOV DX, CS


Meaning : Move the content of CS into DX
Memory outside Processor 01100 01101 BC CA

General Purpose Memory


IP CS DS SS ES AX 01 01 02 00 00 00

01102

BX CX
DX XX XX

Example 1 MOV DX, CS


Meaning : Move the content of CS into DX
Memory outside Processor 01100 01101 BC CA

General Purpose Memory


IP CS DS SS ES AX 01 01 02 02 00 00

01102

BX CX
DX 01 00

Example 2 MOV [SUM],AX


Meaning : Suppose
DS = 0200 SUM = 1212
Move the content of Accumulator AX to the memory location offset by 1212 from the starting location of the current data segment

PA = 02000 + 1212 = 03212 [AL] Memory location of 03212 [AH] Memory location of 03213

MEM = 0020

DS = 1A00 AX = 1234 BH=23 DI=1200

MOV CX,[MEM] MOV AX,0110H MOV DI,AX MOV BL,AL MOV [0100] , AX MOV [BX+DI] , AX MOV [DI] + 4 , AX MOV [BX][DI] + 4 , AX

(a) Value of immediate operand 0110H is moved into AX. (b) Contents of AX are copied into DI. (c) Contents of AL are copied into BL. (d) Contents of AX are copied into memory address DS:0100H (e) Contents of AX are copied into the data segment memory location pointed to by (DS)0 + (BX) + (DI) (f) Contents of AX are copied into the data segment memory location pointed to by (DS)0 + (DI) + 4H (g) Contents of AX are copied into the data segment memory location pointed to by (DS)0 + (BX) + (DI) + 4H

The XCHG Instruction

Example : XCHG [SUM] , BX


Memory outside Processor 01101 01102 87 IE 34 12

General Purpose Memory


IP CS DS SS ES AX 01 11 12 01 00 00

01103 01104 01105

DS (0) + SUM [BX] 12000 + 1234 = 13234


11
01

12000
12001 . . 13234 13235

XX
XX XX XX FF 00

BX CX
DX

AA
00

[BL] 13234 [BH]13235

Example : XCHG [SUM] , BX


Memory outside Processor 01101 01102 87 IE 34 12

General Purpose Memory


IP CS DS SS ES AX 01 11 12 01 00 00

01103 01104 01105

DS (0) + SUM [BX] 12000 + 1234 = 13234


00
01

12000
12001 . . 13234 13235

XX
XX XX XX AA 11

BX CX
DX

FF
00

[BL] 13234 [BH]13235

XCHG AX,DX Write an instruction sequence that will initialize the ES register with the immediate value 1010
MOV AX,1010H MOV ES,AX

Write an instruction sequence that saves the content of the ES register in memory at address DS:1000
MOV [1000H],ES

XCHG [DATA] , AX XCHG [BX+DI] , AX where BX 0100 DI 0010 DS - 1075

The XLAT Instruction

Example LDS SI,[200] outside Processor Memory


General Purpose Memory 01101 01102 01103 01104 01105 C5 36 00 20

IP CS
DS SS ES AX BX CX DX SI DI

01 11
12

00 00
00

DS (0) + [ADDR] SI
00 01 XX FF 00 XX

12000 12001 12202 12203 13000 13001

20 00 00 13

12000 + 0200 = 12200 [12200 & 01] SI

Example LDS SI,[200] outside Processor Memory


General Purpose Memory 01101 01102 01103 01104 01105 C5 36 00 20

IP CS
DS SS ES AX BX CX DX SI DI

01 11
12

00 00
00

DS (0) + [ADDR] SI
00 01 00 FF 00 20

12000 12001 12202 12203 13000 13001

20 00 00 13

12000 + 0200 = 12200 [12200 & 01] SI

Arithmetic Instructions
Operations
Addition Subtraction Multiplication Division

Data Formats
Unsigned and signed bytes or words Unpacked or packed decimal bytes ASCII Numbers

Result of Arithmetic operation affect Flags

Example 1
AL 32 (ASCII for number 2) BL34 (ASCII for number 4)

ADD AL , BL (AL) (AL) + (BL) Answer 66 AAA adjust to give equivalent decimal number 6 Example 2 ADD AL,BL DAA

NEG BX BX = 003A BX = 0000 BX 0000 + 2s complement of 003A 0000+FFC6 FFC6

AL = -1 and CL = -2 what is the content of AX?


AL = FF CL = FE

MUL CL FD02
IMUL CL 0002

What is the result of executing the following sequence of instructions MOV AL,0A1 AL = A1 1010 0001 CBW AX 1111 1111 1010 0001 CWD AX 1111 1111 1010 0001 DX 1111 1111 1111 1111

Assuming that AX=0010 BX=0100 DS=1000 what happens if the XLAT instruction is executed?
AL is loaded from the physical address

10000 + 0100+ 0010= 10110 Write a single instruction that loads AX from address 0200 and DS from address 0202 LDS AX,[0200H]

MOV AL,01010101 AND AL,00011111 OR AL,11000000 XOR AL,00001111 NOT AL

Clearing , setting and toggling bits of an operand Clear a particular bit AND with logic 0 Set a particular bit - OR with logic 1 Toggle(reverse) particular bit XOR operation

Logical Vs Arithmetic

You might also like