Microprocessor Lab Manual Digital Edition
Microprocessor Lab Manual Digital Edition
Laboratory Manual
Contents
1.a 1.b 1.c 1.d 2.a.i 2.a.ii 2.b 2.c.i 2.c.ii 2.c.iii 2.c.iv 2.d 2.e.i 2.e.ii 2.e.iii 2.e.iv 2.e.v 2.e.vi 2.f.i 2.f.ii 3.a 3.b 3.c 3.d 3.e 4.i 4.ii 4.iii 5.i 5.ii 5.iii 5.iv 6 Byte and word transfer in different addressing modes. Block transfer without overlap Block transfer with overlap Block exchange 16 bit Addition/Subtraction 32 bit Addition/Subtraction ASCII adjust after Addition/Subtraction 16 bit Multiplication/Division 32 bit Multiplication 16-bit signed Multiplication Signed Division of word by a byte ASCIl adjust after Multiplication Square of a word Cube of a byte Cube of a word LCM of two numbers HCF of two numbers Factorial of a number Binary to BCD conversion BCD to Binary conversion Bit manupilation to check if the data ispositive or negative Bit manupilation to check if the data isodd or even Bit manupilation to count the number of 1's and 0's in given data Bit wise Palindrome Bit manupilation to check 2 out of 5 code Addition/Subtraction of array of words Largest/Smaliest element in an array Sorting array in Ascending/Descending order String transfer String reverse Character search in a string Palindrome in a String Display string on console using DOS interrupts
Interfacing Programs
1 2 3 4 Matrix Keyboard Interfacing LCD Interface Logical Controller Stepper Motor Interface
Run command prompt and go to Masm directory i.e. C:\masm\ Type the program by opening an editor using Edit command i.e. C:\masm\edit filename.asm After typing the program assemble the program using masm command. i.e. C:\masm\masm filename.asm; After assembling, link the file using link command i.e. C:\masm\link filename.obj; Finally use debug or afdebug command to execute the program. C:\masm\debug filename.exe -t ; for single step execution -g ; for at a time execution -I ; for restarting the program execution -d ; to see the data segment -q ; to quit the execution C:\masm\afdebug filename.exe F1 ; for single step execution g ; for at a time execution L filename.exe ; to reload the program Quit ; to come out of the execute screen
MOV BX, offset Array MOV SI,05h MOV CL,[BX+SI] MOV SI,11H MOV [BX+SI],CL MOV AH,4Ch INT 21h END
1.b.i
.MODEL SMALL .DATA Array1 DW 1111h,2222h,3333h,4444h,5555h Array2 DW 5 DUP (0) Count DW 0005H .CODE MOV AX,@DATA MOV DS,AX LEA SI,Array1 LEA DI,Array2 MOV CX,Count NEXT: MOV AX,[SI] MOV [DI],AX INC SI INC SI INC DI INC DI LOOP NEXT MOV AH,4Ch INT 21h END
1.b.ii
.MODEL SMALL .DATA Array DB 11h,22h,33h,44h,55h Count DW 0005h .CODE MOV AX,@DATA MOV ES,AX MOV DS,AX LEA SI,Array ADD SI,Count MOV CX,Count DEC SI MOV DI,SI ADD DI,2h STD REP MOVSB MOV AH,4Ch INT 21h
END
.MODEL SMALL .DATA Array1 DW 1111h,2222h,3333h,4444h,5555h Array2 DW 1010h,2020h,3030h,4040h,5050h Count DW 0005h .CODE MOV AX,@DATA MOV DS,AX LEA SI,Array1 LEA DI,Array2 MOV CX,Count
NEXT: MOV BX,[SI] MOV DX,[DI] XCHG BX,DX MOV [SI],BX MOV [DI],DX INC SI INC SI INC DI INC DI LOOP NEXT MOV AH,4Ch INT 21h END
; SBB CX,Data3
2.b.
.MODEL TINY .CODE MOV AH,00h MOV AL,39h ADD AL,31h AAA ADD AX,3030h MOV AH,4Ch INT 21h END
2.c.i
.MODEL TINY .CODE MOV AX,1234h MOV BX,7698h ADD AL,31h MUL BX MOV AH,4Ch INT 21h END
16 bit Multiplication/Division
; for Division replace with ; DIV BX
2.c.ii
.MODEL SMALL .DATA Low1 DW 5678h High1 DW 1234h Low2 DW 5678h High2 DW 1234h Ans1 DW ? Ans2 DW ? Ans3 DW ? Ans4 DW ? .CODE MOV AX,@Data MOV DS,AX MOV AX,Low1 MUL Low2 MOV Ans1,AX MOV Ans2,DX MOV AX,Low1 MUL High2 ADD AX,Ans2 ADC DX,00h MOV Ans2,AX MOV Ans3,DX MOV AX,High1 MUL Low2 MOV CX,AX MOV BX,DX MOV AX,High1 MUL High2 ADD BX, AX ADC DX,00H ADD Ans2,CX ADC Ans3,BX ADC DX,00H MOV Ans4,DX MOV AH,4Ch INT 21h END
32 bit Multiplication
2.c.iv
.MODEL TINY .CODE MOV DX,-0ABCh MOV AX, 1234h MOV BX, 2334h IDIV BX MOV CX,AX MOV AH, 4Ch INT 21h END
2.d.
.MODEL TINY .CODE MOV AL,OFh MOV BL,04h MUL BL AAM ADD AX,3030h MOV AH,4Ch INT 21h END
2.e.i
.MODEL SMALL . DATA Number DW OFFFFh Ans DW 2 DUP (?) .CODE MOV AX,@DATA MOV DS, AX MOV DX, OOh MOV AX, Number MUL Number MOV Ans, AX MOV Ans+2, DX MOV AH, 4Ch INT 21h END
Square of a word
2.e.ii
.MODEL SMALL . DATA Number DB OFFh Ans DW 2 DUP (0) .CODE MOV AX,@DATA MOV DS, AX MOV AX, 0000h MOV DX, 0000h MOV CX, 0000h MOV CL, Number MOV AL, CL MUL CL MUL CX MOV Ans, AX MOV Ans+2, DX MOV AH, 4Ch INT 21h END
Cube of a byte
2.e.iii
.MODEL SMALL . DATA NUMBER DW 05566h CUBE DW 3 DUP (0) .CODE MOV AX,@DATA MOV DS, AX MOV DX, 00h MOV AX, NUMBER MUL NUMBER MOV BX, DX MOV DX, 00h MUL NUMBER MOV CUBE, AX MOV CUBE+2, DX MOV AX, BX MUL NUMBER ADD AX, CUBE+2 ADC DX, 00h MOV CUBE+2, AX MOV CUBE+4, DX MOV AH, 4Ch INT 21h END
Cube of a word
2.e.v
.MODEL SMALL .DATA Num1 DW 0005h Num2 DW 0002h Ans DW ? .CODE MOV AX,@DATA MOV DS, AX MOV AX, Num1 MOV BX, Num2 FIRST: CMP AX, BX JA NEXT XCHG AX, BX NEXT: MOV DX, 0000h DIV BX CMP DX, 0000h JE LAST MOV AX, DX JMP FIRST LAST: MOV Ans, BX MOV AH, 4Ch INT 21h END
MOV CH, 00h MOV AL, Number MOV BL, AL MOV CL, AL SUB CL, 02h NEXT: DEC BL MUL BL LOOP NEXT MOV Ans, AX MOV AH, 4Ch INT 21h END
2.f.i
.MODEL SMALL .DATA Binary DB 63h Ans DB 00h, 00h, 00h .CODE MOV AX,@DATA MOV DS, AX MOV AX, 00h MOV AL, Binary MOV CL, 64h DIV CL MOV BCD, AL MOV AL, AH MOV AH, 00h MOV CL, 0Ah DIV CL MOV Ans+ 1, AL MOV Ans+2, AH OR Ans, 30h OR Ans+ l,30h OR Ans+2,30h MOV AH, 4Ch INT 21h END
2.f.ii
.MODEL SMALL .DATA BCD DB 15h Ans DB 00h .CODE MOV AX,@DATA MOV DS, AX MOV AL, BCD AND AL, 0Fh MOV BL, AL MOV AL, BCD AND AL, 0F0h MOV CL, 04h ROR AL, CL MOV CL, 0Ah MUL CL ADD AL, BL MOV Ans, AL MOV AH, 4Ch INT 21h END
3.a.
.MODEL SMALL .DATA Msg1 DB ENTERED NUMBER IS POSITIVE. $ Msg2 DB ENTERED NUMBER IS NEGATIVE. $ Input DB ? .STACK .CODE MOV AX, @Data MOV DS, AX MOV AL, Input ROL AL, 01h JC NEXT LEA DX, Msg1 MOV AH, 09h INT 21h JMP LAST NEXT: LEA DX, Msg2 MOV AH, 09h INT 21h LAST: END MOV AH, 4Ch INT 21h
3.c.
.MODEL SMALL .CODE MOV CX, 0008h MOV AL, 24h MOV BL, 00h MOV DL, BL NEXT: SAR AL, 01h JC DOWN INC BL LOOP NEXT JMP LAST DOWN: INC DL LOOP NEXT LAST: END MOV AH, 4Ch INT 21h
3.d.
.MODEL SMALL .DATA Msg1 DB GIVEN BYTE IS PALINDROME $' Msg2 DB GIVEN BYTE IS NOT PALINDROME $' Input DB ? .CODE MOV AX,@DATA MOV DS, AX MOV BL, Input MOV CX, 0008h MOV DL, BL UP: ROL BL, 01h RCL DL, 01h LOOP UP CMP BL, DL JZ NEXT LEA DX, Msg2 MOV AH, 09h INT 21h JMP LAST NEXT: LEA DX, Msg1 MOV AH, 09h INT 21h LAST: END MOV AH, 4Ch INT 21h
LAST: DISP:
4.i
.MODEL SMALL .DATA Array DW 1234h, 5678h, 9ABCh, 0DEF0h, 0AA11h Count DW 0005h Result DW 0000h, 0000h .CODE MOV AX,@DATA MOV DS, AX MOV DX, 00h MOV CX, Count DEC CX LEA SI, Array MOV BX, [SI] NEXT: INC SI INC SI ADD BX, [SI] JC LAST LOOP NEXT LAST: INC DX LOOP NEXT MOV Result, BX MOV Result+2, DX MOV AH, 4Ch INT 21h END
DOWN:
LAST: END
.MODEL SMALL .DATA String1 DB 'BMSCE DEPT OF ECE$' Length EQU ($-String1) String2 DB LEN DUP (0) .CODE MOV AX, @DATA MOV DS, AX MOV ES, AX MOV CX, Length CLD LEA SI, String1 LEA DI, String2 REP MOVSB MOV AH, 4Ch INT 21h END
5.ii
.MODEL SMALL .DATA String DB 'BMSCE$' Length EQU ($-String) Rvrs DB Length DUP (0) .CODE MOV AX,@DATA MOV DS, AX MOV ES, AX MOV CX, Length LEA SI, String+Length-1 LEA DI, Rvrs REPEAT: MOV AL, [SI] MOV [DI], AL DEC SI INC DI LOOP REPEAT MOV AH, 4Ch INT 21h END
String reverse
5.iii
.MODEL SMALL .DATA String DB 'BMS COLLEGE' Length EQU ($-String) Key DB 'X' Dis1 DB '-IS PRESENT IN GIVEN STRING$' Dis2 DB '-IS NOT PRESENT IN GIVEN STRING$' .CODE MOV AX,@DATA MOV DS, AX MOV ES, AX MOV DL, Key MOV AH, 02h INT 21h LEA DI, String MOV AL, Key MOV CX, Length REPNE SCASB JE PRESENT LEA DX, Dis2 CALL Display JMP OVER PRESENT: LEA DX, Dis1 CALL Display OVER: MOV AH, 4Ch INT 21h Display PROC NEAR MOV AH, 09h INT 21h RET Display ENDP END
String DB 'BMSCE$' Length EQU ($-String) Rvrs DB 30 DUP(0) Dis1 DB '-IS NOT A PALINDROME$' Dis2 DB '-IS A PALINDROME$'
.CODE MOV AX,@DATA MOV DS, AX MOV ES, AX MOV CX, Length LEA SI, String+Length-1 LEA DI, Rvrs MOV AL, [SI] MOV [DI], AL DEC SI INC DI LOOP REPEAT LEA DX, String CALL Display LEA SI, String LEA DI, Rvrs MOV CX, Length REPE CMPSB JNZ NO LEA DX, Dis2 CALL Display JMP OVER NO: LEA DX, Dis1 CALL Display MOV AH, 4Ch INT 21h
REPEAT:
OVER:
Display PROC NEAR MOV AH, 09h INT 21h RET Display ENDP END
6.
.MODEL SMALL
DATA SEGMENT MSG DB BMSCE ECE DEPT$ DATA ENDS CODE SEGMENT
MAIN PROC FAR ASSUME CS: CODE, DS: DATA START: PUSH DS XOR AX, AX PUSH AX MOV AX, DATA MOV DS, AX MOV AH, 09h MOV DX, OFFSET MSG INT 21h RET END START MAIN ENDP CODE ENDS
Type the program by opening an editor using Edit command i.e. C:\masm\edit filename.asm After assembling, link the file using link command i.e. C:\masm\ link filename.obj; Convert the executable file to binary program. i.e. C:\masm\ exe2bin filename.exe Convert the binary file to hex program. i.e. C:\masm\bin2hex filename.exe Open the hex uploader program. i.e. C:\masm\mmeterm
After typing the program assemble the program using masm command. i.e. C:\masm\masm filename.asm;
Set the Baud rate to 9600bits/second. i.e. 5. Configuration> 1. Baud Rate>5. 9600
Press reset on the interface kit. Message will appear on the LCD as uP 8086.
Send file to the processor via serial port [COM1]. i.e. 3. Sendfile>Which File? filename.hex Press Enter Message will appear on the LCD as Data received.
Press Download on the interface kit to prepare the processor to receive file. Message will appear on the LCD as Reading RS 232.
; port a and port c high as output ; port b and port c low as output
CODEN: MOV AL,DL MOV DH,0h MOV BX,OFFSET LOOKUP+8000h ADD BX,DX MOV AL,BYTE PTR[BX] OUT PORTB,AL JMP READKEY ONEMS: PUSH AX MOV AL,0FFh LOP: DEC AL JNZ LOP POP AX RETF LOOKUP: DB DB CODE ENDS END ; delay routine
00h,04h,08h,0Ch,01h,05h,09h,0Dh 02h,06h,0Ah,0Eh,03h,07h,0Bh,0Fh
2. LCD Interface
ORG 400h MES1 DB 'BMSCE' MES2 DB 'OF E AND C' MES3 DB ' ' L1:
CODE SEGMENT ASSUME CS:CODE,DS:CODE,ES:CODE DISINT EQU 21h DSPBUF EQU 9E00h
MOV SI,OFFSET MES3+8000h MOV DI,DSPBUF MOV CX,08h REP MOVSW INT DISINT CALL DELAY MOV SI,OFFSET MES1+8000h MOV DI,DSPBUF MOV CX,08h REP MOVSW INT DISINT CALL DELAY MOV SI,OFFSET MES2+8000h MOV DI,DSPBUF MOV CX,08h REP MOVSW INT DISINT CALL DELAY JMP L1
; move result format message ; to display buffer ; counter for movs instruction ; counter for movs instruction
; move result format message ; to display buffer ; counter for movs instruction ; move 8 words to display buffer
; move result format message ; to display buffer ; counter for movs instruction ; move 8 words to display buffer
DELAY PROC NEAR MOV AX,0FF00h AGAIN: DEC AX JNZ AGAIN RET DELAY ENDP CODE ENDS END
3. Logical Controller
ORG 0400h MOV AL, 89h OUT 46h,AL AGAIN: IN AL, 44h MOV BL, AL AND AL, 0F0h MOV CL, 04h SHR AL,CL AND AL,BL AND AL, 0Fh OUT 42h,AL JMP AGAIN CODE ENDS END
; replace with ; XOR AL,BL for XOR operation ; OR AL,BL for OR operation