Conversion of bcd number to binary using a procedure, Computer Engineering

Assignment Help:

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.


Related Discussions:- Conversion of bcd number to binary using a procedure

Which is not a layer of input-output management module, Which is not a laye...

Which is not a layer of IO management module? Ans. MCS that is Management Control System, is not a layer of IO management module.

Mathematical simulation and modeling applications, Mathematical Simulation ...

Mathematical Simulation and Modeling Applications The tasks including modeling and mathematical simulation require a lot of parallel processing. Three basic formalisms in model

Explain the general model for the translation process, Write down the gener...

Write down the general model for the translation process. For the translation process the general model can be represented as given here:

How adaptive transmission helps tcp to maximize connection, How adaptive tr...

How adaptive transmission helps TCP to maximize throughput on each connection? To know how adaptive retransmission helps TCP maximize throughput upon all connection, see a case

Structure of internet servers address, Structure of Internet Servers Addres...

Structure of Internet Servers Address Structure of an Internet server's address keyed into a client's software is as below: http://www.expertsmind.com Where: htt

Explain inheritance, Can you explain what inheritance is and an example of ...

Can you explain what inheritance is and an example of when you might use it? The process of deriving a new class from an existing class is known as Inheritance. The old class i

Explain the optimization of data access paths, Explain the Optimization of ...

Explain the Optimization of data access paths Optimization is a very significant aspect of any design. The designer must do the followings for optimization: i) Add redundan

Write an algorithm for the braking system, Question: a) Consider a car ...

Question: a) Consider a car having a collision detection mechanism. Write an algorithm (in simple English) to illustrate the collision detection mechanism. b) The same car

What do you understand by electronic funds transfer, What do you understand...

What do you understand by Electronic Funds Transfer?  Electronic Funds Transfer: It's an electronic payment method that transfers the money value from one bank account to

Neural network for two predictors thickness, 2) Consider the following neur...

2) Consider the following neural network for two predictors Thickness and Alignment and two classes Print Quality High and Low. Some weights are shown in the table, including weigh

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