Advanced Microprocessor Lab For V S e m e ste r B .E . (E le ctro n ics & C o m m u n ica tio n E n g in e e rin g )
Name………………………………………… Reg. No……………………………………… Batch…………………………………………
D epartm ent of E lectron ics & Com m un ication En gine
S ri S id d h a rth a In stitu te o f T e ch n o Maralur, Tumkur-5
SSIT
QUESTION BANK 1. (a) Write a program to move an element at Loc1 to Loc2 using base-plus index addressing mode (b) Write a program to move an element at Loc1 to Loc2 using register relative addressing mode 2. Block move a. Without overlap b. With overlap 3. Write a program to interchange blocks of data. 4. Addition. a. Write a program to add two 32-bit numbers b. Write a program to add two 16-bit BCD numbers c. Write a program to show ASCII addition function 5. Subtraction. a. Write a program to subtract two 32-bit numbers b. Write a program to subtract two BCD numbers stored in two memory locations c. Write a program to show ASCII subtraction function 6. Multiplication. a. Write a program to multiply two 16-bit numbers b. Write a program to multiply two 32-bit numbers c. Write a program to illustrate ASCII multiplication function d. Write a program to multiply two signed 8-bit numbers e. Write a program to multiply two signed 16-bit numbers 7. Division. a. Write a program to divide a word by a byte b. Write a program to illustrate the division of a double word by a word c. Write a program to illustrate AAD instruction d. Write a program to illustrate signed division of a word by a byte e. Write a program to illustrate signed division of a double word by a word 8. Write a program to find the square of a number. 9. Write a program to find the cube of a number. 10. Write a program to find the factorial of a number. 11. Write a program find LCM of two numbers. 12. Write a program to find HCF of two numbers. 13. Write a program to check whether the given data is positive or negative. 14. Write a program to check whether the given data is odd or even. 15. Write a program to count number of 1’s and 0’s in a given data byte. 16. Write a program to check whether a given data byte is Palindrome or not. 17. Write a program to check whether a given array is Palindrome or not. 18. Write a program to add series of 8-bit numbers considering possible overflow.
Advanced Microprocessor Lab Manual
-1-
SSIT
19. Write a program to add series of 16-bit numbers considering possible overflow. 20. Write a program to find the smallest of N numbers. 21. Write a program to sort given N numbers in ascending order. 22. Write a program to transfer given source string to destination string using string instructions. 23. Write a program to perform the following operations. a. Reverse a string b. Searching a word from a string 24. Write a program to check if the given data byte is a 2 out of 5 code. 25. WAP to create a file open a file read / write to a file and close a file 26. An ALP to display the string on console using DOS interrupts. 27. An ALP to read the system time. 28. Write a program to convert a given binary number into its BCD equivalent. 29. Write a program to convert a given BCD number into its binary equivalent. 30. Write a program to control the speed of a stepper motor. 31. Develop and execute a program to drive a stepper motor interface to rotate the motor in anti-clock wise direction in N-steps. 32. Write a program for constant display of a string of characters. 33. Write a program to implement a rolling display of characters using display interface. 34. Develop and execute a program to scan for key closer in a key board interface. The row number and the column number of the key pressed are to be stored in memory locations. 35. Program to check for not gate operation using logic controller code segment
Advanced Microprocessor Lab Manual
-2-
SSIT
a ) W r ite a p ro g r a m to m o v e a n e le m e n t a t L o c 1 to L o c 2 u s in g b a s e -p m ode. SOLUTION:
•
MODEL SMALL DATA A r r a yD B
DUP (?) DB 78H DB 20
•
DUP (?)
CODE MOV MOV MOV MOV MOV MOV MOV MOV INT
AX, @Data DS, AX BX, offset array SI, 05H CL, [BX+SI] SI, 11H [BX+SI], CL AH, 4CH 21H
END
RESULT:
b ) W rite a p ro g ra m to m o v e a n e le m e n t a t L o c 1 to L o c 2 u s in g re g . r a d d re s s in g m o d e . SOLUTION:
•
MODEL SMALL DATA A r r a yD B
DUP (?) DB 78H DB 20
•
DUP (?)
CODE
1
Advanced Microprocessor Lab Manual
• 5
1
• 5
-3-
SSIT
MOV MOV MOV MOV MOV MOV INT
AX, @Data DS, AX BX, offset array CL, [BX+05H] [BX+11H], CL AH, 4CH 21H
END
RESULT:
a ) W rite a p ro g ra m to m o v e b lo c k o f d a ta fro m o n e m e m o ry lo c a tio lo c a tio n w ith o u t overlapping. SOLUTION: •
MODEL SMALL DATA A r r a y 1 DW A r r a y 2 DW Count DW
•
1111H, 1222H, 3333H, 4444H, 5555H DUP (?) 0005H
CODE MOV MOV LEA LEA NEXT: MOV MOV MOV INC INC INC INC LOOP MOV INT
AX, @Data DS, AX SI, Array1 DI, Array2 CX, Count AX, [SI] [DI], AX SI SI DI DI NEXT AH, 4CH 21H
END
RESULT:
b ) W rite a p ro g ra m to m o v e b lo ck o f d a ta fro m o n e m e m . L o ca tio n to a n o la p p in g
SOLUTION:
Advanced Microprocessor Lab Manual
2
•
5
2 .
-4-
SSIT
•
MODEL SMALL DATA Data1 DB Count DW
•
10H, 20H, 30H, 40H, 50H 0005H
CODE
REP:
MOV MOV MOV LEA ADD MOV DEC MOV ADD
AX, @Data ES, AX DS, AX SI, Data1 SI, Count CX, Count SI DI, SI DI, 2H
STD MOV MOV INT
SB AH, 4CH 21H
END
RESULT:
Write a program to interchange blocks of data. SOLUTION:
•
•
MODEL SMALL DATA A r r a y 1 DW A r r a y 2 DW
1010H, 2020H, 3030H, 4040H, 5050H 1111H, 2222H, 3333H, 4444H, 5555H
Count CODE
DW
MOV MOV LEA LEA MOV NEXT: MOV MOV XCHG MOV
000SH
MOV
AX, @Data DS, AX SI, Array1 DI, Array2 CX, Count
•
BX, [SI] DX, [DI] BX, DX [SI], BX [DI], DX
Advanced Microprocessor Lab Manual
3
•
-5-
SSIT
INC INC INC INC LOOP MOV INT
SI SI DI DI NEXT AH, 4CH 21H
END
RESULT:
4.(a) Write a program to add two 32-bit numbers. SOLUTION:
•
MODEL SMALL DATA Data1 Data2 Data3 Data4
• •
DW DW DW DW
CODE MOV
A X , @ D a ta
1234H 7678H 8674H 9811H
Advanced Microprocessor Lab Manual
•
-6-
SSIT
MOV MOV ADD MOV ADC MOV INT
DS, AX BX, Data2 BX, Data4 CX, Data1 CX, Data3 AH, 4CH 21H
END
RESULT:
4.(b) Write a program to add two 16-bit BCD numbers. SOLUTION:
•
MODEL TINY CODE MOV MOV MOV ADD DAA MOV MOV ADC DAA MOV MOV INT
BX, 1234H CX, 7698H AL, BL AL, CL DL, AL AL, BH AL, CH DH, AL AH, 4CH 21H
END
RESULT:
Write a program to show ASCII addition function. SOLUTION: •
MODEL TINY CODE MOV
AH, 00H
Advanced Microprocessor Lab Manual
•
4 . •
-7-
SSIT
MOV ADD AAA ADD MOV INT
AL, 39H AL, 31H AX, 3030H AH, 4CH 21H
END
RESULT:
5.(a) Write a program to subtract two 32-bit numbers. SOLUTION: •
MODEL SMALL DATA D T 1 DW D T 2 DW D T 3 DW D T 4 DW D T 5 DW D T 6 DW
•
CODE MOV MOV MOV SUB MOV MOV SBB MOV MOV INT END
RESULT:
1234H 9811H 9900H 0ACDH ? ?
AX, @Data DS, AX AX, DT1 AX, DT3 DT5, AX AX, DT2 AX, DT4 DT6, AX AH, 4CH 21H
Advanced Microprocessor Lab Manual
•
-8-
SSIT
W rite a p ro g ra m to s u b tra c t tw o B C D n u m b e rs s to re d in tw o m e m o ry lo c a tio n s. SOLUTION: •
MODEL SMALL DATA DT1 DB 11H DT2 DB 09H
•
CODE MOV MOV MOV MOV SUB DAS MOV INT
AX, @ Data DS, AX AL, DT1 BL, DT2 AL, BL AH, 4CH 21H
END
RESULT:
Write a program to show ASCII subtraction function. SOLUTION:
•
MODEL TINY CODE MOV MOV SUB AAS ADD MOV INT
AH,00H AL,38H AL,35H AX,3030H AH, 4CH 21H
END
RESULT:
Write a program to multiply two 16-bit numbers. SOLUTION:
MODEL TINY
Advanced Microprocessor Lab Manual
5 .
•
5 .
•
6 .(a )
•
-9-
SSIT
•
CODE AX, 0123H BX, 1155H BX CX, AX AH, 4CH 21H
MOV MOV MUL MOV MOV INT END
RESULT:
Write a program to multiply two 32-bit numbers. SOLUTION:
•
MODEL SMALL DATA Low1 High1 Low2 High2
•
CODE MOV MOV MOV MUL MOV MOV MOV MUL ADD ADC MOV MOV MOV MUL MOV MOV MOV MUL ADD
DW DW DW DW
5678H 1234H 5678H 1234H
RST1 RST2 RST3 RST4
DW DW DW DW
? ? ? ?
AX, @Data DS, AX AX, Low1 Low2 RST1, AX RST2, DX AX, Low1 High2 AX, RST2 DX, 00H
RST2, AX RST3, DX AX, High1 Low2 CX, AX BX, DX AX, High1 High2 BX, AX
Advanced Microprocessor Lab Manual
6 .
•
- 10 -
SSIT
ADC ADD ADC ADC MOV MOV INT
DX, 0H RST2, CX RST3, BX DX, 0H RST4, DX AH, 4CH 21H
END
RESULT:
Write a program to illustrate ASCII multiplication function. SOLUTION:
•
MODEL TINY CODE MOV MOV MUL AAM MOV INT END
AL, 05H BL, 09H BL ADD AX, 3030H AH, 4CH 21H
RESULT:
Ad va nc ed Mi cro pr oc es sor La b Ma nu al
- 11 -
6 .
•
SSIT
6.(d) Write a program to multiply two signed 8-bit numbers. SOLUTION:
•
MODEL TINY CODE MOV MOV IMUL MOV INT
AL, -32H CL, -06H CL AH, 4CH 21H
END
RESULT:
Write a program to multiply two signed 16-bit numbers. SOLUTION:
•
MODEL TINY CODE MOV MOV IMUL MOV INT END
AX, -1234H CX, -0ABCAH CX AH, 4CH 21H
RESULT:
Ad va
nced Microprocessor Lab Manual
- 12 -
•
6 .
•
SSIT
Write a program to divide a word by a byte. SOLUTION:
•
•
MODEL SMALL DATA D a ta 1 D a ta 2 CODE MOV MOV MOV DIV MOV MOV INT
DW DW
0ABCDH 0ABH
A X , @ D a ta DS, AX A X , D a ta 1 Data2 BH, AH AH, 4CH 21H
END
RESULT:
7.(b) Write a program to illustrate the division of a double word by a word. SOLUTION:
•
MODEL TINY CODE MOV
DX, 1111H
Advanced Microprocessor Lab Manual - 13 -
7 .(a )
•
•
SSIT
MOV MOV DIV MOV MOV INT
AX, 1890H BX, 2345H BX BX, AX AH, 4CH 21H
END
RESULT:
Write a program to illustrate AAD instruction. SOLUTION:
•
MODEL TINY CODE MOV MOV AAD DIV MOV MOV INT END
AX, 0607H CH, 09H CH BL, AH AH, 4CH 21H
RESULT:
Ad va nc ed Mi cro pr oc es sor La b Ma nu al
- 14 -
7 .
•
SSIT
Write a program to illustrate signed division of a word by a byte. SOLUTION:
•
MODEL TINY CODE MOV MOV IDIV MOV MOV INT
AX, -1234H BL, 34H BL BL, AH AH, 4CH 21H
END
RESULT:
Write a program to illustrate signed division of a double word by a word. SOLUTION: •
MODEL TINY CODE MOV MOV MOV IDIV MOV MOV INT END
DX, -0ABCH AX, 1112H BX, 2332H BX BX, AX AH, 4CH 21H
RESULT:
Ad
vanced Microprocessor Lab Manual
7 .
- 15 -
•
7 .
•
SSIT
Write a program to find the square of a number. SOLUTION:
•
MODEL SMALL DATA Var DW ____
•
CODE MOV MOV MOV MUL MOV MOV INT
AX, @Data DS, AX AX, Var AX BX, AX AH, 4CH 21H
END
RESULT:
Write a program to find the cube of a number. SOLUTION:
•
MODEL SMALL DATA Va r DW ____
•
CODE MOV
MO
V
MOV MOV
AX, @Data DS, AX CX, 0002H AX, Var
Advanced Microprocessor Lab Manual - 16 -
8
•
9
•
SSIT
Next: MUL LOOP MOV MOV INT
VAR Next BX, AX AH, 4CH 21H
END
RESULT:
Write a program to find the factorial of a number. SOLUTION:
•
MODEL SMALL DATA Data D B
•
____
CODE M OV M OV M OV M OV M OV M OV SUB N e x t:D E C MUL LO O P M OV INT END
AX, @Data DS, AX CH, 0H AL, Data BL, AL CL, AL CL, 02H BL BL Next AH, 4CH 21H
RESULT:
Ad va nc ed Mi cro pr oc es sor La b Ma
nual
- 17 -
1 0
•
SSIT
Write a program find LCM of two numbers. SOLUTION:
•
MODEL SMALL DATA
•
Data1 Data2 LCM CODE
DW DW DW
MOV MOV MOV MOV MOV Next1: P U S H PUSH DIV CMP JZ
0005H 0002H ?
AX, @Data DS, AX AX, Data1 BX, Data2 DX, 0H AX DX BX DX, 0H Next
Ad va
nced Microprocessor Lab Manual
- 18 -
1 1
•
SSIT
POP POP ADD JNC INC JMP Next: POP POP MOV INT
DX AX AX, Data1 Next1 DX Next1 LCM+2 LCM AH, 4CH 21H
END
RESULT:
Write a program find HCF of two numbers. SOLUTION:
•
MODEL SMALL DATA Data1 DW Data2 DW H C F DW ?
•
0005H 0002H
CODE MOV MOV
Advanced Microprocessor Lab Manual
AX, @Data DS, AX
- 19 -
1 2
•
SSIT
MOV MOV Above: CMP Ja XCHG Next2: MOV DIV CMP Je MOV JMP Next: MOV MOV INT
AX, Data1 BX, Data2 AX, BX Next2 AX, BX DX, 0H BX DX, 0H Next AX, DX Above HCF, BX AH, 4CH 21H
END
RESULT:
1 3
Write a program to check whether the given data is positive or negative.
SOLUTION: • MODEL SMALL
Advanced Microprocessor Lab Manual
- 20 -
SSIT
•
DATA MSG 1 MSG 2
• •
DB ‘ENTERED NUMBER IS POSITIVE. $’ DB ‘ENTERED NUMBER IS NEGATIVE . $’ D A T AD B ? MSG 3 DB ‘ENTERED NUMBER IS. $’ STACK CODE MOV MOV MOV
AX, @Data DS, AX AL, DATA
ROL JC LEA
AL, 01 Next DX, MSG1
MOV INT JMP Next: LEA
AH, 09H 21H Last DX, MSG2
MOV INT Last: MOV INT END
AH, 09H 21H AH, 4CH 21H
RESULT:
Ad va nc ed Mi cro pr oc es sor La b Ma nu al
- 21 -
SSIT
Write a program to check whether the given data is odd or even. SOLUTION:
•
•
MODEL SMALL DATA MSG1 MSG2 CODE MOV MOV MOV SAR JC LEA MOV INT JMP Down: L E A MOV INT Last: M O V INT
DB DB
‘GIVEN NUMBER IS ODD. $’ ‘GIVEN NUMBER IS EVEN. $’
A X , @ D a ta DS, AX BL, 24H BL, 01 Down D X, M SG 2 AH, 09H 21H Last D X, M SG 1 AH, 09H 21H AH, 4CH 21H
END
RESULT:
Write a program to count number of 1’s and 0’s in a given data byte. SOLUTION: •
MODEL TINY CODE MOV MOV MOV MOV Next: SAR JC INC LOOP
CX, 0008H AL, 24H BL, 00H DL, BL AL, 01H Down BL Next
Advanced Microprocessor Lab Manual - 22 -
1 4
•
1 5
•
SSIT
JMP Down: INC LOOP Last: MOV INT
Last DL Next AH, 4CH 21H
END
RESULT:
Write a program to check whether a given data byte is Palindrome or not. SOLUTION:
•
MODEL SMALL DATA MSG1 DB MSG2 DB DATA DB
•
‘GIVEN DATA IS PALINDROME. $’ ‘GIVEN DATA IS NOT PALINDROME. $’
CODE MOV MOV MOV MOV MOV Up: ROL RCL LOOP CMP JZ LEA MOV INT JMP Next LEA MOV INT Last: MOV INT END
RESULT:
AX, @ Data DS, AX BL, data CX, 0008H DL, BL BL, 01H DL, 01H Up BL, DL Next DX, MSG2 AH, 09H 21H Last DX, MSG1 AH, 09H 21H AH, 4CH 21H
Advanced Microprocessor Lab Manual
1 6
•
?
- 23 -
SSIT
Write a program to check whether a given array is Palindrome or not. SOLUTION:
•
•
MODEL SMALL DATA MSG1 MSG2
DB DB
Array1 DB Array2 DB
10H, 20H, 20H, 10H 4 DUP (?)
Count CODE
DW
MOV MOV MOV LEA LEA ADD Next: DEC MOV MOV INC LOOP LEA LEA MOV
‘GIVEN ARRAY IS PALINDROME. $’ ‘GIVEN ARRAY IS NOT PALINDROME. $’
0004H
AX, @ Data DS, AX CX, Count SI, Array1 DI, Array2 DI, Count DI AL, [SI] [DI], AL SI Next SI, Array1 DI, Array2 CX, Count
Advanced Microprocessor Lab Manual
1 7
•
- 24 -
SSIT
Up: MOV CMP JNZ INC INC LOOP LEA MOV INT JMP Down: LEA MOV INT Last: MOV INT
AL, [SI] [DI], AL Down SI DI Up DX, MSG1 AH, 09H 21H Last DX, MSG2 AH, 09H 21H AH, 4CH 21H
END
RESULT:
W r i t e a p r o g r a m t o a d d s e r i e s o f 8 - b i t n u m b e r s c o n s i d e r in g p o s s i b l e o v SOLUTION: •
•
MODEL SMALL DATA Array Count CODE MOV MOV MOV LEA XOR Start: A D D JNC INC Next: INC LOOP MOV INT
DB DW
99H, 0ABH, 33H, 84H, 65H 0005H
A X , @ D a ta DS, AX CX, Count S I , A rr a y AX, AX AL, [SI] Next AH SI Start AH , 4CH 21H Ad va nc ed
Microprocessor Lab Manual - 25 -
1 8 •
SSIT
END
RESULT:
W rite a p ro g ra m to a d d s e rie s o f 1 6 -b it n u m b ers c o n s id e rin g p o s s ib le o v erflo w . SOLUTION: •
MODEL SMALL DATA
•
Array Count CODE
DW DW
MOV MOV MOV MOV DEC LEA MOV Next: INC INC ADD JC LOOP Last INC LOOP MOV INT
1234H, 5678H, 89ABH, 0FFEAH, 1189H 0005H
AX, @ Data DS, AX DX, 0H CX, Count CX SI, Array BX, [SI] SI SI BX, [SI] Last Next DX Next AH, 4CH 21H
END
RESULT:
Write a program to find the largest of N numbers. SOLUTION:
•
•
MODEL SMALL DATA Array C o u n t CODE MOV
DB DW A X , @ D a ta
20H, 10H,
30H, 50H,
Advanced Microprocessor Lab Manual
1 9 •
2 0
•
40H 0005H
- 26 -
SSIT
MOV LEA DEC MOV MOV Next: INC CMP JC LOOP JMP Down X C H G LOOP Last: MOV INT END
Note:-
DS, AX SI, Array Count CX, Count AL, [SI] SI AL, [SI] Down Next Last AL, [SI] Next AH, 4CH 21H
For smallest change JC to JNC
RESULT:
2 1
Write a program to sort given N numbers in ascending order. SOLUTION:
Advanced Microprocessor Lab Manual
- 27 -
SSIT
•
MODEL SMALL DATA Array Count
•
CODE
MOV MOV MOV LEA Next: MOV INC INC CMP JNC LOOP Down: X C H G DEC DEC MOV LOOP MOV INT END
DW DW
2020H, 1010H, 3030H, 5500H, 4040H 0005H
A X , @ D a ta DS, AX CX, Count S I , A r ra y B X , [SI] SI SI B X , [SI] Down Next B X , [SI] SI SI [SI], B X Next AH, 4CH 21 H
N o t e :F o -r d e s c e n d in g c h a n g e J N C t o J C
RESULT:
Ad va nc ed Mi cro pr oc es sor La b Ma nu al
•
- 28 -
SSIT
W r ite a p ro g r a m to t r a n s fe r g iv e n s o u r c e s tr in g to d e s tin a tio n s tr in g in s tr u c tio n s . SOLUTION:
•
•
MODEL SMALL DATA D a ta 1 DB ‘WELCOME. $’ D a ta 2 DB 10 DUP(0) CODE AX, @ Data MOV DS, AX MOV ES, AX MOV CX, 07H MOV CLD SI, Offset Data1 MOV DI, Offset Data2 MOV REP MOVSB CX, 07H MOV STD SI, Offset Data1 + 6 MOV DI, Offset Data2 + 14 MOV REP MOVSB AH, 4CH MOV 21H INT END
RESULT:
Ad va nc ed Mi cro pr oc es sor La b Ma nu al
2 2 - 29 -
•
SSIT
2 3 . ( a Write ) a program to reverse a string. SOLUTION:
•
MODEL SMALL DATA M1 M2 B u ff
•
D D D D D C o u n t 1 D C o u n t2 D CODE M O V M O V M O V M O V INT M O V LEA INT M O V M O V INT LEA INC M O V M O V
B B B B B W W
10, 13, ‘ENTER THE STRING: $’ 10, 13, ‘REVERSE OF A STRING: $’ 80 0 80 DUP (0) 0 0 AX, @ Data DS, AX AH, 09H DX, Offset M1 21H AH, 0AH DX, Buff 21H AH, 09H DX, Offset M2 21H BX, Buff BX CH, 00 CL, Buff+1 Ad va nc ed
Microprocessor Lab Manual
- 30 -
•
SSIT
MOV Back: M O V MOV INT DEC JNZ MOV INT END
DI, CX DL, [BX+DI] AH, 02H 21H DI Back AH, 4CH 21H
RESULT:
2 3 . ( b Write ) a program to search a word from a string. SOLUTION:
•
MODEL SMALL DATA N1 Key
DB DW
Count
•
M1 Res M2 CODE
12H, 1414H, 7878H, 6767H, 3434H 3132H DB
DB DB DB
M O V M O V M O V M O V N e x t M: O V C M P JZ IN C
0005H
‘ THE KEY FOUND IN ‘ ‘THE POSITION’, 13, 10, ‘$’ ‘NOT FOUND’, 13, 10, ‘$’ AX, @ Data DS, AX SI, 00H CX, Count AX, NI[SI] AX, Key Suc SI
Advanced Microprocessor Lab Manual
•
- 31 -
SSIT
LOOP JMP Suc: MOV ADD ADD MOV LEA JMP Fall: LEA JMP Last: MOV INT MOV INT
Next Fall AX, SI AL, 01H AL, ‘0’ Res, AL DX, M1 Last DX, M2 Last AH, 09H 21H AH, 4CH 21H
END
RESULT:
Write a program to check if the given data byte is a 2 out of 5 code. SOLUTION:
•
•
MODEL SMALL DATA M1 DB M2 DB N u m DB 3H CODE S t a r tM: O V M O V M O V M O V M O V R e p e aSt :H L
‘NOT 2 OUT OF 5 CODE’, ‘$’ ‘VALID 2 OUT OF 5 CODE’, ‘$’
AX, @Data DS, AX AL, Num BL, 00H CX, 03H AL, 01H Ad va nc
ed Microprocessor Lab Manual - 32 -
2 4
•
SSIT
JC LOOP MOV MOV
Exit Repeat CX, 05H AL, Num
B a c k : SHR JNC INC N e x t : LOOP CMP JNE LEA MOV INT JMP E x it : LEA MOV INT JMP L a s t : MOV INT CODE END
AL, 01H Next BL Back BL, 02H Exit DX, M2 AH, 09H 21H Last DX, M1 AH, 09H 21H Last AH, 4CH 21H Ends Start
RESULT:
WAP to create a file, open a file read/write to a file and close a file. SOLUTION: DATE SEGMENT Filename db “Create. Asm $” Filecontent db “Electronics $”
Advanced Microprocessor Lab Manual
- 33 -
2 5
• • •
SSIT
• •
FDL DW ? DATA ENDS CODE SEGMENT ASSUME CS: CODE DS, ; DATA Start: M O V MOV MOV MOV LEA INT MOV MOV LEA MOV INT MOV MOV MOV LEA INT MOV MOV INT MOV INT CODE END
RESULT:
Advanced Microprocessor Lab Manual
AX, DATA DS, AX AH,3CH CX, 0000H DX, FILE NAME 21H FDL, AX AH,3DH DX, FILENAME AL, 82h 21H AH,40H BX, FDL CX, OBH DX, FILECONTENT 21H AH,3EH BX, FDL 21H AH, 4CH 21H ENDS START
- 34 -
SSIT
An ALP to display the string on console using DOS interrupts. SOLUTION:
• •
DATA SEGMENT MSG DB DATA ENDS
“ Welcome to TCE Dept.”, ‘$’
CODE SEGMENT MAIN ROC ASSUME Start: P U S H XOR PUSH MOV MOV MOV MOV INT MAIN CODE END
FAR
CS: CODE,DS : DATA DS AX, AX AX AX, DATA DS, AX AH, 09H DX, Offset MSG 21H END P ENDS START
RESULT:
Ad va nc ed Mi cro pr oc es sor La b Ma nu al
2 6
•
•
- 35 -
SSIT
An ALP to read the system time. SOLUTION: • •
MODEL Tiny CODE Start: M O V INT MOV AAM MOV CALL MOV INT MOV AAM MOV CALL MOV INT D ISP PRO C MOV ADD MOV INT ADD INT RET DISP END
Advanced Microprocessor Lab Manual
AH, 2CH 21H AL, CH BX, AX DISP AH, 02H 21H AL, CL BX,AX DISP AH, 4CH 21H DL, BL DL, 30H AH, 02H 21 H DL, BL 21H END P START
- 36 -
2 7
SSIT
RESULT:
Write a program to convert a given binary number into its BCD equivalent. SOLUTION:
•
MODEL SMALL DATA N1 RES
•
DB DW
? ?
CODE S t a r tM: O V M O V M O V M O V M O V C A L L M O V M O V C A L L M O V R O L M O V OR M O V M O V IN T
AX, @ DATA DS, AX CX, OOH AL, 64H BL, NI BCD DH, DL AL, OAH BCD CL, OAH DL, CL CL, BL DL, CL RES, DX AH, 4CH 21H Ad va
nced Microprocessor Lab Manual
- 37 -
2 8
•
SSIT
BCD MOV REPEAT: SUB JC INC JMP NEXT: ADD
PROC DL, OOH BL, AL NEXT DL DL BL, AL
RET ENDP END
RESULT:
Write a program to convert a given BCD number into its binary equivalent SOLUTION:
•
MODEL SMALL DATA N1 DB RES DW ?
•
CODE S t a r tM: O V M O V M O V A M M P U S H M O V M U V
72D
AD, @Data DS, AX AL, NI
AX BL, OAH AL, AH
Advanced Microprocessor Lab Manual
- 38 -
2 9
•
SSIT
MUL MOV POP MOV ADD MOV MOV INT
BL BX, AX AX AH, OOH AX, BX RES, AX AH, 4CH 21H
END
RESULT:
Write a program to control the speed of a stepper motor. SOLUTION:
•
MODEL SMALL DATA Seq
DB
3H, 1H, 9H, 8H, 0CH, 4H, 6H, 2H
Delay
DB
(0)
C o n t r o l DW Pc DW
0D803H 0D802H
Advanced Microprocessor Lab Manual - 39 -
3 0
•
SSIT
•
CODE Start: M O V MOV MOV MOV MOV MOV OUT MOV Repeat1:M O V Next: MOV OUT MOV Repeat: M O V Back: L O O P DEC JNZ INC CMP JNZ DEC JNZ INT MOV INT END
AX, @Data DS, AX BX, Offset Seq DX, Control AL, 80H DI, 020H DX, AL DX, Pc SI, 00H AL, BX[SI] DX, AL Delay, 30H CX, 0FFFFH Back Delay Repeat SI SI, 08H Next DI Repeat1 3 AH, 4CH 21H Start
RESULT:
D e v e lo p a n d e x e c u te a p r o g r a m to d r iv e a s te p p e r m o to r in te r fa c e to r in N - s te p s .
Ad va nc ed Mi cro pr
ocessor Lab Manual
- 40 -
3 1
SSIT
SOLUTION:
•
MODEL SMALL DATA Seq DB
•
3H, 1H, 9H, 8H, 0CH, 4H, 6H, 2H
Delay DB C on tro l D W Pc DW CODE S t a r tM: O V M O V M O V M O V M O V M O V O U T M O V R e p e a tM1 :O V N e x t M: O V O U T M O V R e p e aMt : O V B a c k L: O O P D EC JNZ IN C C M P JNZ D EC JN 2 M O V IN T E N D
(0) 0D803H 0D802H AX, @Data DS, AX BX, Offset Seq DX, Control AL, 80H DI, 020H DX, AL DX, Pc SI, 00H AL, BX[SI] DX, AL Delay, 04FFH CX, 0FFFFH Back Delay Repeat SI SI, 08H Next DI Repeat I AH, 4CH 21H Start
RESULT:
Ad va nc ed Mi cro pr oc es sor La b Ma nu
al
• - 41 -
SSIT
Write a program for constant display of a string of characters. SOLUTION:
• •
•
MODEL SMALL STACK 20 DATA
Num
DB
Disp tbl DB
3, 9FH, 25H, 0DH, 99H, 49H, 41H, 1FH, 1, 9
Pa Pb Pc C o n t r o EQ l U CODE
1, 1, 1, 1
EQU 0C800H EQU 0C801H EQU 0C802H 0C803H
Start: M O V MOV MOV MOV OUT CALL MOV INT B c d 4 d is p p r o c MOV Nxtchar:M O V MOV LEA XLAT Nxtseg: M O V OUT MOV MOV MOV OUT MOV
AX, @Data DS, AX AL, 90H DX, Control DX, AL Bcd4disp AH, 4CH 21H SI, 3H AH, 8
AL, Num[SI] BX, Disptbl DX, Pb DX, AL CH, AL AL, 0 DX, Pc DX, AL AL, 0F0H
3 2 Advanced Microprocessor Lab Manual
•
- 42 -
SSIT
OUT DEC
DX, AX AH
JZ MOV
Overchk AL, CH
ROR JMP Overchk:D E C CMP JNE
AL, 1 Nxtseg SI SI, -1 Nxtchar
a
f
g e
RET Bcd4disp ENDP END
b
c d
Start
For example: for1
abcdefg 1 0 0 1 1 1 1 = 9FH
W rite a p rog ram to im ple m e n t a ro llin g d isp la y o f ch arac te rs u sin g d is in te rfa ce . SOLUTION: • •
MODEL SMALL STACK 20 DATA Num1 Num2 Msg
DB DB DB
D isptbl DB
1, 1, 0AH, 0BH, 0CH, 0DH 1, 1 ‘Press any key to return to DOS’, 13H, 10H, ‘$’ 3, 9FH, 25H, 0DH, 99H, 49H, 41H, 1FH, 1H, 9H,
Advanced Microprocessor Lab Manual
3 3
•
- 43 -
SSIT
•
11H, 1H, 63H, 3H Pa EQU 0C800H Pb EQU 0C801H Pc EQU 0C802H C o n t r o EQ l U 0C803H CODE Start: MOV MOV MOV MOV OUT MOV LEA INT Again: MOV MOV INT JNZ LEA CALL CALL LEA CALL CALL JMP Last: MOV INT DELAY MOV Again MOV Again 2 :L O O P POPC DEC JN2 RET DELAY B c d 4 d is MOV Nxtchar: MOV MOV
Advanced Microprocessor Lab Manual
AX, @Data DS, AX AL, 90H DX, Control DX, AL AH, 9 DX, Msg 21H AH, 6 DL, 0FFH 21H Last BP, Num1 Bcd4disp Delay BP Num 2 BCD 4 disp Delag Again AH, 4CH 21H Proc CX, 0FFFFH 1 PUSH CX CX, OFFFH Again 2 X CX Again1 Endp p P ro c SI, 03H AH, 8 AL, DS:[BP+SI]
- 44 -
SSIT
LEA XLAT Nxtseg: MOV OUT MOV MOV MOV OUT MOV OUT DEC JZ MOV ROR JMP Overchk: DEC CMP JNE
BX, Disptbl DX, Pb DX, AL CH, AL AL, 0 DX, Pc DX, AL AL, 0F0H DX, AL AH Overchk AL, CH AL, 1 Nxtseg SI SI, -1 Nxtchar
RET Bcd4disp ENDP Start END
a b
f g
c
e d
For example: for1 abcdefg 1 0 0 1 1 1 1 = 9FH
Advanced Microprocessor Lab Manual
- 45 -
SSIT
D e v e lo p a n d e x e c u te a p r o g ra m to s c a n fo r k e y c lo s e r in a k e y b o a th e c o lu m n number of the key pressed are to be stored in memory locations. SOLUTION: • MODEL SMALL • STACK • DATA P r o m p t DB ‘Press any key to return to DOS’, 13H, 10H, ‘$’ M s g DB Askires Pa Pb Pc Control • CODE
‘The row & column info of the key pressed are as follows’ DB EQU EQU EQU EQU
?, ‘’, ?, 13, 10, ‘$’ 0D800H 0D801H 0D802H 0D803H Start: M O V MOV MOV MOV OUT MOV LEA INT Again: MOV MOV INT JNZ CALL CMP JE ADD MOV ADD MOV MOV
AX, @Data DS, AX AL, 90H DX, Control DX, AL AH, 09H DX, Prompt 21H AH, 6 DL, 0FFH 21H Quit Scan SI, 0 Again BH, 30H
Advanced Microprocessor Lab Manual
AH, 30H Askires+2, AH AH, 9
- 46 -
3 4
SSIT
LEA INT MOV H e r e 1 :MOV H e r e : LOOP DEC JNZ JMP Q u it : MOV INT SCAN MOV MOV MOV MOV N x t r o w ROL :
DX, Msg 21H AH, 0FFH CX, 0FFFFH Here AH Here1 Again AH, 4CH 21H Proc SI, 0 CX, 3 BH, 0 AL, 80H AL, 1
MOV MOV OUT SUB IN CMP JNZ MOV INC LOOP
BL, AL DX, Pc DX, AL DX, 2 AL, DX AL, 0 Keyid AL, BL BH Nxtrow
Keyid: MOV MOV MOV Again2: R O R JC INC LOOP Skip RET SCAN END
SI, 1 CX, 8 AH, 0 AL, 1 Skip AH Again2
RESULT:
Advanced Microprocessor Lab Manual
ENDP Start
- 47 -
SSIT
3 5 Program to cheek for not gate operation using logic controller. SOLUTION: • •
Code Segment Assume CD: CODE
Start: M O V MOV OUT MOV IN NOT DEC OUT MOV INT END
Advanced Microprocessor Lab Manual
DX, 0D803H AL, 8AH DX, AL DX, 0D801H AL, DX AL DX DX, AL AH, 4CH 21H START
- 48 -
SSIT
END
RESULT:
Advanced Microprocessor Lab Manual
- 49 -