DATA SEGMENT
numASCII DB '3', '7', '1'
number DB 3 DUP(?)
DATA ENDS
CODE SEGMENT
ASSUME DS:DATA,CS:CODE
START:
MOV AX,DATA
MOV DS,AX
XOR AX,AX ; ax = 0
LEA SI, numASCII ; addr of numASCII
LEA DI, number ; addr of number
MOV AL, numASCII[SI] ; read first ASCII num
SUB AL,30H ; convert ASCII to number
MOV number[DI],AL ; save first digit
INC SI ; next item in numASCII
INC DI ; next item in number
MOV AL, numASCII[SI] ; read second ASCII num
SUB AL,30H ; convert ASCII to number
MOV number[DI],AL ; save second digit
INC SI ; next item in numASCII
INC DI ; next item in number
MOV AL, numASCII[SI] ; read third ASCII num
SUB AL,30H ; convert ASCII to number
MOV number[DI],AL ; save third digit
; Calculate hundreds
LEA SI,number ; high digit address (hundreds)
MOV CL,100
MOV AL, number[SI] ; hundreds
MUL CL ; <number of hundreds>*100
MOV DX,AX ; save result in DX
INC SI ; second digit address (tens)
; Calculate tens
XOR AX,AX ; AX = 0 before multiplication AX=0
MOV CL,10
MOV AL, number[SI] ; tens
MUL CL ; <number of tens>*10
ADD DX,AX ; hundreds+tens
INC SI ; lower digit address (units)
; Add units and Calculate binary number in DX
XOR AX,AX
MOV AL, number[SI] ; units
ADD DX,AX ; hundreds+tens+units
; result stored in DX register
EXIT_PROG: ; Program is terminated
MOV AH,4CH
INT 21H
CODE ENDS
END START
Comments
Leave a comment