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

Explain the design reusability of verilog, Explain the Design reusability o...

Explain the Design reusability of Verilog There is no concept of packages in Verilog. Functions and procedures used within a model should be  defined  in  the  module.  To  mak

Binary floating-point number range, Q. Binary floating-point number range? ...

Q. Binary floating-point number range? Smallest Negative number   Maximum mantissa and maximum exponent     =    - (1 -2 -24 ) × 2 127   Largest negative number

Software engineering, assignment on transaction flow, transform flow, trans...

assignment on transaction flow, transform flow, transform mapping: refining the architectural design

What is a spool request, What is a Spool request? Spool requests are f...

What is a Spool request? Spool requests are formed during dialog or background processing and placed in the spool database with information about the printer and print format.

How to use http and world wide web, Q. How to use Http and World Wide Web? ...

Q. How to use Http and World Wide Web? Http and World Wide Web One of the most frequently used services on the Internet is the World Wide Web (WWW). The application proto

For which class address 192.5.48.3 belogs, Address 192.5.48.3 belongs to? ...

Address 192.5.48.3 belongs to? Address 192.5.48.3 belongs to class C.

Isoquants, what are the types of isoquants

what are the types of isoquants

Printers, Printers are devices which put ink on paper in a controlled manne...

Printers are devices which put ink on paper in a controlled manner. They manually produce photographic images orreadable text. Printers have gone through a large transition in tech

Illustrates about metal fix, Illustrates about Metal Fix. A Metal Fix i...

Illustrates about Metal Fix. A Metal Fix implies that only the upper metal interconnects layers are influenced. Connections may be made or broken, but new cells may not be adde

Transfer of control, Question a) Name and explian the four essential ...

Question a) Name and explian the four essential elements of a machine instruction. b) Provide any four common examples of mnemonics. c) The level of disagreement conce

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