Write a program in 8086 assembly Language that accepts a string of four characters entered using the keyboard and checks if all the entered characters are decimal digits. In case all the characters are decimal digits then it converts the entered string into equivalent binary number. – IGNOU MCA Assignment 2016 – 17

By | October 22, 2016

MASTER OF COMPUTER APPLICATIONS

Course Code : MCSL-012
Course Title : Computer Organisation and Assembly Language Programming
Assignment Number : MCA(1)/012/Assignment/16-17
Maximum Marks : 50
Weightage : 25%

 

Write a program in 8086 assembly Language that accepts a string of four characters entered using the keyboard and checks if all the entered characters are decimal digits. In case all the characters are decimal digits then it converts the entered string into equivalent binary number. - IGNOU MCA Assignment 2016 – 17

Code:- 

DATA SEGMENT
MSG1 DB 10,13,’ENTER NUMBER HERE :- $’
MSG2 DB 10,13,’ENTERED VALUE IS : $’
MSG3 DB 10,13,’ENTERED VALUE IS NOT A NUMBER ! $’
MSG4 DB 10,13,’ENTERED VALUE NOT A 4 DIGIT VALUE ! $’
MSG5 DB 10,13,’ENTER NUMBER IN BINARY IS :- $’

FLAG DB 0H
NUM  DW ?
RES  DB 20 DUP (‘$’)

P1 LABEL BYTE
M1 DB 0FFH
L1 DB ?
P11 DB 0FFH DUP (‘$’)

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

DISPLAY MSG1

LEA DX,P1
MOV AH,0AH
INT 21H

DISPLAY MSG2
DISPLAY P11

CHECK1: CMP L1,04H
JNE NOT4D

LEA SI,P11
MOV CH,0
MOV CL,L1
DEC CL

CHECK2:
CMP [SI],30H
JB INCFLAG
CMP [SI],3AH
JB NOINC
INCFLAG:
INC FLAG
NOINC:

INC SI
LOOP CHECK2

CHECK3: CMP FLAG,0H
JNE NOTNUM

CONV:
LEA SI,P11

MOV AX,0H
MOV AL,[SI]
SUB AL,30H
MOV DX,1000
MUL DX

MOV NUM,AX
INC SI

MOV AX,0H
MOV AL,[SI]
SUB AL,30H
MOV DL,100
MUL DL

ADD NUM,AX
INC SI

MOV AX,0H
MOV AL,[SI]
SUB AL,30H
MOV DL,10
MUL DL

ADD NUM,AX
INC SI

MOV AX,0H
MOV AL,[SI]
SUB AL,30H

ADD NUM,AX
INC SI

MOV AX,NUM

LEA SI,RES
CALL HEX2BIN

DISPLAY MSG5

LEA DX,RES
MOV AH,9
INT 21H

JMP DONE
NOTNUM:
DISPLAY MSG3
JMP DONE

NOT4D:
DISPLAY MSG4

DONE:

MOV AH,4CH
INT 21H
CODE ENDS

HEX2BIN PROC NEAR
MOV CX,0
MOV BX,2

LOOP1: MOV DX,0
DIV BX
ADD DL,30H
PUSH DX
INC CX
CMP AX,1
JG LOOP1

ADD AL,30H
MOV [SI],AL

LOOP2: POP AX
INC SI
MOV [SI],AL
LOOP LOOP2
RET
HEX2BIN ENDP

END START

DATA SEGMENT
MSG1 DB 10,13,'ENTER NUMBER HERE :- $'
MSG2 DB 10,13,'ENTERED VALUE IS : $'
MSG3 DB 10,13,'ENTERED VALUE IS NOT A NUMBER ! $'
MSG4 DB 10,13,'ENTERED VALUE NOT A 4 DIGIT VALUE ! $'
MSG5 DB 10,13,'ENTER NUMBER IN BINARY IS :- $'
FLAG DB 0H
NUM  DW ?
RES  DB 20 DUP ('$')
P1 LABEL BYTE
M1 DB 0FFH
L1 DB ?
P11 DB 0FFH DUP ('$')
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
DISPLAY MSG1
LEA DX,P1
MOV AH,0AH
INT 21H
DISPLAY MSG2
DISPLAY P11
CHECK1: CMP L1,04H
JNE NOT4D
LEA SI,P11
MOV CH,0
MOV CL,L1
DEC CL
CHECK2:
CMP [SI],30H
JB INCFLAG
CMP [SI],3AH
JB NOINC
INCFLAG:
INC FLAG
NOINC:
INC SI
LOOP CHECK2
CHECK3: CMP FLAG,0H
JNE NOTNUM
CONV:
LEA SI,P11
MOV AX,0H
MOV AL,[SI]
SUB AL,30H
MOV DX,1000
MUL DX
MOV NUM,AX
INC SI
MOV AX,0H
MOV AL,[SI]
SUB AL,30H
MOV DL,100
MUL DL
ADD NUM,AX
INC SI
MOV AX,0H
MOV AL,[SI]
SUB AL,30H
MOV DL,10
MUL DL
ADD NUM,AX
INC SI
MOV AX,0H
MOV AL,[SI]
SUB AL,30H
ADD NUM,AX
INC SI
MOV AX,NUM
LEA SI,RES
CALL HEX2BIN
DISPLAY MSG5
LEA DX,RES
MOV AH,9
INT 21H
JMP DONE
NOTNUM:
DISPLAY MSG3
JMP DONE
NOT4D:
DISPLAY MSG4
DONE:
MOV AH,4CH
INT 21H
CODE ENDS
HEX2BIN PROC NEAR
MOV CX,0
MOV BX,2
LOOP1: MOV DX,0
DIV BX
ADD DL,30H
PUSH DX
INC CX
CMP AX,1
JG LOOP1
ADD AL,30H
MOV [SI],AL
LOOP2: POP AX
INC SI
MOV [SI],AL
LOOP LOOP2
RET
HEX2BIN ENDP
END START

 

Screen Shots :-

Asm_program_Check_4digits_2_binary

Output After Execution :-

Asm_program_Check_4digits_2_binary_Out