Write an 8086 Assembly language program that asks the user to input a single
hexadecimal number. The program will display equivalent binary or decimal value upon user
input selection 'B' for binary conversion and 'D' for decimal conversion.
Note: Binary and decimal conversion codes will be implemented as procedures and will be
called in the main procedure.
Sample Output:
Enter a character? F
Input 'B' for Binary Conversion and 'D' for decimal Conversion? B
The equivalent binary number for 'F' is 1111
Answers
Answer:
how do u do
Explanation:
please follow me
mamakamam
ORG 100H
SECTION .DATA
PRO1 DB 0DH, 0AH, 0DH, 0AH, "INPUT A SIGNED BASE-10 INTEGER: $"
PRO2 DB 0DH, 0AH, "YOUR NUMBER IN BINARY IS: $"
PRO3 DB 0DH, 0AH, "PRETTY SURE THAT WASN'T A NUMBER. PLEASE ENTER A NUMBER VALUE: $"
PRO4 DB 0DH, 0AH, "YOUR NUMBER IN OCTAL IS: $"
SECTION .TEXT
START:
MOV AH, 9; print input pro
MOV DX, PRO1
INT 21H
MOV BX, 0; take input
MOV AH, 1
INT 21H
DecIn:
CMP AL, 0DH; compare input to carriage return; check if user is finished or not
JE DecOut; if yes, display the pro
CMP AL, '0'; compare to '0'
JG IsDigit; jump to IsDigit to confirm whether it is a number
JL NanError; if below 0, print error pro and start again
IsDigit:
CMP AL, '9’; confirms digit value
JL BinCov; if digit, convert it to binary
JG NanError; if not, print an error message 'not a number'
BinCov:
AND AX,000FH; convert it from ascii to base 10 value
PUSH AX; save it on stack
MOV AX,10; set up to value to multiply bx by 10
IMUL BX; dx:ax = bx*10
POP BX; saved value in bx
ADD BX, AX; bx = old bx*10 + new digit
MOV AH,1; input char function
INT 21H; read next character
JMP DecIn; loop until false
NanError:
MOV AH, 9; print error message
MOV DX, PRO3
INT 21H
JMP START; go back to the beginning
DecOut:
MOV AH, 9; output the signed decimal value
MOV DX, PRO2
INT 21H
MOV CX, 16
TOP:
ROL BX,1; shift msb into cf
JC ONE; CF = 1?
MOV DL,'0’; no, set up to print a 0
JMP PRINT; now print
ONE:
MOV DL,'1’; printing a 1
PRINT:
MOV AH,2; print char fcn
INT 21H; print it
LOOP TOP; loop until done
MOV AH, 2; print decimal value in bx
MOV DL, BL
INT 21H
JMP EXIT
EXIT:
MOV AH,04CH; dos function: exit
MOV AL,0; exit code
INT 21H; call dos, exit