Lecture 12 12th Feb
Lecture 12 12th Feb
Topic-IV
T1. Barry B Brey, The Intel Microprocessors. Pearson, Eight Ed. 2009. Chapter 4-6, 8
Lecture 12
Instruction Encoding
ADC CX,43H
Encoding
1000 00 1 1 11 010 001 43H (83 D1 43H)
2/14/2024 31
1
2/14/2024
8-Bit Division
• Uses AX to store the dividend divided by the contents of any 8-bit
register or memory location.
• Quotient moves into AL after the division with AH containing a
whole number remainder.
– quotient is positive or negative; remainder always assumes sign
of the dividend; always an integer
2
2/14/2024
16-Bit Division
• Sixteen-bit division is similar to 8-bit division
– instead of dividing into AX, the 16-bit number is divided into
DX–AX, a 32-bit dividend
Increment
• The INC instruction adds 1 to any register or memory location,
except a segment register.
• The size of the data must be described by using the BYTE PTR,
WORD PTR directives.
• The assembler program cannot determine if the INC [DI]
instruction is a byte-, word-sized increment.
3
2/14/2024
Increment
• INC Destination
Ex: INC CX ; Add 1 to the contents of CX.
EX: INC BYTEPTR [BX] ; Increments the byte pointed to
by the contents of BX.
INC Destination
•INC BL
•INC BX
•INC EDX
2/14/2024 37
4
2/14/2024
DEC Destination
•DEC BL
•DEC BX
2/14/2024 38
use directive
• BYTE PTR, WORD PTR, DWORD PTR
• INC WORD PTR [BX]
• INC BYTE PTR[BX]
• BX-1000H DS-2000H
5
2/14/2024
BCD Arithmetic
• Two arithmetic techniques operate with BCD data:
• addition and subtraction.
• DAA (decimal adjust after addition) instruction follows BCD
addition,
• DAS (decimal adjust after subtraction) follows BCD
subtraction.
– both correct the result of addition or subtraction
so it is a BCD number
6
2/14/2024
DAA
• DAA follows the ADD or ADC instruction to adjust the result into
a BCD result.
• After adding the AL and BL registers, the result is adjusted with a
DAA instruction before being stored.
• Ex: before execution let AL =0101 1001=59 BCD and
BL= 0011 0101= 35 BCD
ADD AL,BL ; AL =1000 1110= 8EH
DAA ; Add 0110 because 1110 > 9
; AL= 1001 0100= 94 BCD
AF,CF,PF and ZF are affected. OF is undefined after DAA
instruction.
7
2/14/2024
DAS Instruction
• Functions as does DAA instruction, except it follows a subtraction
instead of an addition.
• Ex: AL=1000 0110 =86 BCD
BH= 0101 0111 =57 BCD
SUB AL,BH ; AL= 0010 1111 =2FH,CF=0
DAS ; lower nibble=1111>9 So,DAS
subtracts 0000 0110 to give
AL=0010 1001 =29 BCD
ASCII Arithmetic
• ASCII arithmetic instructions function with coded numbers, value
30H to 39H for 0–9.
• Four instructions in ASCII arithmetic operations:
– AAA (ASCII adjust after addition)
– AAD (ASCII adjust before division)
– AAM (ASCII adjust after multiplication)
– AAS (ASCII adjust after subtraction)
• These instructions use register AX as the source and as the
destination.
8
2/14/2024
ASCII Arithmetic
AAA Instruction
• Addition of two one-digit ASCII-coded numbers will not result in
any useful data.
• Ex: Before: AL= 0011 0001 , ASCII 1;
BL= 0011 1001,ASCII 9
ADD AL,BL ; Result : AL=0110 1010 = 6AH,
; which is incorrect BCD
AAA ;
ADD AX, 3030
9
2/14/2024
End of Lecture 12
2/14/2024 49
10