Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Computer Engineering Expert

Q. Conversion of BCD number to binary using a procedure?

Conversion of BCD number to binary using a procedure.

Algorithm for conversion procedure:

Take a packed BCD digit and separate the two digits of BCD.

Multiply the upper digit by 10 (0Ah)

Add the lower digit to the result of multiplication

The implementation of procedure would be dependent on parameter-passing scheme. Let's exhibit this with the help of three programs.

Program: Use of registers for parameter passing: This program uses AH register for passing the parameter.

We are presuming that data is available in memory location. BCD and result is stored in BIN

; REGISTERS: Uses CS, DS, SS, SP, AX

; PROCEDURES: BCD-BINARY

 

DATA_SEG               SEGMENT

            BCD                DB 25h    ; storage for BCD value

            BIN                 DB?    ; Storage for binary value

DATA_SEG               ENDS  

STACK_SEG                         SEGMENT STACK    

                                    DW 200 DUP (0); stack of 200 words

            TOP_STACK LABEL WORD   

STACK_SEG                         ENDS

 

CODE_SEG                           SEGMENT  

            ASSUME CS: CODE_SEG, DS: DATA_SEG, SS: STACK_SEG  

START:  MOV AX, DATA_SEG     ; Initialise data segment

MOV DS, AX      ; Using AX register

                        MOV AX, STACK_SEG      ; Initialise stack

                        MOV SS, AX     ; Segment register. Why 

                                                ; stack?

                        MOV SP, OFFSET TOP_STACK     ; Initialise stack pointer

                        MOV AH, BCD  

                        CALL BCD_BINARY   ; Do the conversion

                        MOV BIN, AH   ; Store the result in the 

                                                ; Memory

; Remaining program can be put here 

; PROCEDURE: BCD_BINARY - Converts BCD numbers to binary.

; INPUT     : AH with BCD value

; OUTPUT     : AH with binary value

; DESTROYS   : AX

BCD_BINARY    PROC NEAR

PUSHF                                   ; Save flags

PUSH              BX                  ; and registers used in procedure

PUSH              CX                  ; before starting the conversion

                                                            ; Do the conversion

MOV               BH, AH          ; Save copy of BCD in BH

AND                           BH, 0Fh          ; and mask the higher bits. The lower digit

                                                            ; is in BH

AND               AH, 0F0h        ; mask the lower bits. The higher digit is in AH 

                                                            ; But in upper 4 bits.

MOV               CH, 04            ; so move upper BCD digit to lower

ROR                AH, CH          ; four bits in AH

MOV               AL, AH           ; move the digit in AL for multiplication

MOV               BH, 0Ah         ; put 10 in BH

MUL               BH                  ; Multiply upper BCD digit in AL

                                                            ; By 0Ah in BH, the result is in AL

MOV               AH, AL           ; the maximum/ minimum number would not 

                                                            ; exceed 8 bits so move AL to AH

ADD               AH, BH          ; Add lower BCD digit to MUL result

; End of conversion, binary result in AH

   POP              CX   ; Restore registers

   POP              BX  

   POPF           RET     ; and return to calling program

BCD_BINARY ENDP    

CODE_SEG ENDS    

             END START

Discussion:

The program written above isn't an optimum program since it doesn't use registers minimally. By now you ought to be able to understand this module. The program copies the BCD number from memory to AH register. AH register is used as it is in the procedure. So the contents of AH register are used in calling program in addition to procedure; or in other words have been passed from main to procedure. Result of the subroutine too is passed back to AH register as returned value. So calling program can find the result in AH register. 

The benefit of using the registers for passing the parameters is the ease with that they can be handled. The drawback, though, is the limit of parameters which can be passed. For instance one cannot pass an array of 100 elements to a procedure by using registers.

Computer Engineering, Engineering

  • Category:- Computer Engineering
  • Reference No.:- M9574775

Have any Question?


Related Questions in Computer Engineering

Questionusing the cost-benefit analysis method estimate how

Question..... Using the cost-benefit analysis method, estimate how much money MidCorp should spend on power protection. You will have to make several assumptions to do this. Your answer should contain an "assumptions" se ...

Question a small financial focused business is looking to

Question : A small, financial focused business is looking to organize and secure its network. It currently has a single public IP address from a local telecom. Construct an argument as to how you think a company should e ...

Discuss the importance functionality and role of a

Discuss the importance, functionality, and role of a GateKeeper or VoIP server in a VoIP -deployed network?

What decimal number does the bit pattern 0xc0d40000

What decimal number does the bit pattern 0xC0D40000 represent if it is: A two's complement integer An unsigned integer A floating point number assuming the IEE 754 single precision format Please provide a detailed explan ...

You were recently hired as a database administrator for

You were recently hired as a database administrator for CSU-Global Campus. During grade reporting, CSG-Global cannot afford to have any downtime. You have been asked to develop a plan for monitoring SQL Server databases. ...

Explain the risk of having hacking tools installed on your

Explain the risk of having hacking tools installed on your computer and why you should contact local law enforcement agencies before installing those tools.

Roberto is the network administrator for an international

Roberto is the network administrator for an international law firm with offices and customers in North America, South America, Africa, and the Middle East. The lawyers frequently contact each other via e-mail, use the In ...

It is just a simple calculator code c language ltstdiohgt

It is just a simple calculator code. C++ language library A) Display on the screen the following menu: Welcome to my calculator Please look at the menu below for your calculations 1. Addition 2. Subtraction 3. Multiplica ...

Should we be renegotiating nafta yes or no if it is

Should we be renegotiating NAFTA? yes or no? If it is renegotiated, should it be replaced? What reasons would make it better in your point of view? What is the best argument you can make why NAFTA should or should not be ...

In mergers and acquisitions there is always a

In mergers and acquisitions there is always a pre-acquisition evaluation and post-acquisition evaluation of technology. Evaluation and control should be connected to each other. What should you know before and after the ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As