• No results found

52594869-8086-Programs-semester-4

N/A
N/A
Protected

Academic year: 2021

Share "52594869-8086-Programs-semester-4"

Copied!
40
0
0

Loading.... (view fulltext now)

Full text

(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

(4)

1) Block movement of data (word transfer) without overlap .MODEL SMALL .DATA SOURCE_BLOCK DW 89ABH,0ABCDH,0020H,0F0H,0100H DESTN_BLOCK DW 5 DUP(?) .CODE

MOV AX,@DATA ;Loads DS with upper 16_bits of Data Seg Base MOV DS,AX

LEA SI, SOURCE_BLOCK ;SI is source pointer

LEA DI, DESTN_BLOCK ;DI is destination pointer. MOV CX,05H ;BLOCK LENGTH = 5

LOC1: MOV AX,[SI] MOV [DI],AX

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

INC DI INC DI DEC CX JNZ LOC1

MOV AH,4CH ;DOS INTERRUPT 21H, FUNCTION 4CH,

INT 21H ;Terminates Program And Returns Control To DOS END ;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 ; Position where destination block ends ; within the source block.

DSTN_BLK DB 10-(POS+1) DUP(0) ; To determine starting of ; destination block.

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

MOV AX,@DATA MOV DS,AX

LEA SI,SRC_BLK ;SI Points To Source Block LEA DI,DSTN_BLK ;DI Points To Destination Block MOV CX,10 ;No.of Bytes To Be Transferred=10

LOC1: MOV AL,[SI]

MOV [DI],AL INC SI INC DI

LOOP LOC1

MOV AH,4CH ;INT 21H, Function 4CH

INT 21H ;Terminates Program, Returns Control To DOS END

;DATA FILE : L

; DB SRC_BLK LA ;source block before execution. Length=0aH ; G

; DB DSTN_BLK LA

; DB SRC_BLK LA ;some of the source words are overwritten. ; Q

(Comment: For word transfer with overlap change

All DB to DW and give the corresponding data (0011H,0022H...) Change AL to AX

(6)

.MODEL SMALL .DATA X_BLOCK DW 0123H,3456H,789AH,0BCDEH,0F231H Y_BLOCK DW 1122H,3344H,5566H,7788H,0AABBH .CODE MOV AX,@DATA

MOV DS,AX ;Loads DS with upper 16-bits of Data_Seg Base LEA SI,X_BLOCK ;SI POINTS TO X_BLOCK

LEA DI,Y_BLOCK ;DI POINTS TO Y_BLOCK MOV CX,0005H ;Length Of Block = 5 LOC1: MOV AX,[SI]

MOV BX,[DI] MOV [DI],AX MOV [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 ;Terminates Program, return control to DOS. END ;DATA FILE : L ; DW X_BLOCK L5 ; DW Y_BLOCK L5 ; G ; DW X_BLOCK L5 ; DW Y_BLOCK L5 ; Q

(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 DB 67H,45H,23H,01H,0EFH,0CDH,0ABH,89H ;X=89ABCDEF01234567H Y DB 34H,12H,0F0H,0DEH,0ABH,34H,0BCH,12H ;Y=12BC34ABDEF01234H Z DB 9 DUP(?) ;Result in 9 bytes. .CODE

MOV AX,@DATA MOV DS,AX

LEA SI,X ;SI POINTS TO ADDEND BYTES LEA DI,Y ;DI POINTS TO AUGEND BYTES LEA BX,Z ;BX POINTS TO RESULT BYTES MOV CX,08 ;

CLC

LOC1: MOV AL,[SI] ADC AL,[DI]

MOV [BX],AL ;PARTIAL RESULT INC SI INC DI INC BX DEC CX JNZ LOC1

MOV AL,00 ;CLEAR ACC RCL AL,01

MOV [BX],AL ;FINAL RESULT BYTE. MOV AH,4CH INT 21H END ;DATA FILE : L ; G ; DB X L8 ; DB Y L8 ; DB Z L9 ; Q

(8)

5) MULTIPLICATION OF TWO UNSIGNED 32-BIT NUMBERS .MODEL SMALL .DATA MPD DW 0C432H,765BH MPR DW 3679H,0B397H RES DW 4 DUP(0) .CODE MOV AX,@DATA MOV DS,AX MOV BX,OFFSET MPD MOV AX,[BX] MUL MPR MOV RES,AX MOV RES+2,DX MOV AX,[BX] MUL MPR+2 ADD RES+2,AX ADC RES+4,DX JNC L1 INC RES+6 L1: MOV AX,[BX+2] MUL MPR ADD RES+2,AX ADC RES+4,DX JNC L2 INC RES+6 L2: MOV AX,[BX+2] MUL MPR+2 ADD RES+4,AX ADC 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)

;><MULT32.DAT ;>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 DW 0B347H,7653H,9641H,458BH DIVS DW 0A8H REM DW ?

COUNT EQU DIVS-DIVD QUO DW 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 AX,DX XOR DX,DX INC CX JMP NEXT1 NEXT: DEC SI DEC SI MOV AX,[SI] NEXT1: DIV BX MOV [DI],AX INC DI INC DI DEC CX JNZ NEXT MOV REM,DX MOV AH,4CH INT 21H ALIGN 16 END

(11)

;DATA FILE ;L ;G ;DW DIVD L4 ;DW DIVS L1 ;DW QUO L4 ;DW REM L1 ;Q ;RESULT FILE ;><DIVN.DAT ;>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 DB 0ACH RES DB 3 DUP(0) COUNT DB 0 .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 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 7DH RES DB 4 DUP(?) N_1S DB 00H N_0S DB 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 DW 50 Y DW 04 Z DW ? .CODE MOV AX,@DATA MOV DS,AX MOV AX,X MOV BX,Y CMP AX,BX

JAE PROCEED ;Both X And Y Are Unsigned Integers LOC2: XCHG AX,BX PROCEED: MOV DX,0 DIV BX CMP DX,0 MOV AX,DX JNZ LOC2 MOV Z,BX MOV AH,4CH INT 21H END ;DATA FILE: L ; G ; DW Z L1 ; Q

(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

MOV AX,X ;first no in AX MOV BX,AX ;first no in BX

MOV DX,0 ;divide DX:AX/Y = first no/second no LOC2: PUSH AX ;LS-word of LCM

PUSH DX ;MS-word of LCM DIV Y

CMP DX,0 POP DX POP AX

JE LOC1 ;if exactly divisible,AX=LCM ADD AX,BX ;AX<-AX+first no

ADC DX,0 ;MS-word of LCM JMP LOC2

LOC1: MOV Z,AX MOV Z+2,DX MOV AH,4CH INT 21H ALIGN 16 END ;DATA FILE: L ; G ; DD Z L1 ; Q

(16)

;11) Program To Find Factorial of A Number (Up to Factorial 9) Using Recursion. .MODEL SMALL

.STACK 64 .DATA

NUM DW 3 ;To find Factorial Of 3 RES DW 2 DUP(0) .CODE MOV AX,@DATA MOV DS,AX MOV AX,NUM CALL FACT MOV AH,4CH

INT 21H ;EXIT TO DOS

FACT PROC NEAR CMP AX,01H

JA CONT MOV RES,01

RET ;Instruction Following Call Fact Executed. CONT: PUSH AX ;Store The Num And Its Decremented Values DEC AX ;Until The No. Is 1

CALL FACT ;List The Pushed Addresses And Data In Stack POP AX

MUL RES MOV RES,AX MOV RES+2,DX

RET ;Instruction Following Call Fact Executed Or FACT ENDP ;Return From Subroutine.

END

;DATA FILE: L ; G

; DD RES L1 ; L

; EW NUM 9 ; Enter nos. upto 9 ; G

; DD RES L1 ; Q

(17)

;RESULT FILE ; L

; G

;Program terminated normally (6) ; DD RES L1

;4C71:0010 0000:0006 ; L

; EW NUM 9 ; G

;Program terminated normally (-128) ; DD RES L1

;4C71:0010 0005:8980 ; Q

(18)

;12)Program to find HEX equivalent of the given BCD no.(16-bit) .MODEL SMALL .STACK 200 .DATA BCD_INPUT DB 45H,67H HEX_VALUE DW 0 FACTORS DB 0AH,64H,0E8H,03H NB_SEP DB 10H .CODE MOV AX,@DATA MOV DS,AX

MOV SI,OFFSET BCD_INPUT MOV DI,OFFSET HEX_VALUE CALL BCD_HEX

MOV AH,4CH INT 21H BCD_HEX PROC NEAR

MOV AX,WORD PTR[SI] OR AH,00

JZ BYTE_CONV

MOV BL,AL ;save lower byte of BCD no in BL MOV AL,AH ;get high byte of bcd in AL. MOV AH,0

DIV NB_SEP ;Quotient in AL ,remainder in AH MOV CH,AH ;save ls-nibble in CH

MOV AH,0

MUL WORD PTR FACTORS+2 ;DX:AX contains result MOV WORD PTR HEX_VALUE,AX

MOV AL,CH

MUL FACTORS+1 ;AH:AL CONTAINS RESULT ADD HEX_VALUE,AX

MOV AL,BL MOV AH,0

BYTE_CONV: DIV NB_SEP ;AL-QUOTIENT,AH-REMAINDER

MOV DL,AH ;Unit place can be directly added ;later.

MOV DH,0 ;no need to multiply by 1

MUL FACTORS ;ten's digit in AL *10,RESULT IN ;AH:AL

ADD AX,DX ;add units place and store byte ;equivalent.

ADD HEX_VALUE,AX RET

BCD_HEX ENDP END

(19)

;DATA FILE ;L ;G ;DW BCD_INPUT L1 ;DW HEX_VALUE L1 ;Q ;RESULT FILE ;L ;G

;Program terminated normally (45) ;DW BCD_INPUT L1

;4C75:0000 6745 ;DW HEX_VALUE L1 ;4C75:0002 1A59 ;Q

(20)

;13)Program to find BCD equivalent of the given HEX no.(16-bit) .MODEL SMALL .STACK 200H .DATA HEX_NO DW 0AB89H BCD_EQU DB 5 DUP(0) DIVISOR_1 DW 2710H ;10000 in decimal DIVISOR_2 DW 03E8H ;1000 in decimal DIVISOR_3 DB 64H ;100 in decimal DIVISOR_4 DB 0AH ;10 in decimal MSG DB 'THE EQUIVALENT BCD NO IS : $' CRLF DB 0DH,0AH,'$' .CODE MOV AX,@DATA MOV DS,AX MOV AX,HEX_NO XOR DX,DX ;clear DX DIV DIVISOR_1

PUSH AX ;AX=quotient(contains MS digit) MOV AX,DX

XOR DX,DX DIV DIVISOR_2

PUSH AX ;II most significant decimal digit MOV AX,DX

DIV DIVISOR_3 PUSH AX

MOV CL,8

SHR AX,CL ;AH=remainder,shift it to AL for DIV DIVISOR_4 ;next division

XCHG AL,AH

MOV WORD PTR BCD_EQU,AX ;lowest 2 digits POP AX

MOV BL,AL ;decimal digits to be packed POP AX

MOV CL,8 SHL AX,CL MOV AL,BL

MOV WORD PTR BCD_EQU+2,AX POP AX MOV BCD_EQU+4,AL MOV AH,9 MOV DX,OFFSET MSG INT 21H CALL DISPLAY MOV AH,4CH INT 21H DISPLAY PROC NEAR MOV CX,5 MOV DI,4

(21)

NEXT: MOV DL,[BX+DI] OR DL,30H MOV AH,2 INT 21H DEC DI LOOP NEXT MOV AH,9 MOV DX,OFFSET CRLF INT 21H RET DISPLAY ENDP END ;DATA FILE: L ; G ; L ; EW HEX_NO FFFF ; G ;RESULTS ON SCREEN. ;Q

(22)

;14) Program To Find Square and Cube of a given number .MODEL SMALL .DATA NUM DW 2535H,0A535H SQU DW 4 DUP(0) CUBE DW 6 DUP(0) MPLIER DW 2 DUP(0) .CODE MOV AX,@DATA MOV DS,AX MOV AX,NUM MOV MPLIER,AX MOV AX,NUM+2 MOV MPLIER+2,AX CALL FIND_SQ CALL FINDCUB MOV AH,4CH INT 21H FIND_SQ PROC NEAR

MOV BX,OFFSET NUM MOV AX,[BX]

MUL MPLIER ;LS WORD OF MPAND x LS WORD OF MPER MOV SQU,AX ;RESULT IN DX:AX

MOV SQU+2,DX

MOV AX,[BX] ;LS WORD OF MPAND x MS WORD OF MPER MUL MPLIER+2

ADD SQU+2,AX ADC SQU+4,DX JNC MSLSX INC SQU+6

MSLSX: MOV AX,[BX+2] ;MS WORD OF MPAND x LS WORD OF MPER MUL MPLIER

ADD SQU+2,AX ADC SQU+4,DX JNC MSMSX INC SQU+6

MSMSX: MOV AX,[BX+2] ;MS WORD OF MPAND x MS WORD OF MPER MUL MPLIER+2

ADD SQU+4,AX

ADC SQU+6,DX ;FINAL CARRY INTO 65TH BIT IGNORED. RET

FIND_SQ ENDP FINDCUB PROC NEAR MOV DI,0 CALL CUB MOV DI,2 CALL CUB RET FINDCUB ENDP

(23)

CUB PROC NEAR CLC

MOV AX,NUM[DI]

MUL SQU ;DX:AX CONTAINS RESULT ADD CUBE[DI],AX

ADC CUBE[DI+2],DX JNC NEXT

INC CUBE[DI+4] NEXT: MOV AX,NUM[DI] MUL SQU+2

ADD CUBE[DI+2],AX ADC CUBE[DI+4],DX JNC NEXT1

INC CUBE[DI+6] NEXT1: MOV AX,NUM[DI] MUL SQU+4

ADD CUBE[DI+4],AX ADC CUBE[DI+6],DX JNC NEXT2

INC CUBE[DI+8] NEXT2: MOV AX,NUM[DI] MUL SQU+6 ADD CUBE[DI+6],AX ADC CUBE[DI+8],DX RET CUB ENDP END ;DATAFILE: L ; G ; DD NUM L1 ; DW SQU L4 ; DW CUBE L6 ; Q

(24)

;15 & 16)Program to add and subtract two strings of ASCII digits. Result is a string of BCD .MODEL SMALL .DATA ASC_STR1 DB '0354' ASC_STR2 DB '9375'

SSIZE EQU ASCSTR2-ASCSTR1-1 ADD_RES DB SSIZE+2 DUP(0) SUB_RES DB SSIZE+2 DUP(0) .CODE

MOV AX,@DATA MOV DS,AX MOV AL,'5'

MOV AH,06 ;AH contains unpacked BCD nos. from(0 to 9) ADD AL,'9'

AAA ;AL contains result which is to be adjusted ;AL=04H ,AH=07H,AX=O704H

MOV AL,'5' MOV AH,06H

SUB AL,'9' ;AL=05H, AH=06H AX=0506H AAS

MOV SI,OFFSET ASCSTR1+SSIZE MOV DI,OFFSET ASCSTR2+SSIZE PUSH SI

PUSH DI ;save SI & DI for subtraction MOV CX,SSIZE+1

MOV BX,OFFSET ADD_RES MOV BP,OFFSET SUB_RES

XOR AH,AH ;CLEAR CARRY, AH=BCD NO 0 BACK1: MOV AL,[SI]

ADC AL,[DI] AAA MOV [BX],AL DEC SI DEC DI INC BX LOOP BACK1 MOV AH,00 RCL AH,1

MOV [BX],AH ;Final carry stored POP DI

POP SI

MOV CX,SSIZE+1 XOR AH,AH

BACK2: MOV AL,[SI] ;for the above example BCD result SBB AL,[DI] ;is negative . Take 10's complement AAS ;and attatch -ve sign to the magnitude MOV DS:[BP],AL

(25)

DEC DI INC BP LOOP BACK2 MOV AH,4CH INT 21H ALIGN 16 END ;DATA FILE: L ; G ; DB ADD_RES L5 ; DB SUB_RES L4

; Q ;Enter different data and ;record result

(26)

;17) Program to multiply ASCII string by a ASCII digit. Result is adjusted and stored in a BCD string .MODEL SMALL .DATA ASCII_STR DB '058343' MPLIER DB '6'

SSIZE EQU MPLIER-ASCIISTR-1

BCDSTR DB SSIZE+2 DUP(0) ;Get The Next Digit .CODE

MOV AX,@DATA MOV DS,AX MOV AL,07H MOV BL,09H

MUL BL ;Multiplication performed with two AAM ;unpacked BCD nos.

;adjust result in AL register MOV DI,OFFSET BCDSTR

MOV SI,OFFSET ASCIISTR+SSIZE MOV DL,MPLIER

AND DL,0FH MOV CX,SSIZE+1 NEXT: MOV AL,[SI] DEC SI AND AL,0FH MUL DL AAM ADD AL,[DI] AAA MOV [DI],AL INC DI MOV [DI],AH LOOP NEXT MOV AH,4CH INT 21H END ;DATA FILE: L ; G ; DB ASCIISTR L6 ; DB MPLIER L1 ; DB BCDSTR L7

; Q ;ENTER OTHER ASCII nos,multiply, ;verify results,in CV itself.

(27)

;18) Program to divide a string of ASCII digits by a single ASCII digit. Result is a string of BCD digits. .MODEL SMALL .DATA ASC_DIVIDEND DB '7658974' ASC_DIVISOR DB '5'

SSIZE EQU ASC_DIVISOR-ASC_DIVIDEND-1 BCD_RES DB SSIZE+1 DUP(0)

REMAINDER DB 0 .CODE MOV AX,@DATA MOV DS,AX MOV DL,ASC_DIVISOR AND DL,0FH XOR AH,AH LEA SI,ASC_DIVIDEND LEA DI,BCD_RES MOV CX,SSIZE+1 NEXT: MOV AL,[SI] INC SI AND AL,0FH AAD DIV DL MOV [DI],AL INC DI DEC CX JNZ NEXT

MOV BYTE PTR[DI],'$' ;Indicate End Of Result Quotient MOV REMAINDER,AH MOV AH,4CH INT 21H ALIGN 16 END ;DATA FILE: L ; G ; DB ASC_DIVIDEND L7 ; DB ASC_DIVISOR L1 ; DB BCD_RES L7 ; DB REMAINDER,L1 ; Q

(28)

19) Program To Transfer String .MODEL SMALL

.DATA

STR1 DB 'WE ARE IN MID SEMESTER$' STR2 DB (STR2-STR1) DUP(0)

COUNT DW (STR2-STR1)

STR3 DB 'STRING PRIMITIVE INSTRUCTIONS ARE VERY USEFUL$' STR4 DB (STR4-STR3) DUP(0)

COUNT2 DW (STR4-STR3)

WORDSTR5 DW 5678H,0ABCDH,0CEFDH,0D536H,5555H,0AAAAH,0FFFFH WORDSTR6 DW (WORDSTR6-WORDSTR5) DUP(0)

COUNT1 DW (WORDSTR6-WORDSTR5)/2 .CODE MOV AX,@DATA MOV DS,AX MOV ES,AX MOV CX,COUNT LEA SI,STR1 LEA DI,STR2 CLD BACK: LODSB STOSB LOOP BACK LEA SI,STR3 LEA DI,STR4 CLD MOV CX,COUNT2

REP MOVSB ;INSTEAD OF LODSB AND STOSB, MOVSB CAN BE USED LEA DI,WORDSTR6

MOV SI,OFFSET WORDSTR5 MOV CX,COUNT1 REP MOVSW MOV AH,4CH INT 21H ALIGN 16 END ;DATAFILE: L ; G ; DB STR1 LCOUNT ; DB STR2 LCOUNT ; DB STR3 LCOUNT2 ; DB STR4 LCOUNT2 ; DW WORDSTR5 LCOUNT1 ; DW WORDSTR6 LCOUNT1 ; Q

(29)

20) PROGRAM TO REVERSING A STRING, CHECK WHETHER THE GIVEN STRING IS A PALINDROME .MODEL SMALL

.DATA

STR1 DB 'WE ARE HAVING GNIVAH ERA EW.' CRLF DB 0DH,0AH,'$'

LEN EQU CRLF-STR1 STR2 DB LEN DUP(?),'$'

MSG_PAL DB 0DH,0AH,'THE STRING IS PALINDROM$'

MSG_NOTPAL DB 0DH,0AH,'THE STRING IS NOT A PALINDROM$' .CODE

MOV AX,@DATA MOV DS,AX MOV ES,AX LEA SI,STR1

LEA DI,STR2+LEN-1 ;STRING REVERSED POINTED BY DI MOV CX,LEN

MOV BX,DI CLD

NEXT: LODSB ;reverse the string STOSB DEC BX MOV DI,BX LOOP NEXT MOV AH,9 MOV DX,OFFSET STR1 INT 21H

MOV DX,OFFSET STR2 ;AH=9 ALREADY. INT 21H

MOV SI,OFFSET STR1 ;REVERSED STRING SHOULD MATCH

MOV DI,OFFSET STR2 ;WITH ORIGINAL STRING FOR A PALINDROME MOV CX,LEN-1

CLD

REPE CMPSB ;REPEAT UNTIL CX=0 AND IF BYTES ARE EQUAL JZ PAL ;IF Z=1,whether CX=0 or not,strings match MOV AH,9

LEA DX,MSG_NOTPAL;Z=0 NO MATCH INT 21H

JMP EXIT PAL: MOV AH,9

LEA DX,MSG_PAL INT 21H

EXIT: MOV AH,4CH INT 21H ALIGN 16 END

(30)

21) program to sort an array of unsigned words using Bubble Sort. .MODEL SMALL .DATA X DW 3598H,5793H,79ABH,0BCDEH,77H,35H,01,0BC34H,0C456H,1234H,9238H Y DW (Y-X)/2 ASC_TABLE DB '0123456789ABCDEF' NB_SEP DB 10H CRLF DB 0DH,0AH,'$' .CODE MOV AX,@DATA MOV DS,AX

NEXT_PASS:LEA SI,X ;SI TO POINT TO THE ARRAY MOV CX,Y ;COUNT IN Y

DEC CX

MOV BL,00 ;EXCHANGE FLAG IN BL LOC2: MOV AX,[SI] ;READ WORD ELEMENT

CMP AX,[SI+2] ;COMPARED WITH THE NEXT HIGHER ELEMENT

JBE LOC1 ;IF PREVIOUS NO.=<PRESENT NO.,ALREADY IN ASCENDIG ORDERNG

XCHG AX,[SI+2] ;ELSE EXCHANGE WORDS XCHG AX,[SI]

MOV BL,0FFH ;EXCHANGE FLAG BYTE = FFH

LOC1: INC SI INC SI DEC CX

JNZ LOC2 ;IF CURRENT PASS NOT OVER,GOTO LOC2

CMP BL,00H ;AFTER A PASS IS OVER,SEE WHETHER EXCHANGE WAS DONE IN THE PAST

JNE NEXT_PASS CALL DISPLAY MOV AH,4CH INT 21H ALIGN 16 DISPLAY PROC NEAR LEA BP,X MOV CX,Y

LOC: MOV AX,DS:[BP] PUSH AX XCHG AH,AL CALL DISP POP AX CALL DISP INC BP INC BP

MOV DL,20H ;ASCII FOR SPACE MOV AH,2

(31)

LOOP LOC MOV AH,9 MOV DX,OFFSET CRLF INT 21H RET DISPLAY ENDP

DISP PROC NEAR ;HEX DATA AL IS DISPLAYED ON SCREEN. MOV BX,OFFSET ASC_TABLE

MOV AH,0 PUSH CX

DIV NB_SEP ;TO SEPARATE NIBBLES MOV CL,AH XLAT MOV AH,2 MOV DL,AL INT 21H MOV AL,CL XLAT MOV DL,AL MOV AH,2 INT 21H POP CX RET DISP ENDP END ;DATAFILE: L ; DW X LB ; G ; DW X LB ; Q

(32)

22) Program to sort an array of unsigned words using INSERTION SORT - ascending order. .MODEL SMALL .DATA X DW 0F321H,3592H,16H,55H,0AAH,13AH,9BH,35H,01H,0FFH Y DW Y-X ASC_TABLE DB '0123456789ABCDEF' NB_SEP DB 10H CRLF DB 0DH,0AH,'$' .CODE MOV AX,@DATA MOV DS,AX

MOV CX,2 ;IN THE FIRST PASS SORT 2 ELEMENTS LOC3: MOV SI,CX ;ONE OF THE ELEMENT IN SI

LOC2: MOV AX,X[SI] ;GET AN ELEMENT IN AX

CMP AX,X[SI-2] ;COMPARE WITH PREVIOUS ELEMENT

JAE LOC1 ;UNSIGNED COMPARISION,IF ABOVE IS EQUAL ALREADY SORTED

XCHG AX,X[SI-2] XCHG AX,X[SI] LOC1: SUB SI,2 JNZ LOC2 ADD CX,2 CMP CX,Y JNE LOC3 CALL DISPLAY MOV AH,4CH INT 21H ALIGN 16

DISPLAY PROC NEAR LEA BP,X MOV CX,Y SHR CX,1

LOC: MOV AX,DS:[BP] PUSH AX XCHG AH,AL CALL DISP POP AX CALL DISP INC BP INC BP

MOV DL,20H ;ASCII FOR SPACE MOV AH,2

INT 21H LOOP LOC MOV AH,9

(33)

MOV DX,OFFSET CRLF INT 21H

RET DISPLAY ENDP

DISP PROC NEAR ;HEX DATA AL IS DISPLAYED ON SCREEN. MOV BX,OFFSET ASC_TABLE

MOV AH,0 PUSH CX

DIV NB_SEP ;TO SEPARATE NIBBLES MOV CL,AH XLAT MOV AH,2 MOV DL,AL INT 21H MOV AL,CL XLAT MOV DL,AL MOV AH,2 INT 21H POP CX RET DISP ENDP END ;DATAFILE: L ; DW X LA ; G ; DW X LA ; Q

(34)

23) PROGRAM TO FIND LARGEST & SMALLEST 16-BIT SIGNED NUMBERS IN A SEQUENCE OF 10 WORDS

.MODEL SMALL .DATA

ARRAY DW 0ABCH,34H,0FFFFH,7867H,2342H,1243H,2455H,5463H,0BC12H,0FFBCH L_POS DW ? ;TO HOLD POSITION OF LARGEST NO.

LARGEST DW ? ;TO HOLD THE LARGEST VALUE

S_POS DW ? ;TO HOLD POSITION OF SMALLEST NO. SMALLEST DW ? ;TO HOLD SMALLEST VALUE

COUNT EQU 0AH .CODE MOV AX,@DATA MOV DS,AX MOV ES,AX

MOV SI,OFFSET ARRAY ;SI TO POINT TO X MOV BP,SI

MOV CX,COUNT-1 ;CX TO HOLD COUNT

MOV BX,[SI] ;LARGEST NUMBER IN BX REG

MOV DI,BX ;SMALLEST NUMBER IN DI REG. INC SI

INC SI

MOV DX,SI ;DX TO CONTAIN OFFSET ADDR OF THE LOC WITH MAX NO. LOOP1: MOV AX,[SI]

CMP BX,AX JGE PTR_UPD

MOV BX,AX ;NEW MAX IN BX

MOV DX,SI ;SAVE OFFSET LOC OF MAX NO. PTR_UPD:CMP DI,AX JL CONT MOV DI,AX MOV S_POS,SI CONT: INC SI INC SI LOOP LOOP1 MOV LARGEST,BX MOV SMALLEST,DI SUB DX,BP SHR DX,1 MOV L_POS,DX SUB S_POS,BP SHR S_POS,1 MOV AH,4CH INT 21H END

(35)

;DATA FILE: L

; DW ARRAY LA ;ARRAY POSITIONS FROM 0 TO 9. ; G ; DW LARGEST L1 ; DW L_POS L1 ; DW SMALLEST L1 ; DW S_POS L1 ; Q

(36)

24) PROGRAM TO SEARCH THE OCCURENCE OF A CHARACTER IN THE GIVEN STRING .MODEL SMALL

.DATA

STR DB 80H,?,7DH DUP(0)

SEARCH_CHAR DB '?' ;TAKE FROM KEYBOARD LEN EQU SEARCH_CHAR-STR

POS DW ?

MSG DB'TYPE IN A SENTENCE,CR,then CHAR TO BE SEARCHED',0DH,0AH,'$ MSG1 DB 0DH,0AH,'SEARCH SUCCESSFUL $'

MSG2 DB 0DH,0AH,'SEARCH NOT SUCCESSFUL$' CRLF DB 0DH,0AH,'$'

.CODE

MOV AX,@DATA MOV DS,AX MOV ES,AX

MOV AH,9 ;Display string;dos function 09H. MOV DX,OFFSET MSG ;DS:DX points to char string INT 21H

MOV AH,0AH ;BUFFERED KB i/p-dos function 0AH. MOV DX,OFFSET STR ;DS:DX points to INPUT BUFFER where INT 21H ;I BYTE-SIZE OF BUFFER-i/p to function. ;II BYTE-NO OF CHAR-o/p of function LEA DI,STR+2 ;ES:DI points to start of string MOV CX,LEN-2 ;LENGTH OF STRING in CX.

MOV AH,9 ;Use fn 9 to get new line,1st position MOV DX,OFFSET CRLF

INT 21H

MOV AH,01H ;Keyboard input,function 01H INT 21H ;o/p of fn. is KB CHAR IN AL MOV SEARCH_CHAR,AL ;which is the char to be searched. REPNE SCASB ;repeat if compared bytes not equal JZ GET_POS

MOV AH,9 ;search not successful. MOV DX,OFFSET MSG2

INT 21H JMP EXIT

GET_POS:SUB DI, OFFSET STR+2 ;search successful,give position. MOV POS,DI

MOV AH,9

MOV DX,OFFSET MSG1 INT 21H

CALL POSDISP EXIT: MOV AH,4CH INT 21H

(37)

POSDISP PROC NEAR

MOV AL,BYTE PTR POS ; positions upto FFH given. AND AL,0F0H

MOV CL,04H ROL AL,CL CALL ASC_DSP

MOV AL,BYTE PTR POS AND AL,0FH CALL ASC_DSP RET ASC_DSP PROC CMP AL,0AH JB LOCX ADD AL,7 LOCX: ADD AL,'0' MOV DL,AL MOV AH,2 INT 21H RET ASC_DSP ENDP POSDISP ENDP END

(38)

LAB EXAM QUESTIONS - MICROPROCESSOR - SEM IV

1. a) Write an ALP to interchange a block of N-bytes / words.

b) Write an ALP to reverse a string and check whether the given

string is a palindrome or not.

2. a) Write an ALP to transfer a block of N word from source block to

the destination block, without overlap.

b) Write an ALP to find the LCM of two 16-bit unsigned integers.

3. a) Write an ALP to transfer a block of N word from source block to

the destination block, with overlap.( Destination block ending on 6

th

byte position of the source block. )

b) Write an ALP to find the HCF of two 16-bit unsigned numbers.

4. a) Write an ALP to add the two given N-bit multi precision numbers

{N

32 bits}.

b) Write an ALP to transfer the given string data to the destination

using string primitive instructions.

5. a) Write an ALP to multiply two 32-bits unsigned hexadecimal

numbers.

b) Write an ALP to interchange a block of N-bytes / words.

6. a) Write an ALP to divide an unsigned N-bit hexadecimal number by

an unsigned Hexadecimal byte (N to be specified > 16bits).

b) Write an ALP to transfer a block of N word from source block to

the destination block, without overlap.

7. a) Write an ALP to check whether the given 8-bit data is

i. 2 out of 5 code.

(39)

b) Write an ALP to multiply a string of ASCII digits by a single

ASCII digit.

8.

a) Write an ALP to find the factorial of a number N (N

9), using

recursion.

b) Write an ALP to transfer the given string data to the destination

using string primitive instructions.

9. a) Write an ALP to convert 16-bit BCD number to its Hexadecimal

equivalent.

b) Write an ALP to interchange a block of N-bytes / words

10. a) Write an ALP to convert a given 16-bit Hexadecimal number to its

BCD equivalent. Display the result.

b) Write an ALP to transfer a block of N word from source block to

the destination block, without overlap.

11. a) Write an ALP to add & subtract two strings of ASCII digits.

(Length to be specified).

b) Write an ALP to check whether the given 8-bit data is

i.

Positive or Negative.

ii.

Odd or even.

iii.

Find the logical 1’s and 0’s in the given data

12. a) Write an ALP to multiply a string of ASCII digits by a single

ASCII digit.

b) Write an ALP to subtract the two given N-bit multi precision

numbers {N

32 bits}.

13. a) Write an ALP to divide a string of ASCII digits by a single ASCII

digit.

b) Write an ALP to transfer a block of N word from source block to

the destination block, without overlap.

(40)

14. a) Write an ALP to sort the given set of 16-bit unsigned integers in

ascending/descending order using Bubble sort algorithm.

b) Write an ALP to add the two given N-bit multi precision numbers

{N

32 bits}.

15. a) Write an ALP to sort the given set of 16-bit unsigned integers in

ascending/descending order using Insertion sort algorithm.

b) Write an ALP to interchange a block of N-bytes / words.

16. a) Write an ALP to find the largest and smallest element in an array of

16-bit signed / unsigned integers. Also display their positions. (Array

size to be specified).

b) Write an ALP to add & subtract two strings of ASCII digits.

(Length to be specified).

17. a) 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

c. Reading a character from keyboard

d. Reading a string using buffered keyboard input.

b) Write an ALP to add the two given N-bit multi precision numbers

{N

32 bits}.

References

Related documents

To ensure the archiving process the documents shall be validated (e.g. validation of the process of conversion from native into STEP format or other data migration), a

(b) in the directors’ opinion, the attached financial statements and notes thereto are in accordance with the Corporations Act 2001, including compliance with accounting standards

While Merrill Lynch research found that roughly half the women taking the IPA wanted to make regular changes to their investment approach—like identifying how to protect investment

Helpful information for converting ASCII decimal hexadecimal octal and binary values can be referenced in world table Table.. The conversion routines emulating

Since some agents hold bank notes and some agents hold no assets in such a steady state equilibrium, then when the holder of a bank note redeems that note in the banking sector, he

Create a Structure From a File: Consider the following data set ( studentData.txt ) Tom,Jones,57 Bill,Uehling,100 Mary,Honda,95 Kathy,Murigami,67 Bill,Jones,99

char* name - pointer to null-terminated ASCII character string with parameter name char* text - pointer to null-terminated ASCII character string with parameter text int

cfwBufferStatInformation.2560.3 : OCTET STRING− (ascii): maximum number of allocated 2560 byte