q show the code conversion with examplethe


Q. Show the Code Conversion with example?

The conversion of data from one form to another is required. Consequently we will discuss an illustration for converting a hexadecimal digit attained in ASCII form to binary form.

Program:

; This program converts an ASCII input to equivalent hex digit which it represents.

; So valid ASCII digits are 0 to 9, A to F and program presumes that the 

; ASCII digit is read from a location in memory known as ASCII. The hex result is 

; left in the AL. Because the program converts just one digit number the AL is 

; Sufficient for the results. Result in AL is made FF if character in ASCII 

; is not proper hex digit.

; ALGORITHM 

; IF number <30h THEN error

; ELSE

; IF number <3Ah THEN Subtract 30h (it's a number 0-9)

; ELSE (number is >39h)

; IF number <41h THEN error (number in range 3Ah-40h which is not a valid

; A-F character range)

; ELSE

; IF number <47h THEN Subtract 37h for letter A-F 41-46 (Please note 

; that 41h - 37h = Ah)

; ELSE ERROR

;

; PORTS: None used

; PROCEDURES: None

; REGISTERS: Uses CS, DS, AX,

;

DATA                         SEGMENT

ASCII DB 39h                       ; any experimental data

DATA ENDS

CODE SEGMENT

                                    ASSUME CS: CODE, DS: DATA

START:                       MOV AX, DATA ; initialise data segment

                                    MOV DS, AX  ; Register using AX

                                    MOV AL, ASCII ; Get the ASCII digits of the number

                                                                        ; start the conversion 

                                    CMP AL, 30h; If the ASCII digit is below 30h then it is not 

JB ERROR; a proper Hex digit

                                    CMP AL, 3Ah; compare it to 3Ah

                                    JB NUMBER; if greater then possibly a letter between A-F

                                    CMP AL, 41h; this step will be done if equal to or above 

; 3Ah

                                    JB ERROR; between 3Ah and 40h is error

                                    CMP AL, 46h

                                    JA ERROR; The ASCII is out of 0-9 and A-F range

                                    SUB AL, 37h; it's a letter in the range A-F so convert

                                    JMP CONVERTED

NUMBER:                  SUB AL, 30h; it is a number in the range 0-9 so convert

JMP CONVERTED

ERROR: MOV AL, 0FFh; you can also display some message here

CONVERTED: MOV AX, 4C00h

INT 21h; the hex result is in AL

CODE ENDS

END START

Request for Solution File

Ask an Expert for Answer!!
Computer Engineering: q show the code conversion with examplethe
Reference No:- TGS0327994

Expected delivery within 24 Hours