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

Forward chaining - artificial intelligence, Forward Chaining - Artificial i...

Forward Chaining - Artificial intelligence: Imagine we have a set of axioms which we know are true statements regarding the world. If we set these to each be a starting state o

Backpropagation learning routine, Backpropagation Learning Routine: Co...

Backpropagation Learning Routine: Conversely as with perceptrons there the information in the network is stored in the weights than the learning problem comes down to the ques

What do you mean by directives, Q What do you mean by Directives? Assem...

Q What do you mean by Directives? Assembly languages support numerous statements. This allows you to control the way in which a source program assembles and list. These stateme

Arterial puncture - specimen collection, Arterial puncture - Specimen colle...

Arterial puncture - Specimen collection: Arterial puncture:    this requires special skill and usually performed only by physician. The preferred site is radial arter

Example of blocking probability for the three stage network, A three stage ...

A three stage network is realized by using switching matrices of size p x s in stage 1, r x r matrices in stage 2 and s x p matrices in stage 3. Using the Lee's probability graph s

Gui status in a program from the object browser, Can we create a gui status...

Can we create a gui status in a program from the object browser? Yes.  You can make a GUI STATUS in a program using SET PF-STATUS.

What is zero address instruction, Zero address instruction.  It is also...

Zero address instruction.  It is also possible to use instruction where the location s of all operand is explained implicitly. This operand of the use of the method for storing

Give the organization of centralized store program control, Give the organi...

Give the organization of centralized store program control ( SPC). Within stored program control systems, a program or set of instructions for the computer that is stored in

Find the minimum sop and pos expression, Q.  Find the minimum SOP and POS e...

Q.  Find the minimum SOP and POS expression for the following functions using K- Map and realize the expression using appropriate gates. Also realize SOP form using NAND-to-NAND ga

Parallel ports - micro-controller, The main I/O used by micro controllers a...

The main I/O used by micro controllers are the parallel ports , the 68HC11F1 has seven  8 bit ports namely Port A,B,C,D,E,F and G . The use of ports depends on the mode configurati

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