You are on page 1of 11

10/24/2023

10/24/2023 Dr. Mazin H. Aziz 2nd-Class Microprocessor I

QUIZ #4

Write the equivalent for each of the following

A. LOOPNE nxt

B. JS cont
Dr. Mazin H. Aziz 2nd-Class Microprocessor I 10/24/2023

1
10/24/2023

Instructions
for
INTEL 8086
Microprocessor
(4)
Arithmetic Group
3
10/24/2023 Dr. Mazin H. Aziz 2nd-Class Microprocessor I

The reference for this


lecture is
chapter-5 /P. 163-185
&P. 204-206
of the textbook
4
10/24/2023 Dr. Mazin H. Aziz 2nd-Class Microprocessor I

2
10/24/2023

ARITHMATIC GROUP

SUB MUL
ADD IMUL
ADC SBB
AAM
DAA DAS
AAA AAS DIV
IDIV
CWD AAD
CBW
10/24/2023 Dr. Mazin H. Aziz 2nd-Class Microprocessor I
Dr. Mazin H. Aziz 2nd-Class Microprocessor 5
5

Signed/Unsigned Integers’ Weal

10/24/2023 Dr. Mazin H. Aziz 2nd-Class Microprocessor I 6

3
10/24/2023

Unsigned Integers

• Unsigned integers are easy – they use all 8 or 16 bits in the byte or
word to represent the number.
• If it is a byte, the total range is 0 to 255
(00000000 to 11111111).
• If it is a word, the total range is 0 to 65,535 (0000000000000000 to
1111111111111111).

10/24/2023 Dr. Mazin H. Aziz 2nd-Class Microprocessor I 7

Signed Integers
• Are slightly more complicated, as they can only use 7 (for the
byte) or 15 (for the word) of the bits to represent the number.
The highest bit is used to indicate the sign.
• A high bit of 0 → positive number
• A high bit of 1 → negative number

• The range of a signed integer in a byte is therefore, -128 to 127,


remembering that the high bit does not count.
• The range of a signed integer in a word is –32,768 to 32,767.

10/24/2023 Dr. Mazin H. Aziz 2nd-Class Microprocessor I 8

4
10/24/2023

Overflow Flag
The rules for turning on the overflow flag in binary/integer math
are two:
1) If the sum of two numbers with the sign bits “OFF” yields a result
number with the sign bit “ON”, the "overflow" flag is turned on.
0100 + 0100 = 1000 (overflow flag is turned “ON”)

2) If the sum of two numbers with the sign bits “ON” yields a result
number with the sign bit “OFF” , the "overflow" flag is turned on.
1000 + 1000 = 0000 (overflow flag is turned “ON”)
Otherwise, the overflow flag is turned “OFF”.
10/24/2023 Dr. Mazin H. Aziz 2nd-Class Microprocessor I 9

INST. OPERANDS FUNCTION


D.OPERAND,S.OPERAND FUNCTION:
ADD REG, memory
D.OPERAND = D.OPERAND + S.OPERAND

Example:
memory, REG MOV AL, 6
ADD AL, -3
REG, REG
FUNCTION:
ADC memory, immediate D.OPERAND = D.OPERAND + S.OPERAND + CF

Example:
REG, immediate
MOV AL, 6
ADC AL, -3
O, S, Z, A, C & P FLAGS are Affected
10/24/2023 Dr. Mazin H. Aziz 2nd-Class Microprocessor I
10

10

5
10/24/2023

Example
MOV BH, 26
ADD BH, 77 ; BH = 103
; CF = 0, ZF = 0
; OF = 0
(103 < 128, sign bit: 0→0)

ADD BH, 39 ; BH = 142


; CF = 0, ZF = 0
; OF = 1
(142 > 128, sign bit: 0→1)

ADD BH, 142 ; BH = 29


; (142+142 = 284 = 255+ 29)
;CF = 1, ZF = 0
; OF = 1
(29 < 128, sign bit: 1→0)
10/24/2023 Dr. Mazin H. Aziz 2nd-Class Microprocessor I 11

11

INST. OPERANDS FUNCTION


D.OPERAND,S.OPERAND FUNCTION:
D.OPERAND = D.OPERAND - S.OPERAND
SUB REG, memory
Example:
MOV AL, 6
memory, REG
SUB AL, 3
REG, REG
FUNCTION:
SBB memory, immediate D.OPERAND = D.OPERAND - S.OPERAND - CF

Example:
REG, immediate
MOV AL, 6
SBB AL, 3

O, S, Z, A, C & P FLAGS are Affected


10/24/2023 Dr. Mazin H. Aziz 2nd-Class Microprocessor I
12
12

6
10/24/2023

Examples
MOV AL, 125
8-bit Addition ADD AL, 15 ; AL = 125 + 15 (= 8Ch)

; AX = 398 – 32 = 366 (= 016Eh)


MOV AX, 398 ; 018Eh
16-bit Subtraction SUB AX, 32 ; AX = 018Eh – 0020h
; DX;AX = 1303F0h + 22A00h = 152DF0h
MOV AX, 03F0h
32-bit Addition MOV DX, 0013h
ADD AX, 2A00h ; 03F0h + 2A00h = 2DF0h
ADC DX, 0002h ; 0013h + 0002h +0 (no carry) = 0015h

; DX;AX = 1303F0h – 22A00h = 10D9F0h


MOV AX, 03F0h
32-bit Subtraction MOV DX, 0013h
SUB AX, 2A00h ; 03F0h - 2A00h = D9F0h
SBB DX, 0002h ; 0013h - 0002h -1 (borrow) = 0010h
10/24/2023 Dr. Mazin H. Aziz 2nd-Class Microprocessor I
13
13

INST. OPERANDS FUNCTION


UNSIGNED MULTIPLY
when operand is a byte: AX = AL * operand.
MUL when operand is a word: (DX AX) = AX * operand.
Example:
MOV AL, 200 ;AL=C8h
REG MOV BL,4
MUL BL ;AX=0320 h (800)
memory SIGNED MULTIPLY
IMUL The same function but it should be used with signed
numbers (i.e. according to the required operation).
Example:
MOV AL, -2 ; AL=0FEh
MOV BL, -4 ; AL=0FCh
IMUL BL ; AX = 8
O & C FLAGS are Affected
10/24/2023 Dr. Mazin H. Aziz 2nd-Class Microprocessor I
14
14

7
10/24/2023

INST. OPERANDS FUNCTION


UNSIGNED DIVIDE
when operand is a byte: AL = AX / operand.
DIV AH = remainder (modulus)
when operand is a word: AX=(DX AX) / operand.
DX = remainder (modulus)
Example: MOV AX, 203 ;AX=00CBh
REG MOV BL,4
DIV BL ;AL=32h, AH=3
memory
IDIV SIGNED DIVIDE
The same function but it should be used with signed
numbers (i.e. according to the required operation).

FLAGS are Undefined Example: MOV AX, -203 ;AX=FF35h


MOV BL, 4
IDIV BL ;AL= -50(CEh), AH= -3(FDh)
Dr. Mazin H. Aziz 2nd-Class Microprocessor I
10/24/2023 Dr. Mazin H. Aziz 2nd-Class Microprocessor 15
15

Examples

; AX = 14 * 29 = 406 (= 0196h)
MOV AL, 14 ; 0Eh
MOV BL, 29 ; 1Dh
MUL BL ; AX = 0Eh * 1Dh

; DX:AX = 5301D0h/ 139Bh


MOV AX, 01D0h
MOV DX, 0053h
MOV BX, 139Bh
DIV BX ; 5301D0h / 139Bh
; AX = Quotient = 1083 (= 043Bh)
10/24/2023
; DX = Remainder = 4375 (= 1117h) 16
Dr. Mazin H. Aziz 2nd-Class Microprocessor I

16

8
10/24/2023

INST. OPERANDS FUNCTION


Convert Byte Into Word

Algorithm:
if high bit of AL = 1 then:
AH = 255 (0FFh)

CBW NO OPERAND else AH = 0


Example:
MOV AH, 0 ; AH = 0
MOV AL, -5 ; AX = 000FBh (251)
CBW ; AX = 0FFFBh (-5)

NONE of the FLAGS are Affected

10/24/2023 Dr. Mazin H. Aziz 2nd-Class Microprocessor I 17

17

INST. OPERANDS FUNCTION


Convert Word to Double Word

Algorithm:
if high bit of AX = 1 then:
DX = 65535 (FFFFh)
else DX = 0

CWD NO OPERAND Example:


MOV DX, 0 ; DX = 0
MOV AX, 0 ; AX = 0
MOV AX, -5 ; DX AX = 0000h:FFFBh
CWD ; DX AX = FFFFh:FFFBh

NONE of the FLAGS are Affected


10/24/2023 Dr. Mazin H. Aziz 2nd-Class Microprocessor I
18
18

9
10/24/2023

HOMEWORK #5
➢ Write A program to calculate the average of 5
numbers each consists of 8-bit.

➢ Write A program to find the area of a circle


having a 5-bits diameter saved in BX.

➢ Write A program to divide the number stored


in CX by 15 using SUB & SBB instructions.

10/24/2023 Dr. Mazin H. Aziz 2nd-Class Microprocessor I 19

19

Quiz Quiz Quiz


1. Write the equivalent 1. Write the equivalent 1. Perform each of the
for the each of the for the instruction following without
following instructions ROR AX,CL using the using multiplication
instruction SHR. or division
instructions.
A. JCXZ next

A. AL = AL X BL
B. LOOP again

B. AL = AL / BL

10/24/2023 Dr. Mazin H. Aziz 2nd-Class Microprocessor I 20

20

10
10/24/2023

THE END
10/24/2023 Dr. Mazin H. Aziz 2nd-Class Microprocessor I 21

21

11

You might also like