Explain passing parameters using pointers, Computer Engineering

Assignment Help:

Q. Explain Passing Parameters Using Pointers ?

This method overcomes the drawback of using variable names directly in procedure. It uses registers to pass procedure pointers to desired data. Let's explain it more with the help of a program.

Program version 2:

DATA_SEG               SEGMENT

                        BCD DB   25h; Storage for BCD test value

BIN      DB?  ; Storage for binary value

DATA_SEG ENDS

STACK_SEG SEGMENT    STACK

DW 100 DUP (0)    ; Stack of 100 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   ; Initialize data

MOV DS, AX   ; segment using AX register

MOV AX, STACK_SEG   ; initialize stack

MOV SS, AX; segment. Why stack?

MOV SP, OFFSET TOP_STACK; initialize stack pointer

; Put pointer to BCD storage in SI and DI prior to procedure call.

                        MOV SI, OFFSET BCD   ; SI now points to BCD_IN 

                        MOV DI, OFFSET BIN; DI points BIN_VAL 

                                                            ; (returned value)

                        CALL BCD_BINARY   ; Call the conversion 

                                                            ; Procedure

                        NOP     ; Continue with program

                                                            ; Here

; PROCEDURE     : BCD_BINARY Converts BCD numbers to binary. 

; INPUT     : SI points to location in memory of data

; OUTPUT     : DI points to location in memory for result

; DESTROYS    : Nothing

BCD_BINARY PROC NEAR

PUSHF     ; Save flag register 

PUSH AX; and AX registers

PUSH BX; BX  

PUSH CX; and CX

MOV AL, [SI]   ; Get BCD value from memory

                                     ; For conversion

MOV BL, AL   ; copy it in BL also

AND   BL, 0Fh   ; and mask to get lower 4 digits

AND AL, 0F0h; Separate upper 4 bits in AL

MOV CL, 04   ; initialize counter CL so that upper digit 

ROR AL, CL; in AL can be brought to lower 4 bit 

                                    ; Positions in AL

MOV BH, 0Ah   ; Load 10 in BH

MUL BH; Multiply upper digit in AL by 10

                                    ; The result is stored in AL

ADD AL, BL   ; Add lower BCD digit in BL to result of 

                                    ; Multiplication

; End of conversion, now restore the original values prior to call. All calls will be in 

; reverse order to save above. The result is in AL register.

MOV [DI], AL   ; Store binary value to memory

POP CX; Restore flags and

POP BX; registers

POP AX  

POPF    

RET    

BCD_BINARY ENDP

CODE_SEG ENDS

             END START

Discussion:

In the program written above DI points to BIN and SI points to the BCD. The instruction MOV AL, [SI] copies the byte pointed by SI to AL register. In the same manner MOV [DI], AL transfers result back to memory location which is pointed by DI. 

This scheme allows you to pass procedure pointers to data anywhere in memory. You can pass pointer to individual data element or a group of data elements such as strings and arrays. This scheme is used for parameters passing to BIOS procedures.


Related Discussions:- Explain passing parameters using pointers

Explain about working of multiplexer, Q. Explain about working of Multiplex...

Q. Explain about working of Multiplexer? Multiplexer is one of the fundamental building units of a computer system that in principle permits sharing of a common line by more th

Define the uniform memory access model (uma), Normal 0 false ...

Normal 0 false false false EN-US X-NONE X-NONE

Difference between a window and a frame?, The Frame class extends Window to...

The Frame class extends Window to describe a main application window that can have a menu bar. A window can be modal.

Simplify using k-map, Q. Simplify Using K-Map 1. M2 + M3 + M5 + M7 + M1...

Q. Simplify Using K-Map 1. M2 + M3 + M5 + M7 + M12 + M13 + M8 + M9 2. M0 + M2 + M4 + M5 + M8 + M10 + M12 3. F(W,X,Y,Z) = ∑ (0,1,2,4,5,6,8,9,12,13,14)

Define baud rate, Define baud rate The rate of data transfer in serial...

Define baud rate The rate of data transfer in serial data communication is signified in bps. Bits per second (bps) is the rate of transfer of information bits. Baud is the num

Designing the instruction format, Q. Designing the instruction format is a ...

Q. Designing the instruction format is a complex art? Instruction Length Significance: It's the fundamental issue of the format design. It concludes the richness and flex

What is pli, What is PLI Programming  Language  Interface  (PLI)  of  V...

What is PLI Programming  Language  Interface  (PLI)  of  Verilog  HDL  is  a  mechanism  to  interface  Verilog programs  with  programs  written  in  C  language.  It also pro

Determine 127.0.0.1 is which type of address, 127.0.0.1 is a? 127.0.0.1...

127.0.0.1 is a? 127.0.0.1 it is a loop-back address.

Show sample instruction format of mips instruction, Q. Show Sample Instruct...

Q. Show Sample Instruction Format of MIPS instruction? Early MIPS architectures had 32-bit instructions and later versions have 64-bit implementations. The first commercial

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