Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 12

4.

(Covers Block 4)
(a) Write a program in 8086 assembly Language (with proper
comments) to count the number of alphabets 'a', 'e' and 'o'
(irrespective of lower or upper case) in a strings. For example, in
case the strings is: "ABaDEFeHIO" the count of 'a' will be 2, 'e' is
2 and 'o' is 1. You may assume that string is available in the
memory and is of length 10. Make suitable assumptions, if any.
ANS:
DATA SEGMENT
STR1 DB ABaDEFeHIO
A DB 0H
E DB 0H
O DB 0H
MSG1 DB 10,13,COUNT OF As IS : $
MSG2 DB 10,13,COUNT OF Es IS : $
MSG3 DB 10,13,COUNT OF Os IS : $
DATA ENDS
DISPLAY MACRO MSG
MOV AH,9
LEA DX,MSG
INT 21H
ENDM
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START:
MOV AX,DATA
MOV DS,AX
LEA SI,STR1
MOV CX,10
CHECK:
MOV AL,[SI]
CMP AL,A

JNE N1
INC A
N1:
CMP AL,a
JNE N2
INC A
N2: CMP AL,E
JNE N3
INC E
N3: CMP AL,e
JNE N4
INC E
N4: CMP AL,O
JNE N5
INC O
N5: CMP AL,o
JNE N6
INC O
N6: INC SI
LOOP CHECK
DISPLAY MSG1
MOV DL,A
ADD DL,30H
MOV AH,2
INT 21H
DISPLAY MSG2
MOV DL,E
ADD DL,30H

MOV AH,2
INT 21H
DISPLAY MSG3
MOV DL,O
ADD DL,30H
MOV AH,2
INT 21H
MOV AH,4CH
INT 21H
CODE ENDS
END START
Write a program in 8086 assembly language that accepts a 2 digit input from the keyboard (as
ASCII input) into packed BCD number. The packed BCD number may be stored in memory.

DATA SEGMENT
MSG1 DB ENTER NUMBER : $
DIGIT1 DB ?
DIGIT2 DB ?
BCD DB ?
DATA ENDS
CODE SEGMENT
ASSUME DS:DATA,CS:CODE
START:
MOV AX,DATA
MOV DS,AX
LEA DX,MSG1
MOV AH,9
INT 21H

MOV AH,1
INT 21H
SUB AL,30H
MOV DIGIT1,AL
MOV AH,1
INT 21H
SUB AL,30H
MOV DIGIT2,AL
MOV AH,DIGIT1
MOV AL,DIGIT2
MOV CL,4
ROL AH,CL
ADD AL,AH
MOV BCD,AL
CODE ENDS
END START
Write a simple near procedure in 8086 assembly language that receives an ASCII digit as
parameter. It returns 1 if the ASCII digit is Z else it returns 0. Make suitable assumptions, if
any.
DATA SEGMENT
MSG1 DB ENTER ALPHABET Z : $
MSG2 DB 10,13,BIT RETURNED IS : $
DATA ENDS
CODE SEGMENT
ASSUME DS:DATA,CS:CODE
START:
MOV AX,DATA
MOV DS,AX

LEA DX,MSG1
MOV AH,9
INT 21H
MOV AH,1
INT 21H
MOV BL,AL
LEA DX,MSG2
MOV AH,9
INT 21H
CALL CHECK
ADD DL,30H
MOV AH,2
INT 21H
MOV AH,4CH
INT 21H
CODE ENDS
CHECK PROC NEAR
CMP BL,Z
JNE SKIP
MOV DL,1
JMP DONE
SKIP:
MOV DL,0
DONE:
RET
CHECK ENDP
END START

Write and run an Assembly language program that counts the occurrence of alphabet A
(irrespective of case) in a sting. For example, for the string AXabAYaf, the output will be 4.
You may assume that the string is available in the memory and output is stored in the AL
register.

DATA SEGMENT
STR1 DB AXabAYaf
A DB 0H
MSG1 DB 10,13,COUNT OF As IS : $
DATA ENDS
DISPLAY MACRO MSG
MOV AH,9
LEA DX,MSG
INT 21H
ENDM
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START:
MOV AX,DATA
MOV DS,AX
LEA SI,STR1
MOV CX,10
CHECK:
MOV AL,[SI]
CMP AL,A
JNE N1
INC A
N1:
CMP AL,a
JNE N2
INC A

N2: INC SI
LOOP CHECK
MOV AL,A
DISPLAY MSG1
MOV DL,A
ADD DL,30H
MOV AH,2
INT 21H
MOV AH,4CH
INT 21H
CODE ENDS
END START
Write and run (using appropriate calling program) a near procedure in assembly language
that converts a packed 2 digit BCD number stored in AL register to equivalent Binary number.
For example, if AL contains a packed BCD number 64 as 0110 0100, then the program will
convert this BCD to equivalent binary number 01000000. The binary number should be
returned back in the AL register itself.

DATA SEGMENT
MSG1 DB ENTER NUMBER : $
DIGIT1 DB ?
DIGIT2 DB ?
BINARY DB ?
DATA ENDS
CODE SEGMENT
ASSUME DS:DATA,CS:CODE
START:
MOV AX,DATA
MOV DS,AX

LEA DX,MSG1
MOV AH,9
INT 21H
MOV AH,1
INT 21H
SUB AL,30H
MOV DIGIT1,AL
MOV AH,1
INT 21H
SUB AL,30H
MOV DIGIT2,AL
MOV AH,DIGIT1
MOV AL,DIGIT2
MOV CL,4
ROL AH,CL
ADD AL,AH
CALL CONVERT
MOV BINARY,AL
MOV AH,4CH
INT 21H
CODE ENDS
CONVERT PROC NEAR
MOV AH,0
MOV BL,AL
AND AL,0F0H
AND BL,0FH

MOV CL,04H
ROL AL,CL
MOV CL,10
MUL CL
ADD AL,BL
RET
CONVERT ENDP
END START
Write and run an assembly language program that multiplies two numbers (of size one byte
only) stored in the memory. The result should be output on the computer monitor.

DATA SEGMENT
NUM1 DB ?
NUM2 DB ?
RESULT DB ?
DIGIT1 DB ?
DIGIT2 DB ?
MSG1 DB 10,13,ENTER FIRST 2 DIGIT NUMBER TO MULTIPLY : $
MSG2 DB 10,13,ENTER SECOND 2 DIGIT NUMBER TO MULTIPLY : $
MSG3 DB 10,13,RESULT OF MULTIPLICATION IS : $
RES DB 10 DUP ($)
DATA ENDS
CODE SEGMENT
ASSUME DS:DATA,CS:CODE
START:
MOV AX,DATA
MOV DS,AX

LEA DX,MSG1
MOV AH,9
INT 21H
MOV AH,1
INT 21H
SUB AL,30H
MOV DIGIT1,AL
MOV AH,1
INT 21H
SUB AL,30H
MOV DIGIT2,AL
MOV AH,0
MOV AL,DIGIT1
MOV CL,10
MUL CL
MOV AH,DIGIT2
ADD AL,AH
MOV NUM1,AL
LEA DX,MSG2
MOV AH,9
INT 21H
MOV AH,1
INT 21H
SUB AL,30H
MOV DIGIT1,AL
MOV AH,1
INT 21H

SUB AL,30H
MOV DIGIT2,AL
MOV AH,0
MOV AL,DIGIT1
MOV CL,10
MUL CL
MOV AH,DIGIT2
ADD AL,AH
MOV NUM2,AL
MOV AH,0
MOV BL,NUM1
MUL BL
LEA SI,RES
CALL HEX2DEC
LEA DX,MSG3
MOV AH,9
INT 21H
LEA DX,RES
MOV AH,9
INT 21H
MOV AH,4CH
INT 21H
CODE ENDS

HEX2DEC PROC NEAR


MOV CX,0
MOV BX,10
LOOP1: MOV DX,0
DIV BX
ADD DL,30H
PUSH DX
INC CX
CMP AX,9
JG LOOP1
ADD AL,30H
MOV [SI],AL
LOOP2: POP AX
INC SI
MOV [SI],AL
LOOP LOOP2
RET
HEX2DEC ENDP
END START

You might also like