Illustration of code conversion, Computer Engineering

Assignment Help:

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


Related Discussions:- Illustration of code conversion

Illustrate what is a ion pair energy, Q. Illustrate what is a ion pair ener...

Q. Illustrate what is a ion pair energy? Answer:- Ion energy contains electric charges called protons (+) and neutrons (0) and electrons (-) charges. It's present in an at

Determine the applications of recursion theorem, Applications of recursion ...

Applications of recursion theorem?  1.  ATM is undecidble.  2.  Fixed point theorem.  3. MINTM is not Turing recognisable

Eight-stage process - conjunctive normal forms, Eight-stage process - Conju...

Eight-stage process - Conjunctive normal forms: Hence we notice the following eight-stage process converts any sentence with CNF as:  1.  Eliminate all arrow connectives by

Variable-partition multiprogramming, Choose the descriptions below with the...

Choose the descriptions below with the most appropriate memory management scheme (A through D).  Solutions may be used once, more than once, or not at all. A.     Fixed-partitio

Explain the functioning of firewall using screening router, Explain the fun...

Explain the functioning of Firewall Using Screening Router. Firewall Using Screening Router: The risk of break-within is large along with this form of firewall: Eve

What is dynpro, What is dynpro?What are its components ? A dynpro (Dyna...

What is dynpro?What are its components ? A dynpro (Dynamic Program) having of a screen and its flow logic and controls exactly single dialog steps. The dissimilar components

Java, about java types

about java types

C++, What are virtual Functions

What are virtual Functions

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd