· web viewmodular programs: generation of fibonacci series factorial of a given numbers find...

63
MICROPROCESSOR LAB List Of Experiments CYCLE-1: 1. Addition of two 16-bit numbers using immediate addressing mode. 2. Subtraction of two 16-bit numbers using immediate addressing mode. 3. Addition of two 16-bit numbers using direct addressing mode. 4. 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

Upload: vanquynh

Post on 25-Apr-2018

218 views

Category:

Documents


2 download

TRANSCRIPT

MICROPROCESSOR LAB

List Of Experiments

CYCLE-1:

1. Addition of two 16-bit numbers using immediate addressing mode.2. Subtraction of two 16-bit numbers using immediate addressing mode.3. Addition of two 16-bit numbers using direct addressing mode.4. Subtraction of two 16-bit numbers using direct addressing mode.

5. Arithmetic Operation:a. Multiword additionb. Multiword Subtractionc. Multiplication of two 16-bit numbersd. 32bit/16 division

6. Signed operation:a. Multiplicationb. Division

7. ASCII Arithmetic:a. AAAb. AASc. AAMd. AADe. DAAf. DAS

8. Logic Operations:a. Shift rightb. Shift leftc. Rotate Right without carryd. Rotate left without carrye. Rotate Right with carryf. Rotate left with carryg. Packed to unpackedh. Unpacked to packedi. BCD to ASCIIj. ASCII to BCD

9. String Operation:a. String Comparisonb. Moving the block of string from one segment to another segment.c. Sorting of string in ascending orderd. Sorting of string in descending ordere. Length of stringf. Reverse of string

10. Dos Function:a. Display a characterb. Display a string c. Reading a Keyboard without echod. Input a character

11. Bios Function:a. Set video modeb. Cursor size c. Keyboard shift statusd. Keyboard input with echo

12. Modular Programs:a. Generation of fibonacci seriesb. Factorial of a given numbersc. Find largest number of a given ‘n’ numbersd. Find smallest number of a given ‘n’ numberse. Display the system time

CYCLE-2

INTERFACING

13. 8279 Keyword Display-To display string of characters14. 8255 PPI----ALP to generate

a. Triangular waveb. Saw tooth wavec. Square wave

MICROCONTROLLER-8051

15. Addition16. Subtraction17. Multiplication18. Division19. Reading and writing on a parallel port20. Swap & Exchange21. Timer mode operation22. 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, bxMov [1504], axHlt

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, bxMov [1504], axHlt

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, 5611Mov bx, 1234Add ax, bxMov [1500], axHlt

Input:Ax 5611Bx1234

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, 4567Mov bx, 1111Sub ax, bxMov [1500], axHlt

Input:

Ax 4567Bx1111

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

. CodeMov AX, 0000hMov BX, 0000hADD AX, BXMov AX, 5678hMov BX, 1234hADC AX, BXMov DX, AXINT 21hEND

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

. CodeMov AX, 0111hMov BX, 1000hSUB AX, BXMOV CX, AXMov AX, 5678hMov BX, 1234hADC AX, BXMov DX, AXINT 21hEND

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

. CodeMov AX, 1234hMov BX, 1234hMUL BXINT 21hEND

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

. CodeMov AX, 2786hMov BX, 2334hMov CX, 3552hDIV CXINT 21hEND

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

. CodeMov AX, 8000hMov BX, 2000hIMUL BXINT 21HEND

INPUT 1:8000hINPUT 2: 2000h

OUTPUT:

AX 0000hDX 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

. CodeMov AX, -0002hMov BL, 80hIDIV BLINT 21HEND

INPUT 1:AX0002hBX 80h

OUTPUT:

AX 00C0hAlC0hAh 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

. CodeMov AL, 35hMov BL, 37hADD AL, BLAAA Int 21hEnd

INPUT 1: 35hINPUT 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

. CodeMov AL, 37hMov BL, 35hSUB AL, BLAAS Int 21hEnd

INPUT 1: 37hINPUT 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

. CodeMov AL, 06hMov BL, 09hMUL BLAAM Int 21hEnd

INPUT 1: 09hINPUT 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

. CodeMov AX, 1264hMov BL, 04hDIV BLAAD Int 21hEnd

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

. CodeMov AL, 59hMov BL, 0935hADD AL, BLDAA Int 21hEnd

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

. CodeMov AL, 75hMov BL, 46hSUBAL, BLDAS Int 21hEnd

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

. CodeMov al, 46hMov cl, 04hShr al, clInt 21hEnd

Input:

Al46Cl04

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

. CodeMov al, 46hMov cl, 04hShl al, clInt 21hEnd

Input:

Al46Cl04

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

. CodeMov al, 68hMov cl, 04hRor al, clInt 21hEnd

Input:

Al68hCl04h

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

. CodeMov al, 60hMov cl, 04hRol al, clInt 21hEnd

Input:

Al60hCl04h

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

. CodeMov al, 56hMov cl, 03hRcr al, clInt 21hEnd

Input:

Al56hCl03h

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

. CodeMov al, 56hMov cl, 03hRcl al, clInt 21hEnd

Input:

Al56hCl03h

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

. CodeMov BL, 57hMov BH, 04hMov AL, BLMov CL, BHSHL AL, CLMov CL, BHROR AL, CLMov DL, ALMov AL, BLMov CL, BHSHR AL, CLMov DH, ALINT 21HEND

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

. CodeMov ax, 0207hMov al, 04hRor al, clShr ax, clINT 21HEND

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

. CodeMov ax, 3638hMov bx, 3030hMov cl, 04hShl al, clRor ax, clINT 21HEND

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

. CodeMov AL, 57hMov CL, 04hSHL AL, CLROR AL. 04HXOR AL, 30HMOV BL, ALMOV AL, 57HMOV CL, 04HSHR AL, CL XOR AL, 30HMOV BH. ALINT 21HEND

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. DataStrg1 db ‘lab’,’$’Strg 2 db ‘lab’, $’Res db ‘strg are equal’,’$’Res db ‘strg are not equal’,’$’Count equ 03h. CodeMov ax, @dataMov ds, axMov es, axLea si, strg1Lea di, strg2CldRep cmpsbJnz loop1Mov ah, 09hLea dx, resInt 21hJmp a1Loop1: mov ah, 09hLea dx, re1Int 21hA1: mov ah, 4chInt 21hEnd

Input:

Strg1Strg2

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

. DataString db’computer’String 1 db8 dup (?). CodeMov ax, @dataMov ds, axMov es, axMov cl, 08hMov si, offset stringMov di, offset string 1CldRep movsbInt 21hEnd

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

. DataList1 db 53h, 10h, 24h, 12hCount Equ, 04h. CodeMov AX, @dataMov DS, AXMov Dx, Count-1Again2: Mov CX, DXMov SI, offset List1Again1: Mov AL, [SI]CMP AL, [SI+1]JL PR1XCHG [SI+1], ALXCHG [SI], ALPR1: ADD SI, 01HLoop Again1DEC DXJNZ Again2Mov AH, 4chInt 21hEnd

Input: Enter string: 53h, 10h, 24h, 12hOutput:

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

. DataList1 db 53h, 10h, 24h, 12hCount Equ, 04h. CodeMov AX, @dataMov DS, AXMov Dx, Count-1Again2: Mov CX, DXMov SI, offset List1Again1: Mov AL, [SI]CMP AL, [SI+1]JL PR1XCHG [SI+1], ALXCHG [SI], ALPR1: ADD SI, 01HLoop Again1DEC DXJNZ Again2Mov AH, 4chInt 21hEnd

Input: Enter string: 53h, 10h, 24h, 12hOutput:

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

. DataS1. Label byteMx1 db 30Al1 db?S2 db’ enter the string’,‘$’S3 db’ Length of the string’,’$’. CodeMov ax, @dataMov ds, axMov ah, 09HLea dx, S2Int 21hMov ah, 0ahLea dx, S3Int 21hMov ah, 02hMov dl, al1Or dl, 30hInt 21hEnd

Input: Enter the stringSVCET

Output: length of the stringDS: 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. CodeMov ah, 00hMov al, 01hInt 10hEnd

Input: Ah00h; Set video modeAl01h; 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. CodeMov ah, 01hMov ch, 00hMov cl, 14hInt 10hEnd

Input:Ah01h set cursor sizeCl 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. CodeMov ah, 12hInt 16hEnd

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

. CodeMov ah, 01hInt 21hEnd

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, 02hMov Dl, ‘a’Int 21hEnd

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. DataStg db “display a string”,’$’. CodeMov ax, @dataMov ds, axMov ah, 09hLea dx, stgInt 21hEnd

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. CodeMov ah, 01hInt 21hEnd

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

. CodeMov ah, 08hInt 21hInt 21hEnd

Input:Ah 08hPress 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. CodeMov ax, @data Mov ds, axMov cl, 05hMov al, 00hMov bl, 01hMov si, 0000hMov [si], alInc siMov [si], bl

Up: add al, blInc siMov [si], alXchg al, blLoop upInt 21hEnd

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. CodeMov ax, @dataMov ds, axMov ax, 0001hMov cl, 05h

Up: Mul clDec clJnz upInt 21hEnd

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. DataList db 02h, 09h, 03h, 06h, 08h, 07. CodeMov ax, @dataMov ds, axMov si, offset listMov cl, 05hMov ax, 0000hMov al, [si]

Up: Inc siCmp al, [si]Jnb goMov al, [si]

Go: loop upInt 21hEnd

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. DataList db 02h, 09h, 03h, 06h, 08h, 07. CodeMov ax, @dataMov ds, axMov si, offset listMov cl, 05hMov al, 00hMov al, [si]

Up: Inc siCmp al, [si]Jnb goMov al, [si]

Go: loop upInt 21hEnd

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 10hIt 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. DataStg1 db’the time is’Stg2 db 2 dup (0),’:’Stg3 db 2 dup (0),’:’Stg4 db 2 dup (0), 0dh, 0ah,’$’Hrs db 0Min db 0Sec db 0. CodeMain proc

Begin: Mov ax, @dataMov ds, axMov ah, 2chInt 21hMov Hours, chMov Min, clMov sec, DHLea bx, stg2+2Xor ax, axMov al, HrsCall num

Mov [bx], axLea bx, stg3+2Xor ax, axMov al, MinCall numMov al, [`bx], axLea bx, stg4+2Xor ax, axMov al, SecCall numMov [bx], axMov ah, 00Mov al, 03Mov ah, 02Mov BH, 00Mov DH, 05Mov dl, 32Lea dx, stg1Mov ah, 09hInt 21h]Jmp beginMain endpNum procMov ah, 00Mov dl, 10Div dlOr ax, 3030hRet Num endpEnd

Result:Thus the ‘ display the time ‘ output is display.

Cycle-2

8279- keyboard display: