SlideShare a Scribd company logo
1 of 35
15CS44 microprocessors & Microcontrollers
Kishore kumar R RLJIT page 1
MODULE -2
X86 Instructions sets description
Topics:
2.1 Arithmetic and logic instructions
2.1.1 Unsigned addition and subtraction
2.1.2 Unsigned multiplication & division
2.1.3 Logic Instructions
2.1.4 BCD & ASCII conversion
2.1.5 Rotate Instructions
2.2 INT 21H & INT 10H programming
2.2.1 BIOS INT 10 H programming
2.2.2 DOS Interrupt 21H
2.2.3 8086/8088 interrupts
2.2.4 x86 and interrupt Assignment
15CS44 microprocessors & Microcontrollers
Kishore kumar R RLJIT page 2
2.1.1 Unsigned addition and subtraction
Unsigned numbers:
 Numbers in which all bits are used to represent data and no bits are used for
the sign.
E.g. 4 = 100
In the above example all three bits are used to represent the value of 4
Addition:
 The Opcode for addition is ADD.
Syntax: ADD destination, source;
Operation: destination = destination + source
Flags affected: AF, CF, PF, ZF, SF, OF
E.g. ADD AL, BL ; AL = AL + BL
Problem: show how the flag register is affected by following instructions
MOV AL, 0F5H
ADD AL, 0BH
Sol )
F5H = 1111 0101
+ +
0BH= 0000 1011
---------------------
0000 0000
---------------------
After addition AL = 0000 0000
CF= 1  since there is carry out from MSB
SF =0  sign is positive (0)
PF=1  number of 1s is zero (even parity)
AF =1 there is a carry from position 3 to 4
ZF = 1  result is zero
15CS44 microprocessors & Microcontrollers
Kishore kumar R RLJIT page 3
Byte Addition:
Program1: write a program to calculate total sum of 5 bytes of data. Each
byte represents daily wages of a worker; the decimal data is as follows 125,
235, 197, 91, 48
125 = 7DH, 235 = EBH, 197= C5H, 91= 5BH, 48 = 30H
Program:
PAGE 60,132
TITLE ADDING 5 BYTES
MODEL SMALL
.DATA
ARR DB 7DH,EBH,C5H,5BH,30H ARR SI
RES DW ?
.CODE
MOV AX,@DATA
MOV DS,AX
MOV SI,OFFSET ARR
MOV CX,5 RES
MOV AX,0
BACK:ADD AL,[SI]
ADC AH,0
INC SI
DEC CX
JNZ BACK
MOV RES,AX
INT 3
END
WORD Addition:
Case1: Adding single word numbers
Case 2: adding multiword numbers
7D
EB
C5
5B
30
B8
02
15CS44 microprocessors & Microcontrollers
Kishore kumar R RLJIT page 4
Case1: Adding single word numbers
Program 2: write a program to calculate total sum of 5 words of data. Each
word represents yearly wages of a worker; the decimal data is as follows
27345, 28521, 29533, 30105, and 32375
27345= 6AD1H , 28521=6F69H, 29533=735DH, 7599H, 7E77H
Program:
PAGE 60,132
TITLE Adding 5 Words of data
.MODEL SMALL
.DATA
ARR DW 6AD1H,6F69H,735DH,7599H,7E77H ARR
SUM DD ?
.CODE
MOV AX,@DATA
MOV DS,AX
MOV CL,5
MOV SI,OFFSET ARR
MOV AX,0
MOV BX,0
BACK: ADD AX,[SI]
ADC BX,0 RES
ADD SI,2
DEC CL
JNZ BACK
MOV SUM,AX
MOV SUM+2,BX
INT 3
END
D1
6A
69
6F
5D
73
99
75
77
7E
A7
41
02
00
15CS44 microprocessors & Microcontrollers
Kishore kumar R RLJIT page 5
Case 2: Addition of Multiword numbers:
Write a program to add N1= 12345678H and N2 = 12345678H
Program:
PAGE 60,132
TITLE Adding Multiword Numbers N1
.MODEL SMALL
.DATA
N1 DD 12345678H
N2 DD 12345678H N2
RES DQ ?
.CODE
MOV AX,@DATA RES
MOV DS,AX
MOV CL,2
CLC
MOV SI,OFFSET N1
MOV DI,OFFSET N2
MOV BX,OFFSET RES
BACK:MOV AX,[SI]
ADC AX,[DI]
MOV [BX],AX
ADD SI,2
ADD DI,2
ADD BX,2
DEC CL
JNZ BACK
INT 3
END
78
56
34
12
78
56
34
12
F0
AC
68
24
00
00
00
00
15CS44 microprocessors & Microcontrollers
Kishore kumar R RLJIT page 6
Subtraction of Unsigned Numbers:
SUB:
 The opcode for subtraction is SUB
 It subtracts the source from the destination and places result in the destination
Syntax: SUB destination, source
Operation: destination = destination – source
Flags affected: CF, AF, PF, SF, OF, ZF
Steps for unsigned subtraction:
1. Take 2’s complement of subtrahend (source operand)
2. Add it to minuend (destination operand)
3. Invert the carry
4. After the result if CF=0, the result is positive if CF=1 result is negative
Example:
15CS44 microprocessors & Microcontrollers
Kishore kumar R RLJIT page 7
SBB (subtract with borrow):
 This instruction subtracts the contents of carry flag from the difference of the operands.
 This instruction is used for multi-byte or multi-word numbers
Syntax: SBB destination, source
Operation : destination = destination - source - CF
e.g. SBB AH, AL ; AH = AH - AL – Carry
SBB CL, 2; CL = CL - 2 – carry
Program 1 : Subtract 6EH from 4CH
.MODEL SMALL
.DATA
NUM1 DB 4CH
NUM2 DB 6EH
RES DB ?
.CODE
MOV AX,@DATA
MOV DS,AX
MOV DH,NUM1; DH = 4CH
SUB DH,NUM2; DH=DH-6EH
JNC NEXT
NOT DH
INC DH
NEXT:MOV RES,DH
INT 3
END
Analysis: 4C-6E = -22
0 1 0 0 1 1 0 0
1 0 0 1 0 0 1 0 (2’s complement)
-----------------------
CF=0 1 1 0 1 1 1 1 0
Invert carry flag CF=1 , hence result is negative so take 2’s complement of result
2’s complement of result = 0010 0010 = 22 CF=1 hence result is -22
15CS44 microprocessors & Microcontrollers
Kishore kumar R RLJIT page 8
Program2: subtract 412963BH from 62562FAH
.MODEL SMALL
.DATA
NUM1 DD 62562FAH NUM1
NUM2 DD 412963BH
RES DD ?
.CODE
MOV AX,@DATA
MOV DS,AX NUM2
MOV AX, NUM1; AX = 62FA
SUB AX,NUM2; AX = AX-62FA
MOV RES,AX
MOV AX,NUM1+2
SBB AX, NUM2+2 RES
MOV RES+2,AX
INT 3
END
Analysis:
62FA – 963B = CCBF AX and CF=1
When SBB is executed
625 – 412 – 1 = 212
2.1.2 Unsigned Multiplication:
Unsigned Multiplication:
There are four cases in unsigned multiplication
1. BYTE × BYTE
2. WORD × WORD
3. BYTE × WORD
625 62fA
412 963B
-----------------
0212 CCBF
------------------
FA
62
25
06
3B
96
12
04
BF
CC
12
02
15CS44 microprocessors & Microcontrollers
Kishore kumar R RLJIT page 9
BYTE × BYTE:
 In byte × byte multiplication, multiplicand must be in AL register and the
second operand can be either in 8-bit register or 8-bit memory location
and result will be stored in AX
Syntax: MUL 8-bit register / memory location
Operation : AX = AL × 8-bit register/ memory location
e.g.1 MUL BL e.g.2 MUL NUM2
AX= AL × BL AX = AL × NUM2
Program 1: multiply 25H and 65H
.MODEL SMALL
.DATA
RES DW ?
.CODE
MOV AX,@DATA
MOV DS,AX
MOV AL,25H; AL =25H
MOV BL,65H; BL = 65H
MUL BL; AX = AL × BL
MOV RES, AX
INT 3
END
WORD × WORD:
 In word×word multiplication, multiplicand must be in AX and multiplier can
be in any 16-bit register or memory location and result will be stored in
DX:AX
 DX contains higher word of the result and AX contains lower word of the
result.
Syntax: MUL 16-bit register/memory location
DX:AX = AX * 16-bit register /memory location
e.g.1 MUL BX e.g.2 MUL WORD PTR [BX]
DX:AX = AX * BX DX:AX = AX * [BX]
[BX] is 16-bit memory location
15CS44 microprocessors & Microcontrollers
Kishore kumar R RLJIT page 10
BYTE × WORD:
 It is similar to word × word multiplication except that AL contains byte
operand and AH must be cleared.
Unsigned multiplication summary:
Multiplication Multiplicand Multiplier Result
BYTE × BYTE AL 8-Bit Register/ memory location AX
WORD × WORD AX 16-Bit Register/ memory location DX:AX
BYTE × WORD AL =byte AH=0 16-Bit Register/ memory location DX:AX
Division of unsigned numbers:
There are four cases in unsigned division
1. Byte over byte
2. Word over word
3. Word over byte
4. Double word over word
Byte / Byte division:
 In byte / byte division, numerator (dividend) must be in AL register and AH
must be zero.
 The denominator (divisor) can be in any 8-bit register or memory location
 After division, quotient will be in AL and remainder will be in AH
Syntax: DIV 8-bit register / memory location
e.g. DIV BL; AX / BL AL = quotient AH =remainder
the following instructions shows various addressing modes that denominator can
take
NUM1 DB 95 NUM1
NUM2 DB 10
QUO DB ? NUM2
REM DB ? QUO
REM
95
10
15CS44 microprocessors & Microcontrollers
Kishore kumar R RLJIT page 11
Using Direct Addressing mode:
MOV AL,NUM1; AL=95
MOV AH,0
DIV NUM2; AX/10 AL=9 AH=5
MOV QUO,AL
MOV REM,AH
Using Register Addressing Mode:
MOV AL, NUM1; AL=95
MOV AH, 0
MOV BL,NUM2 ; BL=10
DIV BL; AX/BL = 95/10 AL=9 AH=5
MOV QUO, AL
MOV REM,AH
Using Register Indirect addressing mode:
MOV AL, NUM1; AL=95
MOV AH, 0
MOV BX, OFFSET NUM2
DIV BYTE PTR BX; 95/10 AL=9 AH=5
MOV QUO, AL
MOV REM, AH
Word/Word Division:
 In Word/Word division, numerator (dividend) is in AX and DX must be zero
 Denominator (divisor) can be in any 16-bit register or memory location
 After division, AX contains quotient, and DX contains remainder
Syntax: DIV 16-bit register / memory location
e.g. MOV AX,9000
MOV DX,0
MOV BX,100
DIV BX; DX:AX/BX  9000/ 100 AX=90 DX=0
Word/Byte:
 Dividend is in AX, divisor in any 8-bit register or memory location
 After division, AL contains quotient AH contains remainder
15CS44 microprocessors & Microcontrollers
Kishore kumar R RLJIT page 12
e.g. DIV BL ; AX/BL AL = quotient AH = remainder
Double-word / Word:
 Dividend is in DX:AX
 Divisor can be in any 16-bit register or memory location
 After division, AX contains quotient and DX contains remainder
Syntax: DIV 16-bit register or memory location
e.g. NUM1 DD 123456H
NUM2 DW 1000H
MOV AX, NUM1; AX= 3456
MOV DX,NUM1+2 DX= 0012
MOV BX, NUM2; BX=1000
DIV BX; 123456/ 1000 AX= 123 DX=456
2.1.3 Logic instructions:
AND:
 This instruction performs AND operation on source and destination and stores
result in Destination.
 AND instruction automatically changes CF and OF to zero and PF, ZF and SF
are set according to result.
Syntax: AND Destination, Source
Function: destination = destination AND Source
e.g. AND AL, BL ; AL = AL AND BL
15CS44 microprocessors & Microcontrollers
Kishore kumar R RLJIT page 13
OR:
 This instruction performs OR operation on destination and source and stores
result in destination.
 OR instruction automatically changes CF and OF to zero and PF, ZF and SF are
set according to result.
e.g.
XOR:
 It performs exclusive-OR operation on destination and source and stores
result in destination.
 XOR instruction clears CF and OF and SF, OF, PF are set according to the
result.
Syntax: XOR destination, source
Functions: destination = destination XOR Source
e.g.
15CS44 microprocessors & Microcontrollers
Kishore kumar R RLJIT page 14
SHIFT:
There are two types of shifts
1. Logical shifts
2. Arithmetic shifts
Logical Shifts:
There are two types of Logical shifts
1. Logical Shift Right (SHR)
2. Logical Shift Left (SHL)
SHR:
 SHR shifts the contents of the destination right by the number of bits
specified in the count
 LSB bit is shifted to carry flag (CF)
 Zero is shifted to MSB
 If count is greater than 1, count should be in CL
Syntax: SHR destination, count
Operation:
e.g. SHR AL, 1 ; the contents of AL are shifted left by one position
15CS44 microprocessors & Microcontrollers
Kishore kumar R RLJIT page 15
SHL:
 SHR shifts the contents of the destination Left by the number of bits
specified in the count
 MSB bit is shifted to carry flag (CF)
 Zero is shifted to LSB
 If count is greater than 1, count should be in CL
Syntax: SHL destination, count
Operation:
e.g SHL AL,1 ; contents of AL are shifted left by one position
15CS44 microprocessors & Microcontrollers
Kishore kumar R RLJIT page 16
Arithmetic Shifts:
There are two types of arithmetic shifts
1. Shift Arithmetic Right (SAR)
2. Shift Arithmetic Left (SAL)
SAR:
 This instruction shifts the signed number in destination right by the number of
bits specified in count.
 This instruction retains (preserves) the MSB (sign bit)
 LSB is shifted to carry flag (CF)
 If count is greater than 1, count should be in CL
Syntax: SAR destination, count
Operation:
e.g. MOV AL, -10 ; AL = -10
SAR AL,1; AL = -5
SAL:
 SAL is similar to SHL
Syntax: SAL destination, count
Operation:
15CS44 microprocessors & Microcontrollers
Kishore kumar R RLJIT page 17
Compare of Signed Numbers:
CMP (compare):
 This instruction compares destination and source and changes flags CF, SF,
ZF according to the result.
 Destination can be any register or memory location
 Source can be any register or memory location or immediate data.
Syntax: CMP Destination, Source
Operation: destination – source
Flags affected: CF, SF, ZF
Program: Write a program to find highest grade in 69, 87, 96, 45 and 75
.MODEL SMALL
.DATA
GRADES DB 69, 87, 96, 45, 75 GRADES
HIGHEST DB ?
.CODE
MOV AX,@DATA
MOV DS,AX
MOV CX,4
MOV SI, OFFSET GRADES
MOV AL,[SI]; AL contains first grade HIGHEST
BACK:INC SI ; point to next grade
CMP AL,[SI]; compare next grade to higher
JA NEXT ; jump if AL is higher
MOV AL,[SI]; AL contains highest grade
NEXT: LOOP BACK ; Jump to back if cx≠0
MOV HIGHEST, AL; move highest grade from AL to memory location
INT 3
END
655
87
96
45
75
96
15CS44 microprocessors & Microcontrollers
Kishore kumar R RLJIT page 18
2.1.4 BCD and ASCII Conversion
BCD:
 BCD stands for Binary coded decimal.
 Binary representation of 0 to 9 is called BCD.
There are two types of BCD
1. Unpacked BCD
2. Packed BCD
Unpacked BCD:
 Lower four bits represent BCD number and upper bits are zero.
e.g. 9 = 0000 1001 5 = 0000 0101
Packed BCD:
 In packed BCD, eight bits are used for two BCD numbers.
 Lower 4 bits represent one BCD number upper 4 bits represent another
BCD number.
e.g. 29 = 0010 1001 56 = 0101 0110
ASCII numbers:
 ASCII (American standard Code for Information Interchange).
 In ASCII keyboards, when key “0” is pressed, the code “0011 0000” (30H)
is provided to computer. Similarly “0011 0001” (31H) is provide for key 1.
Key ASCII CODE Binary BCD (unpacked)
0 30H 0011 0000 0000 0000
1 31H 0011 0001 0000 0001
2 32H 0011 0010 0000 0010
3 33H 0011 0011 0000 0011
4 34H 0011 0100 0000 0100
5 35H 0011 0101 0000 0101
6 36H 0011 0110 0000 0110
7 37H 0011 0111 0000 0111
8 38H 0011 1000 0000 1000
9 39H 0011 1001 0000 1001
15CS44 microprocessors & Microcontrollers
Kishore kumar R RLJIT page 19
ASCII to Unpacked BCD Conversion:
Steps:
1. Perform AND operation on ASCII number and “0000 1111” (0FH) to
convert ASCII number to Unpacked BCD.
e.g.
ASC DB ‘3’ ASC
BCD DB ? BCD
MOV AL,ASC ; AL= 33
AND AL,0FH ; 33 AND 0F = 03 , AL= 03
MOV BCD,AL
Program: Write a program to convert 5 ASCII digits to Unpacked BCD.
.MODEL SMALL ASC BX
.DATA
ASC DB ‘98765’
UNPACK DB 10 DUP(?)
.CODE
MOV AX,@DATA
MOV DS,AX UNPACK SI
MOV CX,5
MOV BX, OFFSET ASC
MOV SI,OFFSET UNPACK
BACK:MOV AL, [BX]
AND AL, 0FH
MOV [SI],AL
INC BX
INC SI
LOOP BACK
INT 3
END
33
03
39
38
37
36
3535
09
08
07
06
05
15CS44 microprocessors & Microcontrollers
Kishore kumar R RLJIT page 20
ASCII to Packed BCD Conversion:
Steps:
1. Perform AND operation on ASCII number and 0F0FH to get unpacked BCD
number.
2. Perform OR operation on Unpacked BCD numbers to get Packed BCD
number.
e.g.
Convert ASCII number 47(3437) to packed BCD(47)
ASC DB ‘47’ ASC
BCD DB ?
MOV AX,ASC; AX = 37 34 BCD
AND AX,0F0FH; 37 34 AND 0F0F = 0704 AX
XCHG AH,AL ; AX= 0407
MOV CL,4
SHL AH,CL; AX =40 07
OR AL,AH; 07 OR 40 = 47  AL
MOV BCD,AL
Packed BCD to ASCII Conversion:
Steps:
1. Perform AND operation on Packed BCD and F00FH to get unpacked BCD
number
2. Perform OR operation unpacked BCD number and 3030H to get ASCII
numbers.
Convert packed BCD 29H to ASCII numbers 32 39
BCD DB 29H BCD
ASC DW ? ASC
MOV AL,BCD; AL =29H
MOV AH,AL; AX = 29 29
AND AX,F00FH; 29 29 AND F0 0F = 20 09
MOV CL,4
34
37
47
32
29
39
15CS44 microprocessors & Microcontrollers
Kishore kumar R RLJIT page 21
SHR AH,CL; AX=02 09
OR AX, 3030H; 02 09 OR 3030 = 32 39
XCHG AH,AL; AX= 39 32
MOV ASC, AX
BCD addition and Correction:
 BCD number can only have digits from 0000 to 1001 (0 to 9)
 Addition of BCD numbers must give valid BCD result (0 t 9)
 If result is not valid BCD it must be corrected by adding 06H or 60H or 66H.
e.g. Add 17H and 28H
17H = 0001 0111
28H = 0010 1000
---------------------------
3FH = 0011 1111 Result is incorrect because F is not BCD number
06H = 0000 0110
-----------------------------
0100 0101
------------------------------
Add 52H and 87H
52H = 0101 0010
87H = 1000 0111
----------------------------
D9H= 1101 1001 Result is incorrect because D is not BCD number
60H = 0110 0000
------------------------------
1 0011 1001
------------------------------
DAA (Decimal Adjust for Addition):
 DAA is used to correct the BCD result.
 DAA works only on AL.
 DAA must be used for ADD or ADC instruction.
Syntax: DAA
Operation:
1. After ADD or ADC if lower nibble is greater than 9 or AF=1 add 60H to AL
2. If upper nibble is greater than 9 or CF=1 add 60H to AL.
15CS44 microprocessors & Microcontrollers
Kishore kumar R RLJIT page 22
e.g.
MOV AL,47H; AL=47H
MOV BL, 25H; BL=25H
ADD AL,BL AL=6CH
DAA ; AL+06H=6CH + 06H =72H AL=72H
DAS (decimal adjust for subtraction):
 DAS is used to correct the BCD result
 DAS works only on AL
 DAS must be used after SUB or SBB instruction
Syntax: DAS
Operation:
 After SUB or SBB if lower nibble is greater than 9 or AF =1 subtract 06H
from AL
 If upper nibble is greater than 9 or CF =1 subtract 60H to AL
Rotate Instructions:
 Rotate instructions rotate the bits of any register or memory location from
one end to another or through the carry.
 There are four types of rotate instructions
1. Rotate left ( ROL)
2. Rotate Right (ROR)
3. Rotate through carry left (RCL)
4. Rotate through carry Right (RCR)
ROL (Rotate left):
• This instruction rotates the contents of destination left by the number of bits specified in
the count.
• MSB bits are rotated into the right most bit (LSB) and into the carry flag (CF).
• If count is more than 1, CL must contain count.
Syntax: ROL Destination,Count
Operation:
15CS44 microprocessors & Microcontrollers
Kishore kumar R RLJIT page 23
e.g. MOV BH,72H ; BH=0111 0010
ROL BH,1 ; CF=0 BH = 1110 0100
To rotate the contents of BH by 4 positions, instructions are
MOV BH, 72H; BH = 0111 0010
MOV CL, 4 CL=4 number of times to rotate
ROL BH, CL CF=1 BH = 0010 0111
ROR (Rotate Right):
• This instruction rotates the contents of destination right by the number of bits specified in
the count.
• LSB bits are rotated into the left most bit (MSB) and into the carry flag (CF).
• If count is more than 1, CL must contain count.
Syntax: ROR Destination, Count
Operation:
e.g. MOV AL, 36H; AL = 0011 0110
ROR AL,1 AL = 0001 1011 CF=0
RCR (Rotate right through carry):
• This instruction rotates the contents of the destination right through carry flag bit by the
number of positions specified in the count.
• LSB bit is shifted into CF, and CF bit is shifted to MSB bit.
• If count is more than 1, CL must contain count.
Syntax: RCR Destination, Count
Operation:
e.g. MOV AL,06H ; AL = 0000 0110 CF=1
RCR AL,1 ; AL = 1000 0011 CF=0
Program: Write a program to count number of 1s in an byte
.MODEL SMALL
.DATA
NUM DB 97H NUM
COUNT DB ? COUNT
97
05
15CS44 microprocessors & Microcontrollers
Kishore kumar R RLJIT page 24
.CODE
MOV AX,@DATA
MOV DS,AX
MOV BL,0 ; BL to keep number of 1s
MOV CL,8; 8 rotations
MOV AL,NUM; AL = 97H= 1001 0111
RPT: ROR AL,1; AL = 1100 1011 CF=1
JNC NEXT; IF CF = 0 JUMP TO NEXT
INC BL ; IF CF=1, Increment BL
NEXT: DEC CL; decrement CL, after every rotation
JNZ RPT
MOV COUNT, BL; Store number of 1s in COUNT
INT 3
END
RCL (Rotate Left through Carry):
• This instruction rotates the contents of the destination left through carry flag bit by the
number of positions specified in the count.
• MSB bit is shifted into CF, and CF bit is shifted to LSB bit.
• If count is more than 1, CL must contain count.
Syntax: RCL Destination, Count
Operation:
e.g. MOV AL, 90H; CF=0 AL = 1001 0000
RCL AL,1 CF=1 AL= 0010 0000
2.2 INT 21H & INT 10H Programming:
2.2.1BIOS INT 10H Programming:
BIOS INT 10H provides many functions
1. Clearing the Screen
2. Setting the cursor to a specific Location
3. Get cursor Position
4. Changing the Video mode
5. Write character at cursor position
6. Writing a pixel
15CS44 microprocessors & Microcontrollers
Kishore kumar R RLJIT page 25
1.Clearing the Screen using INT 10H function 06H:
The instructions to clear the screen are
MOV AH,06H ;AH=06H TO Select scroll Function
MOV AL,00H ;AL=00 TO Clear entire screen
MOV BH,07 ;BH=07 Is normal attribute (white on black)
MOV CH,00 ;CH=00 row value of start point (Upper left corner)
MOV CL,00 ;CL=00 column value of start point
MOV DH,24 ;DH=24 row value of end point (Lower right corner)
MOV DL,79 ;DL=79 column value of end point
INT 10H ;CALL BIOS interrupt
2.Setting the Cursor Position to a Specific Location INT 10H Function 02H:
Instructions to set the cursor position are
MOV AH,02H
MOV BH,PAGE NUMBER(0-5)
MOV DH,ROW NUMBER(00-24)
MOV DL,COL NUMBER(00-79)
INT 10H
Example: Write a code to set cursor position at ROW=15 and column = 25
MOV AH,02H
MOV BH,0 ;PAGE 0
MOV DH,15
MOV DL,25
INT 10H
Program: Write a program that 1)clears the screen 2) set cursor at center of the screen
;To Clear the Screen
MOV AH,06H
MOV AL,00
MOV CH,00
MOV CL,00
MOV DH,24
MOV DL,79
INT 10H
;Setting the cursor at center of the screen
MOV AH,02H
MOV BH,00 ; page 0
MOV DH,12 ;12 row
MOV DL,39 ;39 column
INT 10H ;call BIOS interrupt
15CS44 microprocessors & Microcontrollers
Kishore kumar R RLJIT page 26
3.Get Cursor Position INT 10H Function 03H:
Instructions to get cursor Position
MOV AH,03H
MOV BH,00 ;Page 0
INT 10H ;call BIOS interrupt
After the execution of above instructions, registers DH contain ROW number and DL contain
Column number.
4.Changing Video Mode INT 10H Function 00H:
There are three video modes
1. Text mode (03H), 80 × 25 characters can be displayed
2. Graphics Mode(04H) (resolution= 320×200 = 64,000 pixels)
3. Graphics Mode(06H) (resolution = 640×200=128,000 pixels)
Instructions to change Video mode
MOV AH,00H
MOV AL, VIDEO MODE (03,04,06)
INT 10H
Program: write a code to change a video mode to text mode
MOV AH,00H
MOV AL,03H
INT 21H
Attribute byte in Monochrome Monitors:
 There is an attribute for each character on the screen.
 The attribute byte provides information such as color and intensity of the character
(foreground) and background.
15CS44 microprocessors & Microcontrollers
Kishore kumar R RLJIT page 27
The following are few possible variations of the attributes
Attribute Byte in CGA (Color Graphics Adapter) monitors:
 In CGA monitor, eight different colors can be used for background and foreground by
combining Red, Green, and Blue.
D7 D6 D5 D4 D3 D2 D1 D0
Blinking Red Green Blue Intensity Red Green Blue
Background Foreground
The table below shows few possible variations of attribute byte in CGA
Binary Hexadecimal Color Effect
0000 0000 00 Black on Black
0000 0001 01 Blue on Black
0001 0010 12 Green on Blue
0001 0100 14 Red on Blue
0001 1111 1F High-intensity White on Blue
5.Write a character at cursor position INT 10H Function 09H
Instructions to write a character at cursor position
MOV AH, 09H
MOV BH, Page Number
MOV AL, Character
MOV BL, Attribute
MOV CX, Number of characters to write
INT 10H
E.g. Write a Code to write a character ‘A’ 10 times at cursor position
MOV AH,09H
MOV AL,’A’
MOV BL,07 ;Black on White Attribute
MOV CX,10
INT 10H
15CS44 microprocessors & Microcontrollers
Kishore kumar R RLJIT page 28
E.g. Write a program that puts 20H ( ASCII Space Character) on the entire Screen. Use high –
intensity White on a Blue Background attribute
MOV AH,00 ;Change video mode function
MOV AL,03 ; set TEXT Mode
INT 10H
MOV AH,09H ;Write a character function
MOV BH,00 ;PAGE 0
MOV 20H ;20H ASCII code for space
MOV CX, 2000 ;Write space 2000 times
MOV BL,1FH ;High-Intensity White on Blue
INT 10H
6. Writing a Pixel INT 10H Function 0CH
Instructions to write a pixel
MOV AH,0CH
MOV CX, Column Number
MOV DX, Row Number
MOV BH,PAGE Number
MOV AL, PIXEL Value (01 for White 00 for Black)
INT 10H
Program: i) clear screen ii) set the video mode to CGA of 640×200 resolution and iii) Draw
Horizontal Line starting at Column=100, Row=50 and ending at column 200, Row 50
; To Clear Screen
MOV AH,06H
MOV AL,00
MOV CH,00
MOV CL,00
MOV DH,24
MOV DL,79
INT 10H
;To Set Video Mode to 640×200 Rsolution
MOV AH,00
MOV AL,06
INT 10H
;TO Draw Horizontal Line
MOV CX,100
MOV DX,50
BACK:MOV AH,0CH
MOV AL,01
INT 10H
INC CX
CMP CX,200
JNZ BACK
15CS44 microprocessors & Microcontrollers
Kishore kumar R RLJIT page 29
2.2.2 DOS Interrupt 21H
 DOS provides many functions to Users
 INT 21H can be used to call those Functions.
1. Outputting a String of Data to monitor INT 21H Function 09H
Instructions to display the string of data on monitor
MOV AH,09H
MOV DX, OFFSET address of string
INT 21H;
e.g. Write a code to Display string “welcome to RLJIT”
MSG DX
MSG DB “ Welcome to RLJIT$”
MOV AH,09H
MOV DX, OFFSET MSG or LEA DX, MSG
INT 21H
2. Outputting a single character on monitor INT 21H Function 02H
Instructions to display a character
MOV AH,02H
MOV AL, Character to be displayed
INT 21H
E.g. Write a Code to Display a character ‘J’
MOV AH,02H
MOV AL,’J’
INT 21H
3. Inputting a Single Character with ECHO
Instructions:
MOV AH,01H
INT 21H
After reading a character from keyboard, it will be stored in AL
4. Inputting a single character without Echo
Instructions: MOV AH,07H
INT 21H;
After reading a character from keyboard, it will be stored in AL
R
L
J
I
T
$
15CS44 microprocessors & Microcontrollers
Kishore kumar R RLJIT page 30
5. Inputting a String of Data from keyboard INT 21H Function 0AH
Steps:
1. Set AH=0AH
2. DX=OFFSET address at which the string of data is stored ( buffer area)
3. First byte in buffer contains size of the buffer
4. Second byte contains the length of the string
5. String will be stored from the third byte
Instructions:
MOV AH,0AH
MOV DX, OFFSET Variable-Name
INT 21H
E.g. Write a code to READ a string “USA: BEFORE AFTER
MSG DB 6,?,6 DUP(FF) MSG DX
MOV AH,0AH
LEA DX,MSG or MOV DX, OFFSET MSG
INT 21H
0DASCII Of ENTER Key
Carriage Return & Line Feed:
 Carriage Return & Line Feed are two ASCII characters
 ASCII of Carriage return = 13 or 0DH
 ASCII of Line Feed = 10 or 0AH
 Carriage return character returns a cursor to the beginning of current Line
 Line feed character moves cursor to next line.
LABEL:
 It is a assembler directive used to assign multiple names to same data.
Syntax: Name LABEL Attribute
e.g. P LABEL BYTE MSG P
MSG DB 10
In the above example, P and MSG are two different names for same Memory Location
6
FF
FF
FF
FF
FF
FF
6
3
U
S
A
0D
FF
FF
10
15CS44 microprocessors & Microcontrollers
Kishore kumar R RLJIT page 31
2.2.3 8086/8088 Interrupts:
Interrupt:
 It is an external event that informs the CPU that a device needs service.
 In 8086 there are 256 different interrupts: INT 00H to INT FFH
Interrupt Service Routine (ISR):
 ISR is a program that runs when Interrupt occurs.
 ISR is also called as Interrupt Handler.
Interrupt Vector:
 It is 4-byte number (two bytes for IP, two bytes for CS)
 Interrupt vector contains the address of ISR,
 There are 256 interrupt vectors
 Interrupt vectors are stored in first 1Kbytes of memory (00000H – 003FFH)
Determining address of Interrupt Vector:
 Each interrupt instruction has a numeric value
 The address of interrupt vector is determined by multiplying the interrupt numeric value
by 4.
e.g. INT 10H numeric value = 10H
address of interrupt vector = 10H × 4 =40H
List of interrupts for 8086/8088
15CS44 microprocessors & Microcontrollers
Kishore kumar R RLJIT page 32
Differences between INT and CALL instructions:
CALL INT
A call instruction can jump to any location
within 1-megabyte
INT instruction goes to a fixed memory
location in the interrupt vector table
CALL instruction is used by the programmer
in the program
Interrupt can occur at any time
CALL instruction cannot be masked INT can be masked
CALL instruction saves only CS:IP of next
instruction
INT saves Flag register, and CS:IP of next
instruction
At the end of the procedure instruction RET is
used, RET pops only CS and IP
IRET is used at the end of the interrupt
service routine (ISR), IRET pops flag register
and CS:IP
Problem: Find the physical and Logical address in the Interrupt vector table for INT 12H
and INT 8
i) INT 12H
Address = 12H ×4 =48H
Physical address = 00048H – 0004BH
Logical address = 0000:0048H – 0000: 004BH
ii) INT 8H
Address = 8H × 4 = 20H
Physical address = 00020H – 00023H
Logical address = 0000:0020H – 0000:0023H
Categories of Interrupts:
There are two types of Interrupts
1. Hardware Interrupts
2. Software Interrupts
Hardware Interrupts:
 Interrupts caused by Hardware devices are Hardware interrupts.
 Three Pins in 8086 are available for Hardware interrupts
1. INTR (interrupt Request)
2. NMI (Non-maskable Interrupt)
3. INTA (Interrupt Acknowledge)
15CS44 microprocessors & Microcontrollers
Kishore kumar R RLJIT page 33
INTR:
 This is an input signal to CPU
 INTR can be masked (ignored) and unmasked using instructions CLI and STI.
NMI:
 NMI is an input signal to CPU
 NMI cannot be masked and unmasked using CLI and STI.
Software Interrupts:
 Interrupts caused by Instructions are Software Interrupts.
Eg INT 21H and INT 10H are examples of Software Interrupts
Interrupts and Flag register:
 In flag register, bits D9 and D8 are used for interrupts
 D9 (IF) interrupt flag can be used to ENABLE or DISABLE the hardware interrupts.
 IF=1 interrupts are enabled, IF=0 interrupts are disabled
 Instructions CLI and STI can be used to clear and set the IF
 TF (Trap Flag) is used to Enable and Disable the Debugging Feature
Processing Interrupts:
When Interrupts occurs, following steps are executed
Steps:
1. Flag register is pushed on to the stack and SP is decremented by 2
2. IF, TF are both cleared
3. CS is pushed onto the stack SP is decremented by 2
4. IP is pushed on to the stack SP is decremented by 2
5. INT number is multiplied by 4 to get the address of vector to fetch ISR
6. From new CS and IP , CPU executes instructions
7. IRET pops IP, CS, and Flag register from stack.
Functions Associated with INT 00 to INT 04:
 INT 00 to INT 04 have predefined Functions
 These interrupts are called as conditional interrupts or exception interrupts.
 These interrupts occur when there are conditions that CPU is unable to handle.
15CS44 microprocessors & Microcontrollers
Kishore kumar R RLJIT page 34
INT 00 (Divide error):
 This interrupt occurs, when there is an attempt to divide number by zero.
e.g. MOV AX,92
MOV BL,0
DIV BL ; AX/BL 92/0 = undefined result Interrupt occurs
INT 01 (single Step):
 Executing Instructions one by one and examining the contents of the registers and
memory locations is called Single-Stepping.
 Single-stepping can be enabled using TF, after the execution of every instruction INT 01
will occur.
INT 02 (Non-maskable Interrupt):
 Whenever NMI pin is activated INT 02 will occur and CPU jumps to memory location
00008H to fetch Cs and IP of the ISR of NMI.
INT 03 (breakpoint):
 Breakpoint is used to examine the content of register or memory location after execution
of group of instructions.
INT 04 (Signed Number overflow):
 INT 04 is associated with instruction INTO (interrupt on overflow)
 INTO checks Overflow flag and calls INT04 when OF=1
Important Questions
1. Show how the flag register (ZF, CF, SF, PF, AF) is affected by following instructions
MOV AL, 0F5H
ADD AL, 0BH
2. Show how CPU would subtract 23H from 3FH
3. Write a program to calculate total sum of 5 bytes of data. Each byte represents daily wages of
a worker; the decimal data is as follows 125, 235, 197, 91, and 48.
4. Write a program to add N1= 12345678H and N2 = 12345678H
5. Write a program to subtract 412963BH from 62562FAH
6. Explain the Four cases of the DIVISION.
7. Write a program to multiply 25H and 65H
8. Explain the XOR instruction with example.
9. Write a program to divide 123456H by 1000H
10. Explain SHIFT and ROTATE instructions with Examples
15CS44 microprocessors & Microcontrollers
Kishore kumar R RLJIT page 35
11. Write a program to find highest grade in 69, 87, 96, 45 and 75
12. Explain with example, how BCD number 29H is converted to ASCII numbers 32H 39H
13. Write a program to convert 5 ASCII digits to Unpacked BCD
14. Write a program to count number of 1s in byte 97H
15. Write a program that 1)clears the screen 2) set cursor at center of the screen
16. Write a program that puts 20H ( ASCII Space Character) on the entire Screen. Use high –
intensity White on a Blue Background attribute
17. write a program to i) clear screen ii) set the video mode to CGA of 640×200 resolution and iii)
Draw Horizontal Line starting at Column=100, Row=50 and ending at column 200, Row 50
18. Explain Inputting a string of data Function with an example.
19. Give differences between INT and CALL instructions
20. Find the physical and Logical address in the Interrupt vector table for INT 12H and INT 8
21. What is Interrupt Vector?
22. Write the Steps for Processing Interrupts.

More Related Content

What's hot (20)

Assembly language 8086
Assembly language 8086Assembly language 8086
Assembly language 8086
 
Amba axi 29 3_2015
Amba axi 29 3_2015Amba axi 29 3_2015
Amba axi 29 3_2015
 
Logical instructions (and, or, xor, not, test)
Logical instructions (and, or, xor, not, test)Logical instructions (and, or, xor, not, test)
Logical instructions (and, or, xor, not, test)
 
Ambha axi
Ambha axiAmbha axi
Ambha axi
 
8086 instructions
8086 instructions8086 instructions
8086 instructions
 
Introduction to ARM
Introduction to ARMIntroduction to ARM
Introduction to ARM
 
8086 instruction set with types
8086 instruction set with types8086 instruction set with types
8086 instruction set with types
 
AMBA 2.0
AMBA 2.0AMBA 2.0
AMBA 2.0
 
Ascii adjust & decimal adjust
Ascii adjust & decimal adjustAscii adjust & decimal adjust
Ascii adjust & decimal adjust
 
8086 Architecture
8086 Architecture8086 Architecture
8086 Architecture
 
AMBA_APB_pst
AMBA_APB_pstAMBA_APB_pst
AMBA_APB_pst
 
Instruction set of 8086 Microprocessor
Instruction set of 8086 Microprocessor Instruction set of 8086 Microprocessor
Instruction set of 8086 Microprocessor
 
Shift rotate
Shift rotateShift rotate
Shift rotate
 
AMBA 5 COHERENT HUB INTERFACE.pptx
AMBA 5 COHERENT HUB INTERFACE.pptxAMBA 5 COHERENT HUB INTERFACE.pptx
AMBA 5 COHERENT HUB INTERFACE.pptx
 
Byte and string manipulation 8086
Byte and string manipulation 8086Byte and string manipulation 8086
Byte and string manipulation 8086
 
Superscalar and VLIW architectures
Superscalar and VLIW architecturesSuperscalar and VLIW architectures
Superscalar and VLIW architectures
 
8086 String Instructions.pdf
8086 String Instructions.pdf8086 String Instructions.pdf
8086 String Instructions.pdf
 
Axi
AxiAxi
Axi
 
x86 architecture
x86 architecturex86 architecture
x86 architecture
 
Pcie drivers basics
Pcie drivers basicsPcie drivers basics
Pcie drivers basics
 

Similar to 15CS44 MP & MC Module 2

8086-instruction-set-ppt
 8086-instruction-set-ppt 8086-instruction-set-ppt
8086-instruction-set-pptjemimajerome
 
8085 microprocessor(1)
8085 microprocessor(1)8085 microprocessor(1)
8085 microprocessor(1)Reevu Pal
 
Microprocessor 8086 instruction description
Microprocessor 8086 instruction descriptionMicroprocessor 8086 instruction description
Microprocessor 8086 instruction descriptionDheeraj Suri
 
Chap 3_2.ppt
Chap 3_2.pptChap 3_2.ppt
Chap 3_2.pptinian2
 
15CSL48 MP&MC manual
15CSL48 MP&MC manual15CSL48 MP&MC manual
15CSL48 MP&MC manualRLJIT
 
INTEL 8085 DATA FORMAT AND INSTRUCTIONS
INTEL 8085 DATA FORMAT AND INSTRUCTIONSINTEL 8085 DATA FORMAT AND INSTRUCTIONS
INTEL 8085 DATA FORMAT AND INSTRUCTIONSSwapnil Mishra
 
Chapter 3 instruction set-of-8085
Chapter 3 instruction set-of-8085Chapter 3 instruction set-of-8085
Chapter 3 instruction set-of-8085Shubham Singh
 
Mastering Assembly Language: Programming with 8086
Mastering Assembly Language: Programming with 8086Mastering Assembly Language: Programming with 8086
Mastering Assembly Language: Programming with 8086sravanithonta79
 
Chp6 assembly language programming for pic copy
Chp6 assembly language programming for pic   copyChp6 assembly language programming for pic   copy
Chp6 assembly language programming for pic copymkazree
 
Intel8086_Flags_Addr_Modes_sample_pgms.pdf
Intel8086_Flags_Addr_Modes_sample_pgms.pdfIntel8086_Flags_Addr_Modes_sample_pgms.pdf
Intel8086_Flags_Addr_Modes_sample_pgms.pdfAnonymous611358
 
Assembly Language Basics
Assembly Language BasicsAssembly Language Basics
Assembly Language BasicsEducation Front
 
HKG15-405: Redundant zero/sign-extension elimination in GCC
HKG15-405: Redundant zero/sign-extension elimination in GCCHKG15-405: Redundant zero/sign-extension elimination in GCC
HKG15-405: Redundant zero/sign-extension elimination in GCCLinaro
 

Similar to 15CS44 MP & MC Module 2 (20)

8086-instruction-set-ppt
 8086-instruction-set-ppt 8086-instruction-set-ppt
8086-instruction-set-ppt
 
8086 Instruction set
8086 Instruction set8086 Instruction set
8086 Instruction set
 
Instruction formats-in-8086
Instruction formats-in-8086Instruction formats-in-8086
Instruction formats-in-8086
 
8085 microprocessor(1)
8085 microprocessor(1)8085 microprocessor(1)
8085 microprocessor(1)
 
Mod-2.pptx
Mod-2.pptxMod-2.pptx
Mod-2.pptx
 
Microprocessor 8086 instruction description
Microprocessor 8086 instruction descriptionMicroprocessor 8086 instruction description
Microprocessor 8086 instruction description
 
Chap 3_2.ppt
Chap 3_2.pptChap 3_2.ppt
Chap 3_2.ppt
 
15CSL48 MP&MC manual
15CSL48 MP&MC manual15CSL48 MP&MC manual
15CSL48 MP&MC manual
 
INTEL 8085 DATA FORMAT AND INSTRUCTIONS
INTEL 8085 DATA FORMAT AND INSTRUCTIONSINTEL 8085 DATA FORMAT AND INSTRUCTIONS
INTEL 8085 DATA FORMAT AND INSTRUCTIONS
 
Chapter 3 instruction set-of-8085
Chapter 3 instruction set-of-8085Chapter 3 instruction set-of-8085
Chapter 3 instruction set-of-8085
 
Module 2 (1).pptx
Module 2 (1).pptxModule 2 (1).pptx
Module 2 (1).pptx
 
Arithmetic instrctions
Arithmetic instrctionsArithmetic instrctions
Arithmetic instrctions
 
Mastering Assembly Language: Programming with 8086
Mastering Assembly Language: Programming with 8086Mastering Assembly Language: Programming with 8086
Mastering Assembly Language: Programming with 8086
 
Chp6 assembly language programming for pic copy
Chp6 assembly language programming for pic   copyChp6 assembly language programming for pic   copy
Chp6 assembly language programming for pic copy
 
8255 programming
8255 programming8255 programming
8255 programming
 
Intel8086_Flags_Addr_Modes_sample_pgms.pdf
Intel8086_Flags_Addr_Modes_sample_pgms.pdfIntel8086_Flags_Addr_Modes_sample_pgms.pdf
Intel8086_Flags_Addr_Modes_sample_pgms.pdf
 
Assembly Language Basics
Assembly Language BasicsAssembly Language Basics
Assembly Language Basics
 
Addressing modes
Addressing modesAddressing modes
Addressing modes
 
HKG15-405: Redundant zero/sign-extension elimination in GCC
HKG15-405: Redundant zero/sign-extension elimination in GCCHKG15-405: Redundant zero/sign-extension elimination in GCC
HKG15-405: Redundant zero/sign-extension elimination in GCC
 
LCD_Example.pptx
LCD_Example.pptxLCD_Example.pptx
LCD_Example.pptx
 

Recently uploaded

Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...VICTOR MAESTRE RAMIREZ
 
microprocessor 8085 and its interfacing
microprocessor 8085  and its interfacingmicroprocessor 8085  and its interfacing
microprocessor 8085 and its interfacingjaychoudhary37
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfAsst.prof M.Gokilavani
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxPoojaBan
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoão Esperancinha
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
Current Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLCurrent Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLDeelipZope
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerAnamika Sarkar
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxpurnimasatapathy1234
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort servicejennyeacort
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxDeepakSakkari2
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx959SahilShah
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024hassan khalil
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learningmisbanausheenparvam
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130Suhani Kapoor
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...Soham Mondal
 

Recently uploaded (20)

Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...
 
microprocessor 8085 and its interfacing
microprocessor 8085  and its interfacingmicroprocessor 8085  and its interfacing
microprocessor 8085 and its interfacing
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptx
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
Current Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLCurrent Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCL
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptx
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptx
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learning
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
 
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
 
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
 
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptxExploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
 

15CS44 MP & MC Module 2

  • 1. 15CS44 microprocessors & Microcontrollers Kishore kumar R RLJIT page 1 MODULE -2 X86 Instructions sets description Topics: 2.1 Arithmetic and logic instructions 2.1.1 Unsigned addition and subtraction 2.1.2 Unsigned multiplication & division 2.1.3 Logic Instructions 2.1.4 BCD & ASCII conversion 2.1.5 Rotate Instructions 2.2 INT 21H & INT 10H programming 2.2.1 BIOS INT 10 H programming 2.2.2 DOS Interrupt 21H 2.2.3 8086/8088 interrupts 2.2.4 x86 and interrupt Assignment
  • 2. 15CS44 microprocessors & Microcontrollers Kishore kumar R RLJIT page 2 2.1.1 Unsigned addition and subtraction Unsigned numbers:  Numbers in which all bits are used to represent data and no bits are used for the sign. E.g. 4 = 100 In the above example all three bits are used to represent the value of 4 Addition:  The Opcode for addition is ADD. Syntax: ADD destination, source; Operation: destination = destination + source Flags affected: AF, CF, PF, ZF, SF, OF E.g. ADD AL, BL ; AL = AL + BL Problem: show how the flag register is affected by following instructions MOV AL, 0F5H ADD AL, 0BH Sol ) F5H = 1111 0101 + + 0BH= 0000 1011 --------------------- 0000 0000 --------------------- After addition AL = 0000 0000 CF= 1  since there is carry out from MSB SF =0  sign is positive (0) PF=1  number of 1s is zero (even parity) AF =1 there is a carry from position 3 to 4 ZF = 1  result is zero
  • 3. 15CS44 microprocessors & Microcontrollers Kishore kumar R RLJIT page 3 Byte Addition: Program1: write a program to calculate total sum of 5 bytes of data. Each byte represents daily wages of a worker; the decimal data is as follows 125, 235, 197, 91, 48 125 = 7DH, 235 = EBH, 197= C5H, 91= 5BH, 48 = 30H Program: PAGE 60,132 TITLE ADDING 5 BYTES MODEL SMALL .DATA ARR DB 7DH,EBH,C5H,5BH,30H ARR SI RES DW ? .CODE MOV AX,@DATA MOV DS,AX MOV SI,OFFSET ARR MOV CX,5 RES MOV AX,0 BACK:ADD AL,[SI] ADC AH,0 INC SI DEC CX JNZ BACK MOV RES,AX INT 3 END WORD Addition: Case1: Adding single word numbers Case 2: adding multiword numbers 7D EB C5 5B 30 B8 02
  • 4. 15CS44 microprocessors & Microcontrollers Kishore kumar R RLJIT page 4 Case1: Adding single word numbers Program 2: write a program to calculate total sum of 5 words of data. Each word represents yearly wages of a worker; the decimal data is as follows 27345, 28521, 29533, 30105, and 32375 27345= 6AD1H , 28521=6F69H, 29533=735DH, 7599H, 7E77H Program: PAGE 60,132 TITLE Adding 5 Words of data .MODEL SMALL .DATA ARR DW 6AD1H,6F69H,735DH,7599H,7E77H ARR SUM DD ? .CODE MOV AX,@DATA MOV DS,AX MOV CL,5 MOV SI,OFFSET ARR MOV AX,0 MOV BX,0 BACK: ADD AX,[SI] ADC BX,0 RES ADD SI,2 DEC CL JNZ BACK MOV SUM,AX MOV SUM+2,BX INT 3 END D1 6A 69 6F 5D 73 99 75 77 7E A7 41 02 00
  • 5. 15CS44 microprocessors & Microcontrollers Kishore kumar R RLJIT page 5 Case 2: Addition of Multiword numbers: Write a program to add N1= 12345678H and N2 = 12345678H Program: PAGE 60,132 TITLE Adding Multiword Numbers N1 .MODEL SMALL .DATA N1 DD 12345678H N2 DD 12345678H N2 RES DQ ? .CODE MOV AX,@DATA RES MOV DS,AX MOV CL,2 CLC MOV SI,OFFSET N1 MOV DI,OFFSET N2 MOV BX,OFFSET RES BACK:MOV AX,[SI] ADC AX,[DI] MOV [BX],AX ADD SI,2 ADD DI,2 ADD BX,2 DEC CL JNZ BACK INT 3 END 78 56 34 12 78 56 34 12 F0 AC 68 24 00 00 00 00
  • 6. 15CS44 microprocessors & Microcontrollers Kishore kumar R RLJIT page 6 Subtraction of Unsigned Numbers: SUB:  The opcode for subtraction is SUB  It subtracts the source from the destination and places result in the destination Syntax: SUB destination, source Operation: destination = destination – source Flags affected: CF, AF, PF, SF, OF, ZF Steps for unsigned subtraction: 1. Take 2’s complement of subtrahend (source operand) 2. Add it to minuend (destination operand) 3. Invert the carry 4. After the result if CF=0, the result is positive if CF=1 result is negative Example:
  • 7. 15CS44 microprocessors & Microcontrollers Kishore kumar R RLJIT page 7 SBB (subtract with borrow):  This instruction subtracts the contents of carry flag from the difference of the operands.  This instruction is used for multi-byte or multi-word numbers Syntax: SBB destination, source Operation : destination = destination - source - CF e.g. SBB AH, AL ; AH = AH - AL – Carry SBB CL, 2; CL = CL - 2 – carry Program 1 : Subtract 6EH from 4CH .MODEL SMALL .DATA NUM1 DB 4CH NUM2 DB 6EH RES DB ? .CODE MOV AX,@DATA MOV DS,AX MOV DH,NUM1; DH = 4CH SUB DH,NUM2; DH=DH-6EH JNC NEXT NOT DH INC DH NEXT:MOV RES,DH INT 3 END Analysis: 4C-6E = -22 0 1 0 0 1 1 0 0 1 0 0 1 0 0 1 0 (2’s complement) ----------------------- CF=0 1 1 0 1 1 1 1 0 Invert carry flag CF=1 , hence result is negative so take 2’s complement of result 2’s complement of result = 0010 0010 = 22 CF=1 hence result is -22
  • 8. 15CS44 microprocessors & Microcontrollers Kishore kumar R RLJIT page 8 Program2: subtract 412963BH from 62562FAH .MODEL SMALL .DATA NUM1 DD 62562FAH NUM1 NUM2 DD 412963BH RES DD ? .CODE MOV AX,@DATA MOV DS,AX NUM2 MOV AX, NUM1; AX = 62FA SUB AX,NUM2; AX = AX-62FA MOV RES,AX MOV AX,NUM1+2 SBB AX, NUM2+2 RES MOV RES+2,AX INT 3 END Analysis: 62FA – 963B = CCBF AX and CF=1 When SBB is executed 625 – 412 – 1 = 212 2.1.2 Unsigned Multiplication: Unsigned Multiplication: There are four cases in unsigned multiplication 1. BYTE × BYTE 2. WORD × WORD 3. BYTE × WORD 625 62fA 412 963B ----------------- 0212 CCBF ------------------ FA 62 25 06 3B 96 12 04 BF CC 12 02
  • 9. 15CS44 microprocessors & Microcontrollers Kishore kumar R RLJIT page 9 BYTE × BYTE:  In byte × byte multiplication, multiplicand must be in AL register and the second operand can be either in 8-bit register or 8-bit memory location and result will be stored in AX Syntax: MUL 8-bit register / memory location Operation : AX = AL × 8-bit register/ memory location e.g.1 MUL BL e.g.2 MUL NUM2 AX= AL × BL AX = AL × NUM2 Program 1: multiply 25H and 65H .MODEL SMALL .DATA RES DW ? .CODE MOV AX,@DATA MOV DS,AX MOV AL,25H; AL =25H MOV BL,65H; BL = 65H MUL BL; AX = AL × BL MOV RES, AX INT 3 END WORD × WORD:  In word×word multiplication, multiplicand must be in AX and multiplier can be in any 16-bit register or memory location and result will be stored in DX:AX  DX contains higher word of the result and AX contains lower word of the result. Syntax: MUL 16-bit register/memory location DX:AX = AX * 16-bit register /memory location e.g.1 MUL BX e.g.2 MUL WORD PTR [BX] DX:AX = AX * BX DX:AX = AX * [BX] [BX] is 16-bit memory location
  • 10. 15CS44 microprocessors & Microcontrollers Kishore kumar R RLJIT page 10 BYTE × WORD:  It is similar to word × word multiplication except that AL contains byte operand and AH must be cleared. Unsigned multiplication summary: Multiplication Multiplicand Multiplier Result BYTE × BYTE AL 8-Bit Register/ memory location AX WORD × WORD AX 16-Bit Register/ memory location DX:AX BYTE × WORD AL =byte AH=0 16-Bit Register/ memory location DX:AX Division of unsigned numbers: There are four cases in unsigned division 1. Byte over byte 2. Word over word 3. Word over byte 4. Double word over word Byte / Byte division:  In byte / byte division, numerator (dividend) must be in AL register and AH must be zero.  The denominator (divisor) can be in any 8-bit register or memory location  After division, quotient will be in AL and remainder will be in AH Syntax: DIV 8-bit register / memory location e.g. DIV BL; AX / BL AL = quotient AH =remainder the following instructions shows various addressing modes that denominator can take NUM1 DB 95 NUM1 NUM2 DB 10 QUO DB ? NUM2 REM DB ? QUO REM 95 10
  • 11. 15CS44 microprocessors & Microcontrollers Kishore kumar R RLJIT page 11 Using Direct Addressing mode: MOV AL,NUM1; AL=95 MOV AH,0 DIV NUM2; AX/10 AL=9 AH=5 MOV QUO,AL MOV REM,AH Using Register Addressing Mode: MOV AL, NUM1; AL=95 MOV AH, 0 MOV BL,NUM2 ; BL=10 DIV BL; AX/BL = 95/10 AL=9 AH=5 MOV QUO, AL MOV REM,AH Using Register Indirect addressing mode: MOV AL, NUM1; AL=95 MOV AH, 0 MOV BX, OFFSET NUM2 DIV BYTE PTR BX; 95/10 AL=9 AH=5 MOV QUO, AL MOV REM, AH Word/Word Division:  In Word/Word division, numerator (dividend) is in AX and DX must be zero  Denominator (divisor) can be in any 16-bit register or memory location  After division, AX contains quotient, and DX contains remainder Syntax: DIV 16-bit register / memory location e.g. MOV AX,9000 MOV DX,0 MOV BX,100 DIV BX; DX:AX/BX  9000/ 100 AX=90 DX=0 Word/Byte:  Dividend is in AX, divisor in any 8-bit register or memory location  After division, AL contains quotient AH contains remainder
  • 12. 15CS44 microprocessors & Microcontrollers Kishore kumar R RLJIT page 12 e.g. DIV BL ; AX/BL AL = quotient AH = remainder Double-word / Word:  Dividend is in DX:AX  Divisor can be in any 16-bit register or memory location  After division, AX contains quotient and DX contains remainder Syntax: DIV 16-bit register or memory location e.g. NUM1 DD 123456H NUM2 DW 1000H MOV AX, NUM1; AX= 3456 MOV DX,NUM1+2 DX= 0012 MOV BX, NUM2; BX=1000 DIV BX; 123456/ 1000 AX= 123 DX=456 2.1.3 Logic instructions: AND:  This instruction performs AND operation on source and destination and stores result in Destination.  AND instruction automatically changes CF and OF to zero and PF, ZF and SF are set according to result. Syntax: AND Destination, Source Function: destination = destination AND Source e.g. AND AL, BL ; AL = AL AND BL
  • 13. 15CS44 microprocessors & Microcontrollers Kishore kumar R RLJIT page 13 OR:  This instruction performs OR operation on destination and source and stores result in destination.  OR instruction automatically changes CF and OF to zero and PF, ZF and SF are set according to result. e.g. XOR:  It performs exclusive-OR operation on destination and source and stores result in destination.  XOR instruction clears CF and OF and SF, OF, PF are set according to the result. Syntax: XOR destination, source Functions: destination = destination XOR Source e.g.
  • 14. 15CS44 microprocessors & Microcontrollers Kishore kumar R RLJIT page 14 SHIFT: There are two types of shifts 1. Logical shifts 2. Arithmetic shifts Logical Shifts: There are two types of Logical shifts 1. Logical Shift Right (SHR) 2. Logical Shift Left (SHL) SHR:  SHR shifts the contents of the destination right by the number of bits specified in the count  LSB bit is shifted to carry flag (CF)  Zero is shifted to MSB  If count is greater than 1, count should be in CL Syntax: SHR destination, count Operation: e.g. SHR AL, 1 ; the contents of AL are shifted left by one position
  • 15. 15CS44 microprocessors & Microcontrollers Kishore kumar R RLJIT page 15 SHL:  SHR shifts the contents of the destination Left by the number of bits specified in the count  MSB bit is shifted to carry flag (CF)  Zero is shifted to LSB  If count is greater than 1, count should be in CL Syntax: SHL destination, count Operation: e.g SHL AL,1 ; contents of AL are shifted left by one position
  • 16. 15CS44 microprocessors & Microcontrollers Kishore kumar R RLJIT page 16 Arithmetic Shifts: There are two types of arithmetic shifts 1. Shift Arithmetic Right (SAR) 2. Shift Arithmetic Left (SAL) SAR:  This instruction shifts the signed number in destination right by the number of bits specified in count.  This instruction retains (preserves) the MSB (sign bit)  LSB is shifted to carry flag (CF)  If count is greater than 1, count should be in CL Syntax: SAR destination, count Operation: e.g. MOV AL, -10 ; AL = -10 SAR AL,1; AL = -5 SAL:  SAL is similar to SHL Syntax: SAL destination, count Operation:
  • 17. 15CS44 microprocessors & Microcontrollers Kishore kumar R RLJIT page 17 Compare of Signed Numbers: CMP (compare):  This instruction compares destination and source and changes flags CF, SF, ZF according to the result.  Destination can be any register or memory location  Source can be any register or memory location or immediate data. Syntax: CMP Destination, Source Operation: destination – source Flags affected: CF, SF, ZF Program: Write a program to find highest grade in 69, 87, 96, 45 and 75 .MODEL SMALL .DATA GRADES DB 69, 87, 96, 45, 75 GRADES HIGHEST DB ? .CODE MOV AX,@DATA MOV DS,AX MOV CX,4 MOV SI, OFFSET GRADES MOV AL,[SI]; AL contains first grade HIGHEST BACK:INC SI ; point to next grade CMP AL,[SI]; compare next grade to higher JA NEXT ; jump if AL is higher MOV AL,[SI]; AL contains highest grade NEXT: LOOP BACK ; Jump to back if cx≠0 MOV HIGHEST, AL; move highest grade from AL to memory location INT 3 END 655 87 96 45 75 96
  • 18. 15CS44 microprocessors & Microcontrollers Kishore kumar R RLJIT page 18 2.1.4 BCD and ASCII Conversion BCD:  BCD stands for Binary coded decimal.  Binary representation of 0 to 9 is called BCD. There are two types of BCD 1. Unpacked BCD 2. Packed BCD Unpacked BCD:  Lower four bits represent BCD number and upper bits are zero. e.g. 9 = 0000 1001 5 = 0000 0101 Packed BCD:  In packed BCD, eight bits are used for two BCD numbers.  Lower 4 bits represent one BCD number upper 4 bits represent another BCD number. e.g. 29 = 0010 1001 56 = 0101 0110 ASCII numbers:  ASCII (American standard Code for Information Interchange).  In ASCII keyboards, when key “0” is pressed, the code “0011 0000” (30H) is provided to computer. Similarly “0011 0001” (31H) is provide for key 1. Key ASCII CODE Binary BCD (unpacked) 0 30H 0011 0000 0000 0000 1 31H 0011 0001 0000 0001 2 32H 0011 0010 0000 0010 3 33H 0011 0011 0000 0011 4 34H 0011 0100 0000 0100 5 35H 0011 0101 0000 0101 6 36H 0011 0110 0000 0110 7 37H 0011 0111 0000 0111 8 38H 0011 1000 0000 1000 9 39H 0011 1001 0000 1001
  • 19. 15CS44 microprocessors & Microcontrollers Kishore kumar R RLJIT page 19 ASCII to Unpacked BCD Conversion: Steps: 1. Perform AND operation on ASCII number and “0000 1111” (0FH) to convert ASCII number to Unpacked BCD. e.g. ASC DB ‘3’ ASC BCD DB ? BCD MOV AL,ASC ; AL= 33 AND AL,0FH ; 33 AND 0F = 03 , AL= 03 MOV BCD,AL Program: Write a program to convert 5 ASCII digits to Unpacked BCD. .MODEL SMALL ASC BX .DATA ASC DB ‘98765’ UNPACK DB 10 DUP(?) .CODE MOV AX,@DATA MOV DS,AX UNPACK SI MOV CX,5 MOV BX, OFFSET ASC MOV SI,OFFSET UNPACK BACK:MOV AL, [BX] AND AL, 0FH MOV [SI],AL INC BX INC SI LOOP BACK INT 3 END 33 03 39 38 37 36 3535 09 08 07 06 05
  • 20. 15CS44 microprocessors & Microcontrollers Kishore kumar R RLJIT page 20 ASCII to Packed BCD Conversion: Steps: 1. Perform AND operation on ASCII number and 0F0FH to get unpacked BCD number. 2. Perform OR operation on Unpacked BCD numbers to get Packed BCD number. e.g. Convert ASCII number 47(3437) to packed BCD(47) ASC DB ‘47’ ASC BCD DB ? MOV AX,ASC; AX = 37 34 BCD AND AX,0F0FH; 37 34 AND 0F0F = 0704 AX XCHG AH,AL ; AX= 0407 MOV CL,4 SHL AH,CL; AX =40 07 OR AL,AH; 07 OR 40 = 47  AL MOV BCD,AL Packed BCD to ASCII Conversion: Steps: 1. Perform AND operation on Packed BCD and F00FH to get unpacked BCD number 2. Perform OR operation unpacked BCD number and 3030H to get ASCII numbers. Convert packed BCD 29H to ASCII numbers 32 39 BCD DB 29H BCD ASC DW ? ASC MOV AL,BCD; AL =29H MOV AH,AL; AX = 29 29 AND AX,F00FH; 29 29 AND F0 0F = 20 09 MOV CL,4 34 37 47 32 29 39
  • 21. 15CS44 microprocessors & Microcontrollers Kishore kumar R RLJIT page 21 SHR AH,CL; AX=02 09 OR AX, 3030H; 02 09 OR 3030 = 32 39 XCHG AH,AL; AX= 39 32 MOV ASC, AX BCD addition and Correction:  BCD number can only have digits from 0000 to 1001 (0 to 9)  Addition of BCD numbers must give valid BCD result (0 t 9)  If result is not valid BCD it must be corrected by adding 06H or 60H or 66H. e.g. Add 17H and 28H 17H = 0001 0111 28H = 0010 1000 --------------------------- 3FH = 0011 1111 Result is incorrect because F is not BCD number 06H = 0000 0110 ----------------------------- 0100 0101 ------------------------------ Add 52H and 87H 52H = 0101 0010 87H = 1000 0111 ---------------------------- D9H= 1101 1001 Result is incorrect because D is not BCD number 60H = 0110 0000 ------------------------------ 1 0011 1001 ------------------------------ DAA (Decimal Adjust for Addition):  DAA is used to correct the BCD result.  DAA works only on AL.  DAA must be used for ADD or ADC instruction. Syntax: DAA Operation: 1. After ADD or ADC if lower nibble is greater than 9 or AF=1 add 60H to AL 2. If upper nibble is greater than 9 or CF=1 add 60H to AL.
  • 22. 15CS44 microprocessors & Microcontrollers Kishore kumar R RLJIT page 22 e.g. MOV AL,47H; AL=47H MOV BL, 25H; BL=25H ADD AL,BL AL=6CH DAA ; AL+06H=6CH + 06H =72H AL=72H DAS (decimal adjust for subtraction):  DAS is used to correct the BCD result  DAS works only on AL  DAS must be used after SUB or SBB instruction Syntax: DAS Operation:  After SUB or SBB if lower nibble is greater than 9 or AF =1 subtract 06H from AL  If upper nibble is greater than 9 or CF =1 subtract 60H to AL Rotate Instructions:  Rotate instructions rotate the bits of any register or memory location from one end to another or through the carry.  There are four types of rotate instructions 1. Rotate left ( ROL) 2. Rotate Right (ROR) 3. Rotate through carry left (RCL) 4. Rotate through carry Right (RCR) ROL (Rotate left): • This instruction rotates the contents of destination left by the number of bits specified in the count. • MSB bits are rotated into the right most bit (LSB) and into the carry flag (CF). • If count is more than 1, CL must contain count. Syntax: ROL Destination,Count Operation:
  • 23. 15CS44 microprocessors & Microcontrollers Kishore kumar R RLJIT page 23 e.g. MOV BH,72H ; BH=0111 0010 ROL BH,1 ; CF=0 BH = 1110 0100 To rotate the contents of BH by 4 positions, instructions are MOV BH, 72H; BH = 0111 0010 MOV CL, 4 CL=4 number of times to rotate ROL BH, CL CF=1 BH = 0010 0111 ROR (Rotate Right): • This instruction rotates the contents of destination right by the number of bits specified in the count. • LSB bits are rotated into the left most bit (MSB) and into the carry flag (CF). • If count is more than 1, CL must contain count. Syntax: ROR Destination, Count Operation: e.g. MOV AL, 36H; AL = 0011 0110 ROR AL,1 AL = 0001 1011 CF=0 RCR (Rotate right through carry): • This instruction rotates the contents of the destination right through carry flag bit by the number of positions specified in the count. • LSB bit is shifted into CF, and CF bit is shifted to MSB bit. • If count is more than 1, CL must contain count. Syntax: RCR Destination, Count Operation: e.g. MOV AL,06H ; AL = 0000 0110 CF=1 RCR AL,1 ; AL = 1000 0011 CF=0 Program: Write a program to count number of 1s in an byte .MODEL SMALL .DATA NUM DB 97H NUM COUNT DB ? COUNT 97 05
  • 24. 15CS44 microprocessors & Microcontrollers Kishore kumar R RLJIT page 24 .CODE MOV AX,@DATA MOV DS,AX MOV BL,0 ; BL to keep number of 1s MOV CL,8; 8 rotations MOV AL,NUM; AL = 97H= 1001 0111 RPT: ROR AL,1; AL = 1100 1011 CF=1 JNC NEXT; IF CF = 0 JUMP TO NEXT INC BL ; IF CF=1, Increment BL NEXT: DEC CL; decrement CL, after every rotation JNZ RPT MOV COUNT, BL; Store number of 1s in COUNT INT 3 END RCL (Rotate Left through Carry): • This instruction rotates the contents of the destination left through carry flag bit by the number of positions specified in the count. • MSB bit is shifted into CF, and CF bit is shifted to LSB bit. • If count is more than 1, CL must contain count. Syntax: RCL Destination, Count Operation: e.g. MOV AL, 90H; CF=0 AL = 1001 0000 RCL AL,1 CF=1 AL= 0010 0000 2.2 INT 21H & INT 10H Programming: 2.2.1BIOS INT 10H Programming: BIOS INT 10H provides many functions 1. Clearing the Screen 2. Setting the cursor to a specific Location 3. Get cursor Position 4. Changing the Video mode 5. Write character at cursor position 6. Writing a pixel
  • 25. 15CS44 microprocessors & Microcontrollers Kishore kumar R RLJIT page 25 1.Clearing the Screen using INT 10H function 06H: The instructions to clear the screen are MOV AH,06H ;AH=06H TO Select scroll Function MOV AL,00H ;AL=00 TO Clear entire screen MOV BH,07 ;BH=07 Is normal attribute (white on black) MOV CH,00 ;CH=00 row value of start point (Upper left corner) MOV CL,00 ;CL=00 column value of start point MOV DH,24 ;DH=24 row value of end point (Lower right corner) MOV DL,79 ;DL=79 column value of end point INT 10H ;CALL BIOS interrupt 2.Setting the Cursor Position to a Specific Location INT 10H Function 02H: Instructions to set the cursor position are MOV AH,02H MOV BH,PAGE NUMBER(0-5) MOV DH,ROW NUMBER(00-24) MOV DL,COL NUMBER(00-79) INT 10H Example: Write a code to set cursor position at ROW=15 and column = 25 MOV AH,02H MOV BH,0 ;PAGE 0 MOV DH,15 MOV DL,25 INT 10H Program: Write a program that 1)clears the screen 2) set cursor at center of the screen ;To Clear the Screen MOV AH,06H MOV AL,00 MOV CH,00 MOV CL,00 MOV DH,24 MOV DL,79 INT 10H ;Setting the cursor at center of the screen MOV AH,02H MOV BH,00 ; page 0 MOV DH,12 ;12 row MOV DL,39 ;39 column INT 10H ;call BIOS interrupt
  • 26. 15CS44 microprocessors & Microcontrollers Kishore kumar R RLJIT page 26 3.Get Cursor Position INT 10H Function 03H: Instructions to get cursor Position MOV AH,03H MOV BH,00 ;Page 0 INT 10H ;call BIOS interrupt After the execution of above instructions, registers DH contain ROW number and DL contain Column number. 4.Changing Video Mode INT 10H Function 00H: There are three video modes 1. Text mode (03H), 80 × 25 characters can be displayed 2. Graphics Mode(04H) (resolution= 320×200 = 64,000 pixels) 3. Graphics Mode(06H) (resolution = 640×200=128,000 pixels) Instructions to change Video mode MOV AH,00H MOV AL, VIDEO MODE (03,04,06) INT 10H Program: write a code to change a video mode to text mode MOV AH,00H MOV AL,03H INT 21H Attribute byte in Monochrome Monitors:  There is an attribute for each character on the screen.  The attribute byte provides information such as color and intensity of the character (foreground) and background.
  • 27. 15CS44 microprocessors & Microcontrollers Kishore kumar R RLJIT page 27 The following are few possible variations of the attributes Attribute Byte in CGA (Color Graphics Adapter) monitors:  In CGA monitor, eight different colors can be used for background and foreground by combining Red, Green, and Blue. D7 D6 D5 D4 D3 D2 D1 D0 Blinking Red Green Blue Intensity Red Green Blue Background Foreground The table below shows few possible variations of attribute byte in CGA Binary Hexadecimal Color Effect 0000 0000 00 Black on Black 0000 0001 01 Blue on Black 0001 0010 12 Green on Blue 0001 0100 14 Red on Blue 0001 1111 1F High-intensity White on Blue 5.Write a character at cursor position INT 10H Function 09H Instructions to write a character at cursor position MOV AH, 09H MOV BH, Page Number MOV AL, Character MOV BL, Attribute MOV CX, Number of characters to write INT 10H E.g. Write a Code to write a character ‘A’ 10 times at cursor position MOV AH,09H MOV AL,’A’ MOV BL,07 ;Black on White Attribute MOV CX,10 INT 10H
  • 28. 15CS44 microprocessors & Microcontrollers Kishore kumar R RLJIT page 28 E.g. Write a program that puts 20H ( ASCII Space Character) on the entire Screen. Use high – intensity White on a Blue Background attribute MOV AH,00 ;Change video mode function MOV AL,03 ; set TEXT Mode INT 10H MOV AH,09H ;Write a character function MOV BH,00 ;PAGE 0 MOV 20H ;20H ASCII code for space MOV CX, 2000 ;Write space 2000 times MOV BL,1FH ;High-Intensity White on Blue INT 10H 6. Writing a Pixel INT 10H Function 0CH Instructions to write a pixel MOV AH,0CH MOV CX, Column Number MOV DX, Row Number MOV BH,PAGE Number MOV AL, PIXEL Value (01 for White 00 for Black) INT 10H Program: i) clear screen ii) set the video mode to CGA of 640×200 resolution and iii) Draw Horizontal Line starting at Column=100, Row=50 and ending at column 200, Row 50 ; To Clear Screen MOV AH,06H MOV AL,00 MOV CH,00 MOV CL,00 MOV DH,24 MOV DL,79 INT 10H ;To Set Video Mode to 640×200 Rsolution MOV AH,00 MOV AL,06 INT 10H ;TO Draw Horizontal Line MOV CX,100 MOV DX,50 BACK:MOV AH,0CH MOV AL,01 INT 10H INC CX CMP CX,200 JNZ BACK
  • 29. 15CS44 microprocessors & Microcontrollers Kishore kumar R RLJIT page 29 2.2.2 DOS Interrupt 21H  DOS provides many functions to Users  INT 21H can be used to call those Functions. 1. Outputting a String of Data to monitor INT 21H Function 09H Instructions to display the string of data on monitor MOV AH,09H MOV DX, OFFSET address of string INT 21H; e.g. Write a code to Display string “welcome to RLJIT” MSG DX MSG DB “ Welcome to RLJIT$” MOV AH,09H MOV DX, OFFSET MSG or LEA DX, MSG INT 21H 2. Outputting a single character on monitor INT 21H Function 02H Instructions to display a character MOV AH,02H MOV AL, Character to be displayed INT 21H E.g. Write a Code to Display a character ‘J’ MOV AH,02H MOV AL,’J’ INT 21H 3. Inputting a Single Character with ECHO Instructions: MOV AH,01H INT 21H After reading a character from keyboard, it will be stored in AL 4. Inputting a single character without Echo Instructions: MOV AH,07H INT 21H; After reading a character from keyboard, it will be stored in AL R L J I T $
  • 30. 15CS44 microprocessors & Microcontrollers Kishore kumar R RLJIT page 30 5. Inputting a String of Data from keyboard INT 21H Function 0AH Steps: 1. Set AH=0AH 2. DX=OFFSET address at which the string of data is stored ( buffer area) 3. First byte in buffer contains size of the buffer 4. Second byte contains the length of the string 5. String will be stored from the third byte Instructions: MOV AH,0AH MOV DX, OFFSET Variable-Name INT 21H E.g. Write a code to READ a string “USA: BEFORE AFTER MSG DB 6,?,6 DUP(FF) MSG DX MOV AH,0AH LEA DX,MSG or MOV DX, OFFSET MSG INT 21H 0DASCII Of ENTER Key Carriage Return & Line Feed:  Carriage Return & Line Feed are two ASCII characters  ASCII of Carriage return = 13 or 0DH  ASCII of Line Feed = 10 or 0AH  Carriage return character returns a cursor to the beginning of current Line  Line feed character moves cursor to next line. LABEL:  It is a assembler directive used to assign multiple names to same data. Syntax: Name LABEL Attribute e.g. P LABEL BYTE MSG P MSG DB 10 In the above example, P and MSG are two different names for same Memory Location 6 FF FF FF FF FF FF 6 3 U S A 0D FF FF 10
  • 31. 15CS44 microprocessors & Microcontrollers Kishore kumar R RLJIT page 31 2.2.3 8086/8088 Interrupts: Interrupt:  It is an external event that informs the CPU that a device needs service.  In 8086 there are 256 different interrupts: INT 00H to INT FFH Interrupt Service Routine (ISR):  ISR is a program that runs when Interrupt occurs.  ISR is also called as Interrupt Handler. Interrupt Vector:  It is 4-byte number (two bytes for IP, two bytes for CS)  Interrupt vector contains the address of ISR,  There are 256 interrupt vectors  Interrupt vectors are stored in first 1Kbytes of memory (00000H – 003FFH) Determining address of Interrupt Vector:  Each interrupt instruction has a numeric value  The address of interrupt vector is determined by multiplying the interrupt numeric value by 4. e.g. INT 10H numeric value = 10H address of interrupt vector = 10H × 4 =40H List of interrupts for 8086/8088
  • 32. 15CS44 microprocessors & Microcontrollers Kishore kumar R RLJIT page 32 Differences between INT and CALL instructions: CALL INT A call instruction can jump to any location within 1-megabyte INT instruction goes to a fixed memory location in the interrupt vector table CALL instruction is used by the programmer in the program Interrupt can occur at any time CALL instruction cannot be masked INT can be masked CALL instruction saves only CS:IP of next instruction INT saves Flag register, and CS:IP of next instruction At the end of the procedure instruction RET is used, RET pops only CS and IP IRET is used at the end of the interrupt service routine (ISR), IRET pops flag register and CS:IP Problem: Find the physical and Logical address in the Interrupt vector table for INT 12H and INT 8 i) INT 12H Address = 12H ×4 =48H Physical address = 00048H – 0004BH Logical address = 0000:0048H – 0000: 004BH ii) INT 8H Address = 8H × 4 = 20H Physical address = 00020H – 00023H Logical address = 0000:0020H – 0000:0023H Categories of Interrupts: There are two types of Interrupts 1. Hardware Interrupts 2. Software Interrupts Hardware Interrupts:  Interrupts caused by Hardware devices are Hardware interrupts.  Three Pins in 8086 are available for Hardware interrupts 1. INTR (interrupt Request) 2. NMI (Non-maskable Interrupt) 3. INTA (Interrupt Acknowledge)
  • 33. 15CS44 microprocessors & Microcontrollers Kishore kumar R RLJIT page 33 INTR:  This is an input signal to CPU  INTR can be masked (ignored) and unmasked using instructions CLI and STI. NMI:  NMI is an input signal to CPU  NMI cannot be masked and unmasked using CLI and STI. Software Interrupts:  Interrupts caused by Instructions are Software Interrupts. Eg INT 21H and INT 10H are examples of Software Interrupts Interrupts and Flag register:  In flag register, bits D9 and D8 are used for interrupts  D9 (IF) interrupt flag can be used to ENABLE or DISABLE the hardware interrupts.  IF=1 interrupts are enabled, IF=0 interrupts are disabled  Instructions CLI and STI can be used to clear and set the IF  TF (Trap Flag) is used to Enable and Disable the Debugging Feature Processing Interrupts: When Interrupts occurs, following steps are executed Steps: 1. Flag register is pushed on to the stack and SP is decremented by 2 2. IF, TF are both cleared 3. CS is pushed onto the stack SP is decremented by 2 4. IP is pushed on to the stack SP is decremented by 2 5. INT number is multiplied by 4 to get the address of vector to fetch ISR 6. From new CS and IP , CPU executes instructions 7. IRET pops IP, CS, and Flag register from stack. Functions Associated with INT 00 to INT 04:  INT 00 to INT 04 have predefined Functions  These interrupts are called as conditional interrupts or exception interrupts.  These interrupts occur when there are conditions that CPU is unable to handle.
  • 34. 15CS44 microprocessors & Microcontrollers Kishore kumar R RLJIT page 34 INT 00 (Divide error):  This interrupt occurs, when there is an attempt to divide number by zero. e.g. MOV AX,92 MOV BL,0 DIV BL ; AX/BL 92/0 = undefined result Interrupt occurs INT 01 (single Step):  Executing Instructions one by one and examining the contents of the registers and memory locations is called Single-Stepping.  Single-stepping can be enabled using TF, after the execution of every instruction INT 01 will occur. INT 02 (Non-maskable Interrupt):  Whenever NMI pin is activated INT 02 will occur and CPU jumps to memory location 00008H to fetch Cs and IP of the ISR of NMI. INT 03 (breakpoint):  Breakpoint is used to examine the content of register or memory location after execution of group of instructions. INT 04 (Signed Number overflow):  INT 04 is associated with instruction INTO (interrupt on overflow)  INTO checks Overflow flag and calls INT04 when OF=1 Important Questions 1. Show how the flag register (ZF, CF, SF, PF, AF) is affected by following instructions MOV AL, 0F5H ADD AL, 0BH 2. Show how CPU would subtract 23H from 3FH 3. Write a program to calculate total sum of 5 bytes of data. Each byte represents daily wages of a worker; the decimal data is as follows 125, 235, 197, 91, and 48. 4. Write a program to add N1= 12345678H and N2 = 12345678H 5. Write a program to subtract 412963BH from 62562FAH 6. Explain the Four cases of the DIVISION. 7. Write a program to multiply 25H and 65H 8. Explain the XOR instruction with example. 9. Write a program to divide 123456H by 1000H 10. Explain SHIFT and ROTATE instructions with Examples
  • 35. 15CS44 microprocessors & Microcontrollers Kishore kumar R RLJIT page 35 11. Write a program to find highest grade in 69, 87, 96, 45 and 75 12. Explain with example, how BCD number 29H is converted to ASCII numbers 32H 39H 13. Write a program to convert 5 ASCII digits to Unpacked BCD 14. Write a program to count number of 1s in byte 97H 15. Write a program that 1)clears the screen 2) set cursor at center of the screen 16. Write a program that puts 20H ( ASCII Space Character) on the entire Screen. Use high – intensity White on a Blue Background attribute 17. write a program to i) clear screen ii) set the video mode to CGA of 640×200 resolution and iii) Draw Horizontal Line starting at Column=100, Row=50 and ending at column 200, Row 50 18. Explain Inputting a string of data Function with an example. 19. Give differences between INT and CALL instructions 20. Find the physical and Logical address in the Interrupt vector table for INT 12H and INT 8 21. What is Interrupt Vector? 22. Write the Steps for Processing Interrupts.