6. EEL 3801C
Unsigned Integers
• Unsigned integers are easy – they use all 8 or
16 bits in the byte or word to represent the
number.
• If a byte, the total range is 0 to 255
(00000000 to 11111111).
• If a word, the total range is 0 to 65,535
(0000000000000000 to 1111111111111111).
7. EEL 3801C
Signed Integers
• Are slightly more complicated, as they can only
use 7 or 15 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 to127, remembering that the
high bit does not count.
• The range of a signed integer in a word is
–32,768 to 32,767.
8. INST. OPERANDS FUNCTION
NO OPERAND
Decimal adjust After Addition.
Corrects the result of addition of two packed
BCD values.
Algorithm:
if low nibble of AL > 9 or AF = 1 then:
AL = AL + 6
AF = 1
if AL > 9F or CF = 1 then:
AL = AL + 60h
CF = 1
DAA
Example:
MOV AL, Fh ; AL = 0Fh
DAA ; AL = 15h
O, S, Z, A, C & P FLAGS are Affected
9. 8086 Assembly 9
BCD Packing
• When typing a digit from the keyboard, it is
represented in ASCII values 30H thru 39H
– 00110000 thru 00111001
– if we replace the 0011 in the upper nibble, we
are left with BCD code for the digit
– this is an unpacked BCD number because we
are using 8 bits to represent it
• We can combine 2 BCD digits in a single
byte…this is a packed BCD number
10. EXAMPLE 1:
AL contains 25 (packed BCD)
BL contains 65 (packed BCD)
ADD AL, BL ;AL=8Ah
DAA ;AL=90h (8A+06)
EXAMPLE 2:
AL contains 45 (packed BCD)
BL contains 65 (packed BCD)
ADD AL, BL ;AL=AAh
DAA ;AL=?
11. INST. OPERANDS FUNCTION
NO OPERAND
ASCII Adjust after Addition.
Corrects result in AH and AL after addition
when working with BCD values.
Algorithm:
if low nibble of AL > 9 or AF = 1 then:
AL = AL + 6
AH = AH + 1
AF = 1 & CF = 1
else AF = 0 & CF = 0
In both cases: clear the high nibble of AL
AAA
A& C FLAGS are Affected
Example: MOV AX, 8h
ADD AX, 7h ; AH = 00, AL =0Fh
AAA ; AH = 01, AL = 05
12. EXAMPLE 1:
AL contains 32 (ASCII code for number 2)
BL contains 34 (ASCII code for number 4)
ADD AL,BL ;AL=66h
AAA ;AL=06 AH=00
?
EXAMPLE 2:
AL contains 32 (ASCII code for number 2)
BL contains 38 (ASCII code for number 8)
ADD AL, BL ;AL=6Ah
AAA ;AL=? AH=?
?
13. INST. OPERANDS FUNCTION
SUB
D.OPERAND,S.OPERAND
REG, memory
memory, REG
REG, REG
memory, immediate
REG, immediate
FUNCTION:
D.OPERAND = D.OPERAND - S.OPERAND
SBB
O, S, Z, A, C & P FLAGS are Affected
Example:
MOV AL, 6
SUB AL, 3
FUNCTION:
D.OPERAND = D.OPERAND - S.OPERAND - CF
Example:
MOV AL, 6
SBB AL, 3
14. INST. OPERANDS FUNCTION
NO OPERAND
Decimal adjust After Subtraction.
Corrects the result of subtraction of two
packed BCD values.
Algorithm:
if low nibble of AL > 9 or AF = 1 then:
AL = AL - 6
AF = 1
if AL > 9F or CF = 1 then:
AL = AL - 60h
CF = 1
DAS
Example: MOV AL, 0
SUB AL, 01h ; AL = 0FFh (-1)
DAS ; AL = 99h, CF=1
S, Z, A, C & P FLAGS are Affected
15. EXAMPLE 1:
MOV AL,83h
MOV BL,28h
SUB AL,BL ;AL=5Bh (83h-28h)
;= (83h+TC(28h))
;=(83h+D8h)
DAS ;AL=55h (5Bh-6)
EXAMPLE 2:
MOV AL, 16h
MOV BL,28h
SUB AL, BL ;AL=EEh (16h-28h)
DAS ;AL=?
16. INST. OPERANDS FUNCTION
NO OPERAND
ASCII Adjust after Subtraction.
Corrects result in AH and AL after subtraction
when working with BCD values.
Algorithm:
if low nibble of AL > 9 or AF = 1 then:
AL = AL - 6
AH = AH - 1
AF = 1 & CF = 1
else AF = 0 & CF = 0
In both cases: clear the high nibble of AL
AAS
A& C FLAGS are Affected
Example: :
MOV AX, 02FFh ; AH = 02, AL = FFh
AAS ; AH = 01, AL = 09
17. EXAMPLE 1:
MOV AX,38h
SUB AL,39h ;AX=00FFh (38h-39h)
;= (38h+TC(39h))
;=(38h+C7h)
AAS ;AX=FF09h (Ten’s
;complement of -1)
EXAMPLE 2:
MOV AX, 38h
SUB AL, 35h ;AX=0003h (38h-35h)
;= (38h+TC(35h))
;=(38h+??h)
AAS ;AX=????h ( ? )