program a good illustration of code conversion


Program: A good illustration of code conversion: Write a program to convert a; 4-digit BCD number into its binary equivalent. BCD number is stored as a; word in memory location known as BCD. The result is to be stored in location HEX.

; ALGORITHM:

; Let us assume the BCD number as 4567

; Put the BCD number into 4, 16bit registers

; Extract the first digit (4 in this case)

; By masking out the other three digits. Since, its place value is 1000.

; So multiply by 3E8h (that is 1000 in hexadecimal) to get 4000 = 0FA0h

; Extract the second digit (5)

; By masking out the other three digits.

; Multiply by 64h (100)

; Add to first digit and get 4500 = 1194h

; Extract the third digit (6)

; By masking out the other three digits (0060)

; Multiply by 0Ah (10)

; Add to first and second digit to get 4560 = 11D0h

; Extract the last digit (7)

; By masking out the other three digits (0007)

; Add the first, second, and third digit to get 4567 = 11D7h

; PORTS    : None used

; REGISTERS: Uses CS, DS, AX, CX, BX, DX

 

THOU             EQU    3E8h    ; 1000 = 3E8h

DATA             SEGMENT

                        BCD    DW     4567h

                        HEX    DW?    ; Storage reserved for result

DATA ENDS

 

CODE SEGMENT

            ASSUME CS: CODE, DS: DATA

START:           MOV AX, DATA; initialise data segment

                        MOV DS, AX; using AX register

                        MOV AX, BCD; get the BCD number AX = 4567

                        MOV BX, AX; copy number into BX; BX = 4567

                        MOV AL, AH; place for upper 2 digits in AX = 4545

                        MOV BH, BL; place for lower 2 digits in BX = 6767

                                                ; split up numbers so that we have one digit 

                                                 ; In each register

                        MOV CL, 04; bit count for rotate

                        ROR AH, CL; digit 1 (MSB) in lower four bits of AH. 

                                                 ; AX = 54 45

                        ROR BH, CL; digit 3 in lower four bits of BH.

; BX = 76 67

                        AND AX, 0F0FH; mask upper four bits of each digit. 

                                                ; AX = 04 05

AND BX, 0F0FH; BX = 06 07

                        MOV CX, AX; copy AX into CX so that can use AX for 

                                                 ; Multiplication CX = 04 05

; CH comprises digit 4 having place value 1000, CL comprises digit 5 

 ; having place value 100, BH comprises digit 6 having place value 10 and 

 ; BL comprises digit 7 having unit place value.

 ; So attain the number as CH × 1000 + CL × 100 + BH × 10 + BL

 

MOV AX, 0000H; zero AH and AL

            ; Now multiply every number by its place 

            ; Value

MOV AL, CH; digit 1 to AL for multiply 

MOV DI, THOU; no immediate multiplication is allowed so 

     ; move thousand to DI

MUL DI; digit 1 (4)*1000

            ; result in DX and AX. Because BCD digit

            ; will not be greater than 9999, the result will 

            ; be in AX only. AX = 4000

 MOV DH, 00H; zero DH

 MOV DL, BL; move BL to DL, so DL = 7

 ADD DX, AX; add AX; so DX = 4007

 MOV AX, 0064h; load value for 100 into AL

 MUL CL; multiply by digit 2 from CL

ADD DX, AX; add to total in DX.  DX now comprises

            ; (7 + 4000 + 500)

 MOV AX, 000Ah; load value of 10 into AL

 MUL BH; multiply by digit 3 in BH

 ADD DX, AX; add to total in DX; DX comprises

            ; (7 + 4000 + 500 +60)

MOV HEX, DX; put result in HEX for return

MOV AX, 4C00h

INT 21h

CODE ENDS

END START

Request for Solution File

Ask an Expert for Answer!!
Computer Engineering: program a good illustration of code conversion
Reference No:- TGS0328088

Expected delivery within 24 Hours