52594869-8086-Programs-semester-4

January 13, 2017 | Author: Imran | Category: N/A
Share Embed Donate


Short Description

Download 52594869-8086-Programs-semester-4...

Description

1

LIST OF MICROPROCESSOR LAB EXPERIMENTS 1. Write an ALP to transfer a block of N word from source block to the destination block, without overlap. 2. Write an ALP to transfer a block of N word from source block to the destination block, with overlap. 3. Write an ALP to interchange a block of N-bytes / words. 4.

Write an ALP to add the two given N-bit multi precision numbers {N ≥ 32 bits}.

5. Write an ALP to multiply two 32-bits unsigned hexadecimal numbers. 6. Write an ALP to divide an unsigned N-bit hexadecimal number by an unsigned Hexadecimal byte (N to be specified > 16bits). 7. Write an ALP to check whether the given 8-bit data is a. 2 out of 5 code. b. Bitwise and nibble wise palindrome. 8. Write an ALP to check whether the given 8-bit data is a. Positive of Negative. b. Odd or even. c. Find the logical 1’s and 0’s in the given data. 9. Write an ALP to find the HCF of two 16-bit unsigned numbers. 10.Write an ALP to find the LCM of two 16-bit unsigned integers.

2 11. Write

an ALP to find the factorial of a number N (N≤ 9).

12.Write an ALP to convert 16-bit BCD number to its Hexadecimal equivalent. 13.Write an ALP to convert a given 16-bit Hexadecimal number to its BCD equivalent. Display the result. 14.Write an ALP to find the square and cube of a given 32-bit hexadecimal number. 15.Write an ALP to add two strings of ASCII digits. (Length to be specified). 16.Write an ALP to subtract two strings of ASCII digits (Length to be specified). 17.Write an ALP to multiply a string of ASCII digits by a single ASCII digit. 18.Write an ALP to divide a string of ASCII digits by a single ASCII digit. 19.Write an ALP to transfer the given string data to the destination using string primitive instructions. 20.Write an ALP to reverse a string and check whether the given string is a palindrome or not. 21.Write an ALP to sort the given set of 16-bit unsigned integers in ascending/descending order using Bubble sort algorithm. 22.Write an ALP to sort the given set of 16-bit unsigned integers in ascending/descending order using Insertion sort algorithm.

3

23.Write an ALP to find the largest element in an array of 16-bit signed / unsigned integers. (Array size to be specified). 24.Write an ALP to search for the occurrence of a character in a given string. The string and the character, to be entered from the keyboard using DOS interrupts INT 21H function calls for a. Reading a character from keyboard b. Reading a string using buffered keyboard input.

4

1) Block movement of data .MODEL SMALL .DATA SOURCE_BLOCK DESTN_BLOCK .CODE

LOC1:

(word transfer) without overlap

DW DW

89ABH,0ABCDH,0020H,0F0H,0100H 5 DUP(?)

MOV MOV LEA LEA MOV

AX,@DATA DS,AX SI, SOURCE_BLOCK DI, DESTN_BLOCK CX,05H

MOV MOV INC INC INC INC DEC JNZ

AX,[SI] [DI],AX SI SI DI DI CX LOC1

MOV AH,4CH INT 21H END

;Loads DS with upper 16_bits of Data Seg Base ;SI is source pointer ;DI is destination pointer. ;BLOCK LENGTH = 5

;Each pointer to be incremented by 2 ;to point to next word.

;DOS INTERRUPT 21H, FUNCTION 4CH, ;Terminates Program And Returns Control To DOS

;DATA FILE: L ; G ; DW SOURCE_BLOCK L5 ; DW DESTN_BLOCK L5 ; Q

(Comment: For Byte transfer without overlap (question 1b) change All DW to DB (corresponding data should be given 98h,0CFH...) Change AX to AL in LOC1 Loop {MOV AL,[SI] & MOV [DI],AL} Increment SI & DI register only once)

5 2) Block movement of data (Byte transfer) with overlap Write an ALP to move a block of N=10 data bytes with overlap, the destination block ending on 6th byte position of the source block. .MODEL SMALL .DATA POS

EQU 6

DSTN_BLK DB SRC_BLK

; Position where destination block ends ; within the source block. 10-(POS+1) DUP(0)

; To determine starting of ; destination block.

DB 11H,22H,33H,44H,55H,66H,77H,88H,99H,0AAH

.CODE MOV AX,@DATA MOV DS,AX LEA SI,SRC_BLK LEA DI,DSTN_BLK MOV CX,10 LOC1:

;SI Points To Source Block ;DI Points To Destination Block ;No.of Bytes To Be Transferred=10

MOV AL,[SI] MOV [DI],AL INC SI INC DI LOOP LOC1 MOV AH,4CH INT 21H END

;DATA FILE : L ; DB SRC_BLK LA ; G ; DB DSTN_BLK LA ; DB SRC_BLK LA ; Q

(Comment:

;INT 21H, Function 4CH ;Terminates Program, Returns Control To DOS

;source block before execution. Length=0aH ;some of the source words are overwritten.

For word transfer with overlap change All DB to DW and give the corresponding data (0011H,0022H...) Change AL to AX Again Increment SI & DI register)

6 3) Block Interchange of 2 Blocks of Word Data .MODEL SMALL .DATA X_BLOCK DW Y_BLOCK DW

0123H,3456H,789AH,0BCDEH,0F231H 1122H,3344H,5566H,7788H,0AABBH

.CODE

LOC1:

MOV MOV LEA LEA MOV

AX,@DATA DS,AX SI,X_BLOCK DI,Y_BLOCK CX,0005H

MOV MOV MOV MOV

AX,[SI] BX,[DI] [DI],AX [SI],BX

INC DI INC DI INC SI INC SI LOOP LOC1

;Decrements CX,if CX != 0, jumps to LOC1.

MOV AH,4CH INT 21H END ;DATA FILE ; ; ; ; ; ;

: L DW DW G DW DW Q

;Loads DS with upper 16-bits of Data_Seg Base ;SI POINTS TO X_BLOCK ;DI POINTS TO Y_BLOCK ;Length Of Block = 5

;Terminates Program, return control to DOS.

X_BLOCK L5 Y_BLOCK L5 X_BLOCK L5 Y_BLOCK L5

7

4)

Program to perform addition on multi precision nos. x+y=z, where x and y are 64-bit nos, each.

.MODEL SMALL .DATA X Y Z .CODE

DB DB DB

;X=89ABCDEF01234567H ;Y=12BC34ABDEF01234H ;Result in 9 bytes.

MOV AX,@DATA MOV DS,AX LEA LEA LEA MOV CLC

LOC1:

67H,45H,23H,01H,0EFH,0CDH,0ABH,89H 34H,12H,0F0H,0DEH,0ABH,34H,0BCH,12H 9 DUP(?)

SI,X DI,Y BX,Z CX,08

MOV AL,[SI] ADC AL,[DI] MOV [BX],AL INC INC INC DEC JNZ MOV RCL MOV

SI DI BX CX LOC1 AL,00 AL,01 [BX],AL

MOV AH,4CH INT 21H END

;DATA FILE : L ; G ; DB X L8 ; DB Y L8 ; DB Z L9 ; Q

;SI POINTS TO ADDEND BYTES ;DI POINTS TO AUGEND BYTES ;BX POINTS TO RESULT BYTES ;

;PARTIAL RESULT

;CLEAR ACC ;FINAL RESULT BYTE.

8

5) MULTIPLICATION OF TWO UNSIGNED 32-BIT NUMBERS .MODEL SMALL .DATA

MPD MPR RES

DW DW DW

0C432H,765BH 3679H,0B397H 4 DUP(0)

.CODE MOV AX,@DATA MOV DS,AX MOV MOV MUL MOV MOV

BX,OFFSET MPD AX,[BX] MPR RES,AX RES+2,DX

MOV MUL ADD ADC JNC INC

AX,[BX] MPR+2 RES+2,AX RES+4,DX L1 RES+6

L1:

MOV MUL ADD ADC JNC INC

AX,[BX+2] MPR RES+2,AX RES+4,DX L2 RES+6

L2:

MOV MUL ADD ADC

AX,[BX+2] MPR+2 RES+4,AX RES+6,DX

MOV AH,4CH INT 21H END ;DATA FILE ;L ;G ;DW MPD L2 ;DW MPR L2 ;DW RES L4 ;Q ;RESULT FILE

9 ;>L ;>G ;Program terminated normally (-83) ;>DW MPD L2 ;4C74:0002 C432 765B ;>DW MPR L2 ;4C74:0006 3679 B397 ;>DW RES L4 ;4C74:000A 47A2 FC40 137E 5308 ;>Q

10

6)DIVISION BY A BYTE OR WORD .MODEL SMALL .DATA

DIVD DIVS REM COUNT QUO

DW DW DW EQU DW

0B347H,7653H,9641H,458BH 0A8H ? DIVS-DIVD COUNT DUP(0)

.CODE MOV AX,@DATA MOV DS,AX MOV SI,OFFSET DIVD+COUNT-1 MOV DI,OFFSET QUO DEC SI MOV DX,[SI] MOV BX,DIVS MOV CX,COUNT/2 DEC CX CMP DX,DIVS JB CONT JMP ADJUST CONT: CMP CX,0 JNZ NEXT INC CX MOV AX,DX MOV DX,0 JMP NEXT1 ADJUST: MOV XOR INC JMP NEXT: DEC DEC MOV NEXT1: DIV MOV INC INC DEC JNZ MOV

AX,DX DX,DX CX NEXT1 SI SI AX,[SI] BX [DI],AX DI DI CX NEXT REM,DX

MOV AH,4CH INT 21H ALIGN 16 END

11

;DATA FILE ;L ;G ;DW ;DW ;DW ;DW ;Q

DIVD L4 DIVS L1 QUO L4 REM L1

;RESULT FILE ;>L ;>G ;Program terminated normally (-93) ;>DW DIVD L4 ;4C74:0000 B347 7653 9641 458B ;>DW DIVS L1 ;4C74:0008 00A8 ;>DW QUO L4 ;4C74:000C 0069 F946 7C22 05A3 ;>DW REM L1 ;4C74:000A 004F ;>Q

12

;7) CHECK WHETHER THE GIVEN 8 BIT DATA IS: ;1)2 OUT OF 5 CODE ;2)BITWISE AND NIBBLEWISE PALINDROME .MODEL SMALL .DATA NUM RES COUNT .CODE

DB DB DB

0ACH 3 DUP(0) 0

MOV AX,@DATA MOV DS,AX LEA SI,NUM LEA DI,RES CALL FINDP MOV AH,4CH INT 21H

FINDP PROC NEAR MOV AX,[SI] MOV BX,AX TEST AL,0E0H JNZ NO25 MOV CX,5 BACK0: ROR AL,1 JNC LOC1 INC COUNT LOC1: LOOP BACK0 CMP COUNT,2 JZ NEXT1 NO25: MOV BYTE PTR [DI],0FFH NEXT1: MOV AX,BX MOV CX,8 BACK1: ROL AL,1 RCR AH,1 LOOP BACK1 CMP AH,AL JZ PAL_NIB MOV BYTE PTR 1[DI],0FFH PAL_NIB:MOV AX,BX AND AL,0FH AND BL,0F0H MOV CL,04H ROR BL,CL CMP AL,BL JZ LOC2 MOV BYTE PTR 2[DI],0FFH LOC2: RET

13 FINDP ENDP END 8)CHECK WHETHER THE GIVEN 8-BIT DATA IS ;1)POSITIVE OR NEGATIVE ;2)ODD OR EVEN ;3)FIND THE NUMBER OF 1'S & 0'S .MODEL SMALL .DATA NUM DB RES DB N_1S DB N_0S DB

7DH 4 DUP(?) 00H 08H

.CODE MOV AX,@DATA MOV DS,AX LEA SI,NUM LEA DI,RES CALL FINDP MOV AH,4CH INT 21H FINDP PROC NEAR MOV AX,[SI] MOV BX,AX AND AL,0FFH JNS NEXT1 MOV BYTE PTR [DI],0FFH NEXT1: TEST AL,01H JNZ NEXT2 MOV BYTE PTR 1[DI],0FFH NEXT2: MOV AX,BX MOV CX,08 BACK : ROL AL,1 JNC LOC1 INC N_1S LOC1:

LOOP BACK MOV AL,N_1S MOV BYTE PTR 2[DI],AL SUB N_0S,AL MOV AL,N_0S MOV BYTE PTR 3[DI],AL RET FINDP ENDP END

14

9) Program To Find HCF (GCD) Of Two 16-Bit Unsigned Integers. .MODEL SMALL .DATA X Y Z .CODE

DW DW DW

50 04 ?

MOV MOV

AX,@DATA DS,AX

MOV MOV CMP JAE

AX,X BX,Y AX,BX PROCEED

LOC2:

XCHG

AX,BX

PROCEED:

MOV DIV CMP MOV JNZ MOV

DX,0 BX DX,0 AX,DX LOC2 Z,BX

MOV INT END

AH,4CH 21H

;DATA FILE: ; ; ;

L G DW Z L1 Q

;Both X And Y Are Unsigned Integers

15

10) Program To Find LCM Of Two 16-Bit Unsigned Integers .MODEL SMALL .DATA X DW 50 Y DW 04 Z DW 2 DUP(?) .CODE MOV AX,@DATA MOV DS,AX

LOC2:

LOC1:

MOV AX,X MOV BX,AX MOV DX,0

;first no in AX ;first no in BX ;divide DX:AX/Y = first no/second no

PUSH AX PUSH DX DIV Y CMP DX,0 POP DX POP AX JE LOC1 ADD AX,BX ADC DX,0 JMP LOC2

;LS-word of LCM ;MS-word of LCM

MOV Z,AX MOV Z+2,DX MOV AH,4CH INT 21H ALIGN 16 END

;DATA FILE: ; ; ;

L G DD Z L1 Q

;if exactly divisible,AX=LCM ;AX
View more...

Comments

Copyright ©2017 KUPDF Inc.
SUPPORT KUPDF