MICROPROCESSOR LAB List Of Experiments CYCLE-1: 1. 2. 3. 4. Addition of two 16-bit numbers using immediate addressing mode. Subtraction of two 16-bit numbers using immediate addressing mode. Addition of two 16-bit numbers using direct addressing mode. Subtraction of two 16-bit numbers using direct addressing mode. 5. Arithmetic Operation: a. Multiword addition b. Multiword Subtraction c. Multiplication of two 16-bit numbers d. 32bit/16 division 6. Signed operation: a. Multiplication b. Division 7. ASCII Arithmetic: a. AAA b. AAS c. AAM d. AAD e. DAA f. DAS 8. Logic Operations: a. Shift right b. Shift left c. Rotate Right without carry d. Rotate left without carry e. Rotate Right with carry f. Rotate left with carry g. Packed to unpacked h. Unpacked to packed i. BCD to ASCII j. ASCII to BCD 9. String Operation: a. String Comparison b. Moving the block of string from one segment to another segment. c. Sorting of string in ascending order d. Sorting of string in descending order e. Length of string f. Reverse of string 10. Dos Function: a. Display a character b. Display a string c. Reading a Keyboard without echo d. Input a character 11. Bios Function: a. Set video mode b. Cursor size c. Keyboard shift status d. Keyboard input with echo 12. Modular Programs: a. Generation of fibonacci series b. Factorial of a given numbers c. Find largest number of a given ‘n’ numbers d. Find smallest number of a given ‘n’ numbers e. Display the system time CYCLE-2 INTERFACING 13. 8279 Keyword Display-To display string of characters 14. 8255 PPI----ALP to generate a. Triangular wave b. Saw tooth wave c. Square wave MICROCONTROLLER-8051 15. Addition 16. Subtraction 17. Multiplication 18. Division 19. Reading and writing on a parallel port 20. Swap & Exchange 21. Timer mode operation 22. Serial Communication implementation Addition of two 16-bit numbers using DAM Aim: Write an ALP in 8086 to perform the addition of two 16-bit numbers by using direct addressing mode. Apparatus: 8086 Trainer Kit. Program: Mov ax, [1500] Mov bx, [1502] Add ax, bx Mov [1504], ax Hlt Input: Ax 3322 [1500]22 [1501]33 Bx5544 [1502]44 [1503]55 Output: Ax8866 [1500]66 [1501]88 Result: Thus the addition of two 16-bit numbers has been executed successfully using DAM and the result is verified. Subtraction of two 16-bit numbers using DAM Aim: Write an ALP in 8086 to perform the Subtraction of two 16-bit numbers by using direct addressing mode. Apparatus: 8086 Trainer Kit. Program: Mov ax, [1500] Mov bx, [1502] Sub ax, bx Mov [1504], ax Hlt Input: Ax 4433 [1500]33 [1501]44 Bx2222 [1502]22 [1503]22 Output: Ax2211 [1500]11 [1501]22 Result: Thus the Subtraction of two 16-bit numbers has been executed successfully using DAM and the result is verified. Addition of two 16-bit numbers using IAM Aim: Write an ALP in 8086 to perform the addition of two 16-bit numbers by using Immediate addressing mode. Apparatus: 8086 Trainer Kit. Program: Mov ax, 5611 Mov bx, 1234 Add ax, bx Mov [1500], ax Hlt Input: Ax 5611 Bx1234 Output: Ax6845 [1500]45 [1501]68 Result: Thus the addition of two 16-bit numbers has been executed successfully using IAM and the result is verified. Subtraction of two 16-bit numbers using IAM Aim: Write an ALP in 8086 to perform the addition of two 16-bit numbers by using Immediate addressing mode. Apparatus: 8086 Trainer Kit. Program: Mov ax, 4567 Mov bx, 1111 Sub ax, bx Mov [1500], ax Hlt Input: Ax 4567 Bx1111 Output: Ax3456 [1500]56 [1501]34 Result: Thus the subtraction of two 16-bit numbers has been executed successfully using IAM and the result is verified. 1. Arithmetic Operations a) Multi Word addition ASM code: . Model small . Stack . Data . Code Mov AX, 0000h Mov BX, 0000h ADD AX, BX Mov AX, 5678h Mov BX, 1234h ADC AX, BX Mov DX, AX INT 21h END INPUT 1: 56780000h INPUT 2: 12340000h OUTPUT: 68AD0000h CX: 0000 DX: 68AD RESULT: Thus the program for addition of two double words has been executed successfully by using TASM & result is verified. b) Multi Word subtraction ASM code: . Model small . Stack . Data . Code Mov AX, 0111h Mov BX, 1000h SUB AX, BX MOV CX, AX Mov AX, 5678h Mov BX, 1234h ADC AX, BX Mov DX, AX INT 21h END INPUT 1: 56780111h INPUT 2: 12341000h OUTPUT: 4443F111h CX: F111 LSW of the result DX: 68AD MSW of the result RESULT: Thus the program for subtraction of two double words has been executed successfully by using TASM & result is verified. c) Multiplication of two 16-bit numbers ASM code: . Model small . Stack . Data . Code Mov AX, 1234h Mov BX, 1234h MUL BX INT 21h END INPUT 1: 1234h INPUT 2: 1234h OUTPUT: 014B5A90h CX: 5A90 LSW of the result DX: 014B MSW of the result RESULT: Thus the program for multiplication of two 16-bit program executed successfully by using TASM & result is verified. d) Multi Word Division (32-bit/16-bit) ASM code: . Model small . Stack . Data . Code Mov AX, 2786h Mov BX, 2334h Mov CX, 3552h DIV CX INT 21h END INPUT 1: 23342786h INPUT 2: 3552h OUTPUT: 303EA904h AX: A904 LSW of the result DX: 303E MSW of the result RESULT: Thus the multi word division of programs executed successfully by using TASM & result is verified. 3. Signed Operation a. Multiplication of two signed numbers ASM code: . Model small . Stack . Data . Code Mov AX, 8000h Mov BX, 2000h IMUL BX INT 21H END INPUT 1:8000h INPUT 2: 2000h OUTPUT: AX 0000h DX F000h RESULT: Thus the program for multiplication of two signed numbers has been executed successfully by using TASM & result is verified. b. Division of two signed numbers ASM code: . Model small . Stack . Data . Code Mov AX, -0002h Mov BL, 80h IDIV BL INT 21H END INPUT 1:AX0002h BX 80h OUTPUT: AX 00C0h AlC0h Ah 00h RESULT: Thus the program for division of two signed numbers has been executed successfully by using TASM & result is verified. 4. ASCII Arithmetic Operation a) AAA ASM code: . Model small . Stack . Data . Code Mov AL, 35h Mov BL, 37h ADD AL, BL AAA Int 21h End INPUT 1: 35h INPUT 2: 37h OUTPUT: AX0102h RESULT: Thus the program for AAA has been executed successfully by using TASM & result is verified. b) AAS ASM code: . Model small . Stack . Data . Code Mov AL, 37h Mov BL, 35h SUB AL, BL AAS Int 21h End INPUT 1: 37h INPUT 2: 35h OUTPUT: AX0002h RESULT: Thus the program for AAS has been executed successfully by using TASM & result is verified. c) AAM ASM code: . Model small . Stack . Data . Code Mov AL, 06h Mov BL, 09h MUL BL AAM Int 21h End INPUT 1: 09h INPUT 2: 06h OUTPUT: AX0504h(un packed BCD) RESULT: Thus the program for AAM has been executed successfully by using TASM & result is verified. d) AAD ASM code: . Model small . Stack . Data . Code Mov AX, 1264h Mov BL, 04h DIV BL AAD Int 21h End INPUT 1: 1264h INPUT 2: 04h OUTPUT: AX0499 RESULT: Thus the program for AAD has been executed successfully by using TASM & result is verified. e) DAA ASM code: . Model small . Stack . Data . Code Mov AL, 59h Mov BL, 0935h ADD AL, BL DAA Int 21h End INPUT 1: 59h INPUT 2: 35h OUTPUT: AX0094h RESULT: Thus the program for DAA has been executed successfully by using TASM & result is verified. f) DAS ASM code: . Model small . Stack . Data . Code Mov AL, 75h Mov BL, 46h SUBAL, BL DAS Int 21h End INPUT 1: 75h INPUT 2: 46h OUTPUT: AL29h RESULT: Thus the program for DAS has been executed successfully by using TASM & result is verified. Logic Operation Shift Right ASM code: . Model small . Stack . Data . Code Mov al, 46h Mov cl, 04h Shr al, cl Int 21h End Input: Al46 Cl04 Output: 04h RESULT: Thus the program for Shift right operation has been executed successfully by using TASM & result is verified. Shift Left ASM code: . Model small . Stack . Data . Code Mov al, 46h Mov cl, 04h Shl al, cl Int 21h End Input: Al46 Cl04 Output: 60h RESULT: Thus the program for Shift left operation has been executed successfully by using TASM & result is verified. Rotate Right Without Carry ASM code: . Model small . Stack . Data . Code Mov al, 68h Mov cl, 04h Ror al, cl Int 21h End Input: Al68h Cl04h Output: 86h RESULT: Thus the program for rotate right without carry has been executed successfully by using TASM & result is verified. Rotate Left Without carry ASM code: . Model small . Stack . Data . Code Mov al, 60h Mov cl, 04h Rol al, cl Int 21h End Input: Al60h Cl04h Output: 06h RESULT: Thus the program for rotate left without carry has been executed successfully by using TASM & result is verified. Rotate Right With Carry ASM code: . Model small . Stack . Data . Code Mov al, 56h Mov cl, 03h Rcr al, cl Int 21h End Input: Al56h Cl03h Output: Al= Bl RESULT: Thus the program for rotate right with carry has been executed successfully by using TASM & result is verified. Rotate Left With Carry ASM code: . Model small . Stack . Data . Code Mov al, 56h Mov cl, 03h Rcl al, cl Int 21h End Input: Al56h Cl03h Output: Al=8Ah RESULT: Thus the program for rotate left with carry has been executed successfully by using TASM & result is verified. Packed BCD to UNPACKED BCD Conversion ASM Code: . Model small . Stack . Data . Code Mov BL, 57h Mov BH, 04h Mov AL, BL Mov CL, BH SHL AL, CL Mov CL, BH ROR AL, CL Mov DL, AL Mov AL, BL Mov CL, BH SHR AL, CL Mov DH, AL INT 21H END Input: BL (Packed BCD) = Output: DX (Unpacked BCD) = RESULT: Thus the program for conversion of packed to unpacked has been executed successfully by using TASM & result is verified. UNPACKED BCD to Packed BCD Conversion ASM Code: . Model small . Stack . Data . Code Mov ax, 0207h Mov al, 04h Ror al, cl Shr ax, cl INT 21H END Input: AX0207(Unpacked BCD) Output: AX0027(packed BCD) RESULT: Thus the program for conversion of unpacked to packed has been executed successfully by using TASM & result is verified. ASCII to BCD ASM Code: . Model small . Stack . Data . Code Mov ax, 3638h Mov bx, 3030h Mov cl, 04h Shl al, cl Ror ax, cl INT 21H END Input: AX3638h(Unpacked BCD) Output: AX0068(packed BCD) RESULT: Thus the program for conversion of ASCII to BCD value has been executed successfully by using TASM & result is verified. BCD to ASCII ASM Code: . Model small . Stack . Data . Code Mov AL, 57h Mov CL, 04h SHL AL, CL ROR AL. 04H XOR AL, 30H MOV BL, AL MOV AL, 57H MOV CL, 04H SHR AL, CL XOR AL, 30H MOV BH. AL INT 21H END Input: AL (BCD) Output: BX (ASCII) RESULT: Thus the program for conversion of BCD TO ASCII value has been executed successfully by using TASM & result is STRING OPERATIONS Strings Comparison: ASM CODE: . Model small . Stack . Data Strg1 db ‘lab’,’$’ Strg 2 db ‘lab’, $’ Res db ‘strg are equal’,’$’ Res db ‘strg are not equal’,’$’ Count equ 03h . Code Mov ax, @data Mov ds, ax Mov es, ax Lea si, strg1 Lea di, strg2 Cld Rep cmpsb Jnz loop1 Mov ah, 09h Lea dx, res Int 21h Jmp a1 Loop1: mov ah, 09h Lea dx, re1 Int 21h A1: mov ah, 4ch Int 21h End Input: Strg1 Strg2 Output: Result: Thus the program of string comparison is executed successfully and the result is verified. Data Transfer from one segment to another segment ASM CODE: . Model small . Stack . Data String db’computer’ String 1 db8 dup (?) . Code Mov ax, @data Mov ds, ax Mov es, ax Mov cl, 08h Mov si, offset string Mov di, offset string 1 Cld Rep movsb Int 21h End Input: Output: Result: Thus the program to move a block of string from one memory location to another memory location is executed successfully. Sorting a string in an ascending order ASM code: . Model small . Stack . Data List1 db 53h, 10h, 24h, 12h Count Equ, 04h . Code Mov AX, @data Mov DS, AX Mov Dx, Count-1 Again2: Mov CX, DX Mov SI, offset List1 Again1: Mov AL, [SI] CMP AL, [SI+1] JL PR1 XCHG [SI+1], AL XCHG [SI], AL PR1: ADD SI, 01H Loop Again1 DEC DX JNZ Again2 Mov AH, 4ch Int 21h End Input: Enter string: 53h, 10h, 24h, 12h Output: Sorted String: 10h, 12h, 24h, 53h Result: Thus the program for sorting a string in an ascending order is executed successfully by TASM & result is verified. Sorting a string in an descending order ASM code: . Model small . Stack . Data List1 db 53h, 10h, 24h, 12h Count Equ, 04h . Code Mov AX, @data Mov DS, AX Mov Dx, Count-1 Again2: Mov CX, DX Mov SI, offset List1 Again1: Mov AL, [SI] CMP AL, [SI+1] JL PR1 XCHG [SI+1], AL XCHG [SI], AL PR1: ADD SI, 01H Loop Again1 DEC DX JNZ Again2 Mov AH, 4ch Int 21h End Input: Enter string: 53h, 10h, 24h, 12h Output: Sorted String: 10h, 12h, 24h, 53h Result: Thus the program for sorting a string in an ascending order is executed successfully by TASM & result is verified. Length of the string ASM Code: . Model small . Stack . Data S1. Label byte Mx1 db 30 Al1 db? S2 db’ enter the string’,‘$’ S3 db’ Length of the string’,’$’ . Code Mov ax, @data Mov ds, ax Mov ah, 09H Lea dx, S2 Int 21h Mov ah, 0ah Lea dx, S3 Int 21h Mov ah, 02h Mov dl, al1 Or dl, 30h Int 21h End Input: Enter the string SVCET Output: length of the string DS: 0005 Result: Thus the program to find the length of the string is executed successfully by TASM & result is verified. BIOS FUNCTION (a) Set video mode: ASM CODE: . Model small . Stack . Data . Code Mov ah, 00h Mov al, 01h Int 10h End Input: Ah00h; Set video mode Al01h; mode has been set for 25*40 Output: The output screen has been changed for 25*40 Result: Thus the program to set video mode is executed successfully by TASM & result is verified. (b) Set cursor size ASM Code: . Model small . Stack . Data . Code Mov ah, 01h Mov ch, 00h Mov cl, 14h Int 10h End Input: Ah01h set cursor size Cl 14h top level value of the cursor. Ch 00h low level value of the cursor. Output: Thus cursor size has been changed. Result: Thus the program to set cursor size is executed successfully by TASM & result is verified. © Key board shift status ASM Code: . Model small . Stack . Data . Code Mov ah, 12h Int 16h End Input: Caps lock, num lock, scroll lock are chosen before execution of the program. Output: Al 70-01110000. The content of the al reg has to represented bit wise. The corresponding bit has been set. Result: Thus the program to know the keyboard status is executed successfully by TASM & result is verified. Keyboard Input With Echo ASM Code: . Model Small . Stack . Data . Code Mov ah, 01h Int 21h End Input: Ah01h Output: The character ‘a’ is display along with ASCII value AX=0061. Result: Thus the program for keyboard input with echo using TASM software is executed successfully. Dos Function Calls 1) Display a character: Program: . Model Small . Stack . Data . Code Mov ah, 02h Mov Dl, ‘a’ Int 21h End Input: Character ‘a’ is given as input. Output: Character ‘a’ is display as output along with ASCII value DX=0061 Result: Thus the program to display a character has successfully executed and output is verified. 2) Display a String: Program: . Model Small . Stack . Data Stg db “display a string”,’$’ . Code Mov ax, @data Mov ds, ax Mov ah, 09h Lea dx, stg Int 21h End Input: “ Display a string” is given as input. Output: Display a string is obtained as output. Result: Thus the program to display a string was successfully executed and output is verified. 3) Input a character: Program: . Model small . Stack . Data . Code Mov ah, 01h Int 21h End Input: Ah01h ‘A’ is entered as input. Output: The character ‘a’ is displayed along with ASCII value i.e. AX=0161 Result: Thus the program to input a character was executed successfully and the result is verified 4) Reading a keyboard without Echo Program: . Model small . Stack . Data . Code Mov ah, 08h Int 21h Int 21h End Input: Ah 08h Press a char ‘a’ Output: The character ‘a’ is not displayed but ASCII value is AX=0861 Result: Thus the program to read a keyboard character without echo is executed successfully by TASM result is verified. Modular Program 1) Fibonacci series: Aim: Write a program to generate fibonnaci series. Apparatus: System with TASM software. Program: . Model small . Stack . Data . Code Mov ax, @data Mov ds, ax Mov cl, 05h Mov al, 00h Mov bl, 01h Mov si, 0000h Mov [si], al Inc si Mov [si], bl Up: add al, bl Inc si Mov [si], al Xchg al, bl Loop up Int 21h End Input: Cl 05h Output: Result: Thus the program to find the fibonacci series is executed successfully using TASM software and output is verified. 2) Factorial of a given numbers Aim: To write an ALP program to generate factorial of a given numbers. Apparatus: System with TASM software. Program: . Model small . Stack . Data . Code Mov ax, @data Mov ds, ax Mov ax, 0001h Mov cl, 05h Up: Mul cl Dec cl Jnz up Int 21h End Input: Cl 05h Output: Result: Thus the factorial of a given number was executed successfully using TASM and result is verified. 3) Largest number of a given ‘n’ numbers Aim: To write an ALP program to generate largest number of a given number. Apparatus: System with TASM software. Program: . Model small . Stack . Data List db 02h, 09h, 03h, 06h, 08h, 07 . Code Mov ax, @data Mov ds, ax Mov si, offset list Mov cl, 05h Mov ax, 0000h Mov al, [si] Up: Inc si Cmp al, [si] Jnb go Mov al, [si] Go: loop up Int 21h End Input: 02h, 09h, 03h, 06h, 08h, 07 Output: Result: Thus the factorial largest number of a given ‘n’ number program was executed successfully using TASM and result is verified. 4) Smallest number of a given ‘n’ numbers Aim: To write an ALP program to generate smallest number of a given number. Apparatus: System with TASM software. Program: . Model small . Stack . Data List db 02h, 09h, 03h, 06h, 08h, 07 . Code Mov ax, @data Mov ds, ax Mov si, offset list Mov cl, 05h Mov al, 00h Mov al, [si] Up: Inc si Cmp al, [si] Jnb go Mov al, [si] Go: loop up Int 21h End Input: 02h, 09h, 03h, 06h, 08h, 07 Output: Result: Thus the factorial smallest number of a given ‘n’ number program was executed successfully using TASM and result is verified. 5) Display the system time Aim: To write an ALP to display the system time in cursor position continuously. Dos function code 2 ch of int 21 When this function is executed, it reads hours, Minutes & Seconds from main memory and stores it in the following specified registers. CH=Hour (0 to 23) CL=Minutes (0 to 59) DH=Seconds (0 to 59) Text display function code 02h 0f int 10h It sets the cursor position and displays the content. It uses the following specified registers. DH=cursor row (0 to 24) DL=cursor column (0 to 79 for 80 X 25 display) (0 to 39 for 40 X 25 display) BH=video page no. Program: . Model small . Stack . Data Stg1 db’the time is’ Stg2 db 2 dup (0),’:’ Stg3 db 2 dup (0),’:’ Stg4 db 2 dup (0), 0dh, 0ah,’$’ Hrs db 0 Min db 0 Sec db 0 . Code Main proc Begin: Mov ax, @data Mov ds, ax Mov ah, 2ch Int 21h Mov Hours, ch Mov Min, cl Mov sec, DH Lea bx, stg2+2 Xor ax, ax Mov al, Hrs Call num Mov [bx], ax Lea bx, stg3+2 Xor ax, ax Mov al, Min Call num Mov al, [`bx], ax Lea bx, stg4+2 Xor ax, ax Mov al, Sec Call num Mov [bx], ax Mov ah, 00 Mov al, 03 Mov ah, 02 Mov BH, 00 Mov DH, 05 Mov dl, 32 Lea dx, stg1 Mov ah, 09h Int 21h] Jmp begin Main endp Num proc Mov ah, 00 Mov dl, 10 Div dl Or ax, 3030h Ret Num endp End Result: Thus the ‘ display the time ‘ output is display. Cycle-2 8279- keyboard display: