Answer to Question #150524 in Assembler for Ravin Kumar

Question #150524
Write and run a 8086 Assembly language program that converts a three digit ASCII number
stored in three consecutive byte locations in the memory, into a binary number. The output
should be stored in DX register.
1
Expert's answer
2020-12-13T22:48:33-0500

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


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS