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 instruction level of parallel processing, Instruction Level It ...

Instruction Level It refers to condition where different instructions of a program are implemented by different processing elements. Most processors have various execution unit

Explain sample instruction format of mips instruction, Q. Explain Sample In...

Q. Explain Sample Instruction Format of MIPS instruction? All MIPS instructions are of same size and are 32 bits long. MIPS designers chose to keep all instructions of same len

Explain the concept behind pre-compositing adobe, Question 1: (a) Expl...

Question 1: (a) Explain the concept behind Pre-Compositing Adobe After Effects. (b) Briefly describe the Wiggler function in Animation help in Adobe After Effects. (c)

What is wmfc, What is WMFC? WMFC if the control signals that causes the...

What is WMFC? WMFC if the control signals that causes the processor's control circuitry to wait for the arrival of the MFC signal.

Doubly linked list than by singly linked list, Which operations is performe...

Which operations is performed more efficiently by doubly linked list than by singly linked list Deleting a node whose location is given.

What does the future in gimp, Version 2.8 may bring a combined Transform to...

Version 2.8 may bring a combined Transform tool (Scale, Rotate,Flip and Perspective), more use of Cairo for attractive ant aliased graphics and more usability improvements. We will

What are the authentication methods in .net, What are the authentication me...

What are the authentication methods in .NET?   1. WINDOWS AUTHENTICATION 2. FORMS AUTHENTICATION 3. PASSPORT AUTHENTICATION The authentication option for the ASP.N

Explain what the difference between the two readings, The following sentenc...

The following sentences have a (potential) scope ambiguity. Give two translations into predicate logic for each sentence (one formula for each reading), and explain in words what t

Explain the page stealer and the fault handler, How the Kernel handles both...

How the Kernel handles both the page stealer and the fault handler? The page stealer and the fault handler thrash because of the shortage of the memory. If the sum of the worki

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