Assignment 2 Solution Ask the user to input a decimal number from

advertisement

Assignment 2 Solution

3Ask the user to input a decimal number from 0-9 and display its binary equivalence in a newline.

The user must input a number if another character is entered display a message that it is “illegal” then ask the user again. After showing the binary number ask the user if she wants to check another number if (Y-y) is input ask the user to enter a digit, if (N-n) terminate the program. When asking the user if she wants to check, if the input is another character show a message guiding the user to input (Y-y for Yes and N-n for No) then ask again. A sample run is shown at the bottom.

org 100h

;SHOW THE MESSAGE

;and prompt the user to enter a digit

DISP:

MOV AH,9

LEA DX,MS1

INT 21H

MOV AH,1 ;entering a digit

INT 21H

;if it is between 0 and 9 continue

; else print an illigal message

CMP AL,'0'

JNGE ILLI

CMP AL,'9'

JNLE ILLI

;converting the entered number to decimal

AND AX,0FH

MOV BX,AX

;displaying a newline

MOV AH,9

LEA DX,NEWL

INT 21H

;counter 16 times will print a binary number

MOV CX,16

MOV AH,2

TOP_:

ROL BX,1 ;content in BX

JC display_one ; print bit ‘1’

MOV DL,"0" ; else Print bit ‘0’

JMP display display_one:

MOV DL,"1"

Display:

MOV AH,1

INT 21H

CMP AL,'Y'

JE NEWL_

CMP AL,'y'

JE NEWL_

CMP AL,'N'

JE EXIT

CMP AL,'n'

JE EXIT

INT 21H ; Print bit either ‘0’ or ‘1’

LOOP TOP_

;cheking if the user wants to repeat the process again

;if y or n is printed it will be accepted

;else a notification message will be displayed

;that asks the user to enter either y or n

CHK:

MOV AH,9

LEA DX,MS3

INT 21H

Type_YN:

MOV AH,9

LEA DX,MS4

INT 21H

JMP CHK

;displaying illigal message if the user input a different digit

ILLI:

MOV AH,9

LEA DX,MS2

INT 21H

NEWL_:

MOV AH,9

LEA DX,NEWL

INT 21H

JMP DISp

; LOOP BACK

EXIT: ret newl db 0ah,0dh,"$"

MS1 DB "Enter a digit (0-9): $"

MS2 DB " ILLIGAL $"

MS3 DB 0DH,0AH,"DO YOU WANT TO CHECK ANOTHER NUMBER: $"

MS4 DB 0DH,0AH,"Please Type in (Y-y for YES/ N-n for NO) $"

Download