Start New Discussion within our Software Development Community

hi!

i'm doing a university project in asm using the assembler found in tanenbaum's book "structured computer organization"(ftp here), which produces code to be run on a 8088 emulator (s88)

so, what i wanted to ask is:

say i want to call a subroutine that needs some variables.
the most obvious thing would be to push them on the stack prior to calling the subroutine.
the only problem is that one thing the subroutine needs to do is to print/read them, and in order to do that it has to enqueue them on the stack in a precise order, so what would happen is that i'd have two copies of the same variable on the stack.
for example:

PUSH romfile
CALL readfile

...
readfile:
PUSH BP
MOV BP,SP
PUSH 0
PUSH 6(BP) ! here i'm putting romfile on the stack again
PUSH _OPEN
SYS

another solution would be to have a register (BX maybe?) point to the variable before calling the subroutine, and then pushing that register into the stack. this way tho, i wouldn't be really calling a subroutine with parameters, right?
what i mean to say, is that imho in this case the signature wouldn't be:

readfile(char *file)

but a simple

readfile(void)

is this second approach correct?
i think a drawback in it is that you force people who may be using this subroutine to use a particular register to store the parameters.

thanks, sorry for the mess :)
asymmetric

> PUSH 6(BP) ! here i'm putting romfile on the stack again
It's the way a compiler would do it.

> another solution would be to have a register (BX maybe?)
Also a possible way, for example __fastcall

Whether you push all the params, or pass a few in registers, I think you'd still declare the function in the same way. readfile(char *file) Tells you the interface, not the implementation.

Adopting a consistent approach which works would be more important than over-optimising every single case.

This question has already been answered. Start a new discussion instead.