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

How a typical dma controller can be interfaced to an 8086, Demonstrate how ...

Demonstrate how a typical DMA controller can be interfaced to an 8086/8085 based maximum mode system.  For 8088 in maximum mode: The RQ/GT0 and RQ/GT1 pins are used to is

State the term availability - organisational security scheme, State the ter...

State the term Availability - organisational security scheme What data needs to be available continually, compared to data which can be "off line" for limited periods. Th

My project has not working, my project is in .net of lan chatting its have ...

my project is in .net of lan chatting its have tcp\ip connection problem

Instruction set and effective addressing techniques, The term addressing mo...

The term addressing mode is a technique of stating the input and output of an instruction; it is termed the effective address. There are 6 effective addresses in the 68HC11 set of

Regular expression pattern in a wsdl document, Probelm: (a) Show the at...

Probelm: (a) Show the attributes used by Regular Expression Pattern in a WSDL document. (b) Describe the three standard wire formats for transmitting Web Service requests a

Board coloring, In this problem you are given a board in which some of the...

In this problem you are given a board in which some of the elements are placed as shown in diagram below. Each element represents a color. Fill the other elements in the board, suc

Give the example of spreadsheet, Give the example of Spreadsheet By sel...

Give the example of Spreadsheet By selecting cell C1 and dragging the formula down to C5 the below formulae will be replicated in C2 to C5: (A2*B2), (A3*B3), (A4*B4) and (A5*B5

Differences between flexgrid control and dbgrid control, Normal 0 ...

Normal 0 false false false EN-IN X-NONE X-NONE MicrosoftInternetExplorer4

Explain why most interrupts are active low, Explain why most interrupts are...

Explain why most interrupts are active low? This answers why most signals are active low when you see the transistor level of a module, active low implies that the capacitor in

Define syntax of mpi_bcast function, Q. Define syntax of MPI_Bcast function...

Q. Define syntax of MPI_Bcast function? MPI_Bcast(msgaddr, count, datatype, rank, comm):   This function is used by a process ranked rank in group comm to transmit messag

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