(4)
INST. OPERANDS FUNCTION
ADD
D.OPERAND,S.OPERAND
REG, memory
memory, REG
REG, REG
memory, immediate
REG, immediate
FUNCTION:
D.OPERAND = D.OPERAND + S.OPERAND
ADC
O, S, Z, A, C & P FLAGS are Affected
Example:
MOV AL, 6
ADD AL, -3
FUNCTION:
D.OPERAND = D.OPERAND + S.OPERAND + CF
Example:
MOV AL, 6
ADC AL, -3
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 = 28
; CF = 1, ZF = 0
(142+142 = 256 + 28)
; OF = 1
(28 < 128, sign bit: 1→0)
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).
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.
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
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
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=?
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
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=?
?
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
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
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=?
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
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 ( ? )
Examples
; DX;AX = 1303F0h + 22A00h = 152DF0h
MOV AX, 03F0h
MOV DX, 0013h
ADD AX, 2A00h ; 03F0h + 2A00h = 2DF0h
ADC DX, 0002h ; 0013h + 0002h ; +0(no carry) = 0015h
; AX = 398 – 32 = 366 (= 016Eh)
MOV AX, 398; 018Eh
SUB AX, 32 ; AX = 018Eh – 0020h
; DX;AX = 1303F0h – 22A00h = 10D9F0h
MOV AX, 03F0h
MOV DX, 0013h
SUB AX, 2A00h ; 03F0h - 2A00h = D9F0h
SBB DX, 0002h ; 0013h - 0002h
; -1(borrow) = 0010h
MOV AL, 125
ADD AL, 15 ; AL = 125 + 15 (= 8Ch)
Instruction 4.pptx

Instruction 4.pptx

  • 1.
  • 4.
    INST. OPERANDS FUNCTION ADD D.OPERAND,S.OPERAND REG,memory memory, REG REG, REG memory, immediate REG, immediate FUNCTION: D.OPERAND = D.OPERAND + S.OPERAND ADC O, S, Z, A, C & P FLAGS are Affected Example: MOV AL, 6 ADD AL, -3 FUNCTION: D.OPERAND = D.OPERAND + S.OPERAND + CF Example: MOV AL, 6 ADC AL, -3
  • 5.
    MOV BH, 26 ADDBH, 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 = 28 ; CF = 1, ZF = 0 (142+142 = 256 + 28) ; OF = 1 (28 < 128, sign bit: 1→0)
  • 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 NOOPERAND 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 BCDPacking • 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 contains25 (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 NOOPERAND 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 contains32 (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 NOOPERAND 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 MOVBL,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 NOOPERAND 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 SUBAL,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 ( ? )
  • 18.
    Examples ; DX;AX =1303F0h + 22A00h = 152DF0h MOV AX, 03F0h MOV DX, 0013h ADD AX, 2A00h ; 03F0h + 2A00h = 2DF0h ADC DX, 0002h ; 0013h + 0002h ; +0(no carry) = 0015h ; AX = 398 – 32 = 366 (= 016Eh) MOV AX, 398; 018Eh SUB AX, 32 ; AX = 018Eh – 0020h ; DX;AX = 1303F0h – 22A00h = 10D9F0h MOV AX, 03F0h MOV DX, 0013h SUB AX, 2A00h ; 03F0h - 2A00h = D9F0h SBB DX, 0002h ; 0013h - 0002h ; -1(borrow) = 0010h MOV AL, 125 ADD AL, 15 ; AL = 125 + 15 (= 8Ch)