UNIT-2

1.  Write an ALP to add two 8-bit numbers

Data segment

Num-1 DB 56H

Num-2 DB 23H

Result DB (?)

Data Ends

Code Segment

Assume CS: Code, DS: Data

Start: MOV AX, Data

MOV DS, AX

MOV AL, Num-1

MOV BL, Num-2

ADD AL, BL

MOV Result, AL

MOV AH, 4CH

INT 21H

Code Ends

End Start

2.  Write an ALP to add a constant to series of numbers in a list:

Data Segment

List DB 05, 23, 45,78,45,03

Data Ends

Code Segment

Assume CS: Code, Ds: Data

Start: MOV Ax, data

MOV Ds, Ax

LES BX, List

MOC CL, [BX]

LOOP: INC BX

ADD [BX], 10H

DEC CL

JNZ LOOP

Code Ends

End Start

3.  Write an ALP to display message on screen

Data Segment

Msg DB ‘MICROPRCESSORS $’

Data Ends

Code Segment

Assume CS: Code, DS: Data

Start: MOV AX, Data

MOV DS, AX

MOV AH, 09H

MOV DX, OFFSET Msg

INT 21H

MOV AH, 4CH

INT 21H

Code Ends

End Start

4.  Write an ALP to find no of +ve & -ve numbers from a given series of signed numbers

Data Segment

List DW 1234, 4567, 8976, 1238, 8975,

Count EQU 05h

Data Ends

Code Segment

Assume CS: Code, DS: Data

Start: MOV AX, Data

MOV DS, AX

XOR BX, BX

XOR DX, DX

MOV CL, Count

MOV SI, OFFSET List

AGAIN: MOV AX, [SI]

SHL AX, 01H

JC NEG

INC BX

JMP NEXT

NEG: INC DX

NEXT: ADD SI, 02H

DEC CL

JNZ AGAIN

MOV AH, 4CH

INT 21H

Code Ends

End Start

5.  Write an ALP to find no of Even & Odd numbers from a given series of signed numbers

Data Segment

List DW 1234, 4567, 8976, 1238, 8975,

Count EQU 05h

Data Ends

Code Segment

Assume CS: Code, DS: Data

Start: MOV AX, Data

MOV DS, AX

XOR BX, BX

XOR DX, DX

MOV CL, Count

MOV SI, OFFSET List

AGAIN: MOV AX, [SI]

ROR AX, 01H

JC ODD

INC BX

JMP NEXT

ODD: INC DX

NEXT: ADD SI, 02H

DEC CL

JNZ AGAIN

MOV AH, 4CH

INT 21H

Code Ends

End Start

6.  Write an ALP to find sum of series of numbers

Data Segment

Count Equ 05H

Num_List DB 01, 02, 03, 04, 05

Result DB (?)

Data Ends

Code Segment

Assume CS: Code, DS: Data

Start: MOV AX, Data

MOV DS, AX

MOV CL, Count

XOR AX, AX

MOV SI.OFFSET NUM_LIST

GO: MOV BX, [SI]

ADD AX, BX

INC SI

DEC CL

JNZ GO

MOV DI, OFFSET RESULT

MOV [DI], AX

MOV AH, 4CH

INT 21H

Code Ends

End Start

7.  Write an ALP to move string of data from 2000H to 3000H length of the string is 0AH

Data Segment

Source Equ 2000H

Dest Equ 3000H

Count Equ 0AH

Data Ends

Code Segment

Assume CS: Code, DS: Data

Start: MOV AX, Data

MOV DS, AX

MOV SI, OFFSET Source

MOV DI, OFFSET Dest

MOV CL, Count

REP MOV SW

MOV AH, 4CH

INT 21H

Code Ends

Ends Start

8.  Write an ALP to move string of data from 2000H to 3000H length of the string is 0AH

Data Segment

Source Equ 2000H

Dest Equ 3000H

Count Equ 0AH

Data Ends

Code Segment

Assume CS: Code, DS: Data

Start: MOV AX, Data

MOV DS, AX

MOV SI, OFFSET Source

MOV DI, OFFSET Dest

MOV CL, Count

BACK: MOV AX, [SI]

MOV [DI], AX

INC SI

INC DI

DEC CL

JNZ BACK

MOV AH, 4CH

INT 21H

Code Ends

Ends Start

9.  Write an ALP to convert given binary number in to gray code

Data Segment

NUM Equ 34H

Result DB (?)

Data Ends

Code Segment

Assume CS: Code, DS: Data

Start: MOV AX, Data

MOV DS, AX

MOV AX, NUM

MOV BX, AX

RCR AX, 01H

XOR BX, AX

MOV Result, BX

MOV AH, 4CH

INT 21H

Code Ends

End Start

10.  Write an ALP to perform one byte BCD addition

Data Segment

Num-1 Equ 92H

Num-2 Equ 52H

RESULT DB 02 DUP (0)

Data Ends

Code Segment

Assume CS: Code, Ds: Data

Start: MOV AX, Data

MOV DS, AX

MOV BL, NuM-1

MOV AL, Num-2

ADD AL, BL

DAA

MOV RESULT, AL

JNC GO

INC [RESULT+1]

GO: MOV AH, 4CH

INT 21H

Code Ends

End Start

11.  Write an ALP to find largest number from the given list

Data Segment

LIST DB 52, 56, 89, 55, 23

Count DB 05H

Largest DB (?)

Data Ends

Code Segment

Assume CS: Code, DS: Data

Start: MOV AX, Data

MOV DS, AX

MOV CL, Count

MOV SI, OFFSET LIST

MOV AL, [SI]

AGAIN: CMP AL, [SI+1]

JNL NEXT

MOV AL, [SI+1]

NEXT: INC SI

DEC CL

JNZ AGAIN

MOV SI, OFFSET Largest

MOV [SI], AL

MOV AH, 4CH

INT 21H

Code Ends

End Start

12.  Write an ALP to find square root of given 8-bit number assuming the number is perfect square

Data Segment

NUM Equ 36H

RESULT DB (?)

Assume CS: Code, Ds: Data

Start: MOV AX, Data

MOV DS, AX

MOV CL, NUM

MOV BL, 01H

MOV AL, 00H

UP: CMP CL, 00

JZ GO

SUB CL, BL

INC AL

ADD BL.02H

JMP UP

GO: MOV RESULT, AL

MOV AH, 4CH

INT 21H

Code Ends

End Start

13.  Write an ALP to arrange the given list of numbers in ascending order using bubble sorting

Data Segment

List DB 23, 45, 56, 89, 78

Count EQU 04H

Data Ends

Code Segment

Assume CS: Code, DS: Data

Start: MOV AX, Data

MOV DS, AX

MOV DL, Count-1

AGAIN: MOV CL, DL

MOV SI, OFFSET List

BACK: MOV AL, [SI]

CMP AL, [SI+1]

JL GO

XCHG [SI+1], AL

XCHG [SI], AL

GO: INC SI

LOOP BACK

DEC DL

JNZ AGAIN

MOV AH, 4CH

INT 21H

Code Ends

End Start

14.  Write an ALP to find weather the given data is even or odd parity, if even parity put DL=00H, else put DL=01H, Assuming the given data is multi byte

Data Segment

NUM DD 33 44 88 66H

BYTE_COUNT EQU 04H

Data Ends

Code Segment

Assume CS: Code, DS: Data

Start: MOV AX, Data

MOV DS, AX

MOV DH, BYTE_COUNT

XOR AL, AL

MOV CL, 00H

MOV SI, OFFSET NUM

NXT-BYTE: MOV AL, [SI]

JP EVEN-PARITY

INC CL

EVEN-PARITY: INC SI

MOV AL, 00H

DEC DH

JNZ NXT-BYTE

MOV DL, 00H

RCR CL, 01H

JNC CLEAR

INC DL

CLEAR: MOV AH, 4CH

INT 21H

Code Ends

End Start

15.  Write an ALP to read a character from key board and convert it in to upper case before display it, the program must be needed to terminate by pressing CNTRL+C key

Data Segment

M-1 DB ‘Enter the key: $’

M-2 DB ‘the upper case letter is: $’

Data Ends

Code Segment

Assume CS: Code, DS: Data

Start: MOV AX, Data

MOV DS, AX

MOV AX, 09H

MOV DX, OFFSET M-1

INT 21H

MOV AH, 01H

INT 21H

CMP AL, 61H

JB NO

CMP AL, 7AH

JA NO

AND AL, 5FH ; or AND AL, DFH

NO: MOV DL, AL

MOV AH, 09H

MOV DX, OFFSET M-2

INT 21H

MOV AH, 02H

INT 21H

JMP Start

Code Ends

End Start

16.  Write an ALP to perform addition, Subtraction, multiplication, division on given operands, perform BCD operation for addition & subtraction.

Data Segment

OPR-1 Equ 98H

OPR-2 Equ 49H

SUM DW 01 DUP (00)

DIFF DW 01 DUP (00)

PROD DW 01 DUP (00)

DIV DW 01 DUP (00)

Data Ends

Code Segment

Assume CS: Code, DS: Data

Start: MOV AX, Data

MOV DS, AX

MOV BL, OPR-2

XOR AL, AL

MOV AL, OPR-1

ADD AL, BL

DAA

MOV BYTE_PTR SUM, AL

JNC GO-1

INC [SUM+1]

GO-1: XOR AL, AL

MOV AL, OPR-1

SUB AL, BL

DAS

MOV BYTE_PTR DIFF, AL

JNB GO-2

INC [DIFF+1]

GO-2: XOR AL, AL

MOV AL, OPR-1

MUL BL

MOV WORD_PTR PROD, AX

XOR AX, AX

MOV AL, OPR-1

DIV BL

MOV WORD_PTR DIV, AX

MOV AH, 4CH

INT 21H

Code Segment

End Start

17.  Write an ALP to implement Display string on the monitor.

DATA SEGMENT

MESSAGE DB ' COLLEGE $’

DATA ENDS

CODE SEGMENT

ASSUME CS: CODE, DS: DATA

START: MOV AX, DATA

MOV DS, AX

LEA DX, MESSAGE

MOV AH, 09H

INT 21H

MOV AH, 4CH

INT 21H

CODE ENDS

END START

18.  Write an ALP to implement Move Block of data from one location to another location.

DATA SEGEMENT

COUNT DB 05H

ARRAY DB 45H, 65H, 4BH, 8EH, 0BCH

DEST DB 10 DUP (0)

DATA ENDS

CODE SEGEMENT

ASSUME CS: CODE, DS: DATA, ES: DATA

START: MOV AX, DATA

MOV DS, AX

MOV ES, AX

MOV CL, COUNT

LEA SI, ARRAY

LEA DI, DEST

REP MOVSB

INT 3

CODE ENDS

END START

19.  . Write an ALP to implement String comparison (Pass word checking).

DATA SEGMENT

PASSWORD DB 'WELLCOME'

NEWSTR DB 'WELCOME' / 'WELLCOME'

CNT DB 05H

STR1 DB 'THE GIVEN STRING IS VALID$'

STR2 DB 'THE GIVEN STRING IS INVALID$'

DATA ENDS

CODE SEGMENT

ASSUME CS: CODE, DS: DATA, ES: DATA

START: MOV AX, DATA

MOV DS, AX

MOV ES, AX

MOV CL, CNT

LEA SI, PASSWORD

LEA DI, NEWSTR

REP CMPSB

JNZ L1

LEA DX, STR1

JMP L2

L1: LEA DX, STR2

L2: MOV AH, 09H

INT 21H

INT 3

CODE ENDS

END START

20.  Write an ALP to implement read a character from key board with or without echo.

DATA SEGMENT

MES DB 0AH, 0DH ; for carriage return and line feed

BUFFER DB 0FH DUP (?) ; to store the I/p character string

DATA ENDS

CODE SEGMENT

ASSUME CS: CODE, DS: DATA

START: MOV AX, DATA

MOV DS, AX ; Initialize the DS register

LEA DI, BUFFER ; destination pointer to buffer

MOV AL, 01H ; to read character to AL register

L3: CMP AL, 0DH ; while AL=carriage return, read character

JNE L1 ; when ZF is not set jump to label L1

JMP L2 ; when ZF is set jump to label L2

L1: MOV AH, 01H / 08H ; 01 is read to char. with echo, 08 is without echo

INT 21H ; DOS interrupt service routine

MOV [DI], AL ; move AL to DI register

INC DI ; Incrementing DI

JMP L3

L2: MOV BYTE PTR [DI], '$' ; $ is store end of the character

LEA DX, MES ; display string

MOV AH, 09H ; display string function code

INT 21H ; DOS interrupt service routine

MOV AH, 4CH ; return to dos prompt

INT 21H

CODE ENDS ; end of code segment

END START

21.  Write an ALP to implement Reverse the string.

DATA SEGMENT

MAX EQU 0050H

STR DB MAX DUP (?)

REV DB MAX DUP (?)

DATA ENDS

CODE SEGMENT

ASSUME CS: CODE, DS: DATA

START: MOV AX, DATA

MOV DS, AX

MOV AH, 3FH

MOV BX, 0

MOV CX, MAX

MOV DX, OFFSET STR

INT 21H

AND AX, AX

JZ DONE

MOV CX, AX

PUSH CX

MOV BX, OFFSET STR

MOV SI, OFFSET REV

ADD SI, CX

DEC SI

RS: MOV AL, [BX]

MOV [SI], AL

INC BX

DEC SI

LOOP RS

POP CX

MOV AH, 40H

MOV BX, 1

MOV DX, OFFSET REV

INT 21H ; Print the reverse string

DONE: MOV AH, 4CH ; DOS terminate program function

INT 21H ; Terminate the program

CODE ENDS

END START

22.  Write an ALP to implement BCD to HEX conversion using procedure.

DATA SEGMENT

BCD_INPUT DB 37H

BIN_VALUE DB ?

DATA ENDS

STACK_SEG SEGMENT STACK

DW 100 DUP (0)

DW 100 DUP (0)

TOP_STACK LABEL WORD

STACK_SEG ENDS

CODE SEGMENT

ASSUME CS: CODE, DS: DATA, SS: STACK_SEG

START: MOV AX, DATA

MOV DS, AX ; Initialize DS register

MOV AX, STACK_SEG

MOV SS, AX

MOV SP, OFFSET TOP_STACK

MOV AL, BCD_INPUT ; BCD number in AL register

PUSH AX

CALL BCD_BIN

POP AX

MOV BIN_VALUE, AL ; Store the result

INT 3 ; Return to DOS

BCD_BIN PROC NEAR

PUSH F ; Save registers

PUSH AX

PUSH BX

PUSH CX

PUSH BP

MOV BP, SP

MOV AX, [BP+12]

MOV BL, AL ; Keep copy in BL register

AND BL, 0FH ; Separate upper nibble

AND AL, 0F0H

MOV CL, 04 ; Move upper BCD digit to

ROR AL, CL ; low nibble position for multiply

MOV BH, 0AH ; Load conversion factor in BH

MUL BH ; Multiply upper BCD digit in AL by 0AH

ADD AL, BL ; Add lower BCD digit to mul

MOV [BP+12], AX

POP BP ; Restore registers

POP CX

POP BX

POP AX

POP F

RET

BCD_BIN ENDP

CODE ENDS

END START

23.  Write an ALP to implement HEX to BCD conversion.

DATA SEGMENT

HEX DB 5CH

BCD EQU 00H

DATA ENDS

CODE SEGMENT

ASSUME CS: CODE, DS: DATA

START: MOV AX, DATA ; initialize DS register

MOV DS, AX

MOV AL, HEX ; Bring the input HEX value to AL reg

MOV AH, 00H

MOV BH, 0AH

DIV BH ; divide HEX number with 0AH

MOV CL, 04H

ROL AL, CL ; Rotate Quotient AL 4 times left

ADD AL, AH ; Add reminder to AL

MOV BCD, AL ; Store the BCD result in the location BCD

MOV AH, HEX

INT 3

CODE ENDS

END START

24.  Write an ALP to implement sorting.

SIGNED UNSIGNED

ASCENDING ORDER JLE JBE

DESCENDING ORDER JGE JAE

DATA SEGMENT

ADDR EQU 2500H

DATA ENDS

CODE SEGMENT

ASSUME CS: CODE, DS: DATA

START: MOV AX, DATA

MOV DS, AX ; Initialize DS register

MOV SI, ADDR ; Move address 2500H in to Source Index

MOV BL, [SI] ; BL gives the number of passes

DEC BL ; Decrement BL

L3: MOV CL, [SI] ; CL indicates the number of comparisons

DEC CL ; Decrement count

INC SI

L2: MOV AL, [SI] ; Move the element to AL register

INC SI ; next element

CMP AL, [SI]

JLE L1

XCHG AL, [SI] ; If AL not smaller, then exchange the elements

DEC SI

JNZ L2 ; If BL > 0 the more passes are need

L1: DEC BL

MOV SI, ADDR

JNZ L3

INT 3 ; Breaking Interrupt

CODE ENDS

END START

25.  Write an ALP to implement Factorial using recursive procedure.