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

Vector-memory instructions-vector processing, Vector-Memory Instructions : ...

Vector-Memory Instructions : When vector operations with memory M are executed then these are vector-memory instructions. These instructions are denoted with the many function mapp

Microcontrollers (mcu), Main Objectives: Uploading codes into the mi...

Main Objectives: Uploading codes into the microcontrollers Interfacing between both microcontrollers via I 2 C Reading and writing into various ports on the MCU Int

Explain about registers, Q. Explain about Registers? A register is a gr...

Q. Explain about Registers? A register is a group of flip-flops that store binary information and gates that controls when and how information is transferred to register. An n-

Describe about directory in doc, Q. Describe about directory in DOC? We...

Q. Describe about directory in DOC? We all know that, the volume of the hard disk is generally quite large (10 MB to a few GB). You can keep hundreds or even thousands of files

How do we call one script-fu script from another, he trick to calling scrip...

he trick to calling script-fu-scripts from any more script is to just reference the main define for the script and not to try to use the pdb call. All the scripts in script-fu shar

What is error detection code, What is Error detection code? It is a bin...

What is Error detection code? It is a binary code that notice digital errors during transmission. The detected errors cannot be correct but the presence is shown.

Why erlang is used, Erlang is used to (A) Measure busy period         ...

Erlang is used to (A) Measure busy period                (B) Give total busy period in minutes (C)  Measure average call rate       (D) Indicate total call period Ans

Dbms, Disadvantages of file processing system

Disadvantages of file processing system

Explain r-2r ladder d/a converter, Explain R-2R ladder D/A converter. A...

Explain R-2R ladder D/A converter. Ans. R-2R ladder D/A converter: An R-2R ladder D/A converter is shown in Fig.(a). It uses resistors of only two values R and 2R. The inp

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