0% found this document useful (0 votes)
8 views

Lecture 12 12th Feb

Uploaded by

Anmol Murti
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Lecture 12 12th Feb

Uploaded by

Anmol Murti
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

2/14/2024

Topic-IV

80x86 Instruction Sets and ALP

T1. Barry B Brey, The Intel Microprocessors. Pearson, Eight Ed. 2009. Chapter 4-6, 8

Lecture 12

ELECTRICAL ELECTRONICS COMMUNICATION INSTRUMENTATION

Instruction Encoding

ADC CX,43H

Encoding
1000 00 1 1 11 010 001 43H (83 D1 43H)

2/14/2024 31

ELECTRICAL ELECTRONICS COMMUNICATION INSTRUMENTATION

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

ELECTRICAL ELECTRONICS COMMUNICATION INSTRUMENTATION

• Numbers usually 8 bits wide in 8-bit division .


– the dividend must be converted to a 16-bit wide number in
AX ; accomplished differently for signed and unsigned
numbers

• CBW/CWD (convert byte to word) instruction performs this


sign conversion.

ELECTRICAL ELECTRONICS COMMUNICATION INSTRUMENTATION

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

• As with 8-bit division, numbers must often be converted to the


proper form for the dividend.
– if a 16-bit unsigned number is placed in AX, DX must be
cleared to zero

• In the 80386 and above, the number is zero-extended by using


the MOVZX instruction.

ELECTRICAL ELECTRONICS COMMUNICATION INSTRUMENTATION

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.

ELECTRICAL ELECTRONICS COMMUNICATION INSTRUMENTATION

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.

ELECTRICAL ELECTRONICS COMMUNICATION INSTRUMENTATION

INC Destination

Destination –Register or memory location ( specified in 24 diff


ways)

•( AF, OF, PF, SF, ZF affected, CF not affected)

•INC BL

•INC BX

•INC EDX

2/14/2024 37

ELECTRICAL ELECTRONICS COMMUNICATION INSTRUMENTATION

4
2/14/2024

DEC Destination

Destination –Register or memory location ( specified in 24 diff


ways)

•( AF, OF, PF, SF, ZF affected, CF not affected)

•DEC BL

•DEC BX

2/14/2024 38

ELECTRICAL ELECTRONICS COMMUNICATION INSTRUMENTATION

INC/DEC the contents of a Memory


location
 Specify the data size in memory

use directive
• BYTE PTR, WORD PTR, DWORD PTR
• INC WORD PTR [BX]
• INC BYTE PTR[BX]
• BX-1000H DS-2000H

After execution of After execution of


Consider INC WORD PTR INC BYTE PTR [BX]
[BX]

21000 FF 21000 00 21000 00


21001 00 21001 01 21001 00
2/14/2024 39

ELECTRICAL ELECTRONICS COMMUNICATION INSTRUMENTATION

5
2/14/2024

BCD and ASCII Arithmetic


• The microprocessor allows arithmetic manipulation of both
BCD (binary-coded decimal) and ASCII (American
Standard Code for Information Interchange) data.

ELECTRICAL ELECTRONICS COMMUNICATION INSTRUMENTATION

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

ELECTRICAL ELECTRONICS COMMUNICATION INSTRUMENTATION

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.

ELECTRICAL ELECTRONICS COMMUNICATION INSTRUMENTATION

 Ex: up counter can be implemented as follows.

MOV COUNT,00H ; COUNT=00H


MOV AL,COUNT ;AL=00H
ADD AL,01H ;AL=01H
DAA ; decimal adjust the result
MOV COUNT,AL ; put decimal result back in
memory

ELECTRICAL ELECTRONICS COMMUNICATION INSTRUMENTATION

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

ELECTRICAL ELECTRONICS COMMUNICATION INSTRUMENTATION

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.

ELECTRICAL ELECTRONICS COMMUNICATION INSTRUMENTATION

8
2/14/2024

ASCII Arithmetic

ELECTRICAL ELECTRONICS COMMUNICATION INSTRUMENTATION

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

ELECTRICAL ELECTRONICS COMMUNICATION INSTRUMENTATION

9
2/14/2024

 The lower order byte( lower nibble )of AL is unpacked and


Higher nibble is zeroed.
 The AAA instruction works only on the AL register.
 The AAA instruction updates AF and CF but OF,PF,SF and ZF
are left undefined.

ELECTRICAL ELECTRONICS COMMUNICATION INSTRUMENTATION

End of Lecture 12

2/14/2024 49

ELECTRICAL ELECTRONICS COMMUNICATION INSTRUMENTATION

10

You might also like