Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Function calls
#1
When doing assembler based function calls, there's something that confuses me about the stack.
Code:
FUNCTION thing (num1 as uByte, num2 as uByte) as uByte
asm
DI
HALT
end asm
END FUNCTION

When the virtual computer crashes, you can look at the registers and the stack and find out what it's doing.

The stack seems to have
uinteger <something>
uinteger <return address>
uinteger <44,num1>
uinteger <44,num2>

A is set to num1

First question: What's the <something> ? I end up popping it off the stack and dumping it. This worries me.
Second question: If I can trust A to be num1 already, why do I have to go through num1 to get to num2?
Third question: Why the 44's strapped to each byte parameter?

So right now I end up:
Code:
POP BC  ; throw this away
POP HL  ; return address
POP AF  ; num 1 -> A
POP DE  ; num2 -> D.

And since that's less than helpful:
LD E,D
LD D,0

To make DE the value of num2.

Question 1 worries me most. What IS that extra value on the stack?

Is there a better way of handling parameters - with IX+offset, say?
Does the compiler set it to clean up the stack afterwards, and I shouldn't POP it at all?

Sorry to whine, but this isn't documented, and I'm trying to reverse engineer it! I've got the hang of fastcall, but soemtimes I want more than one parameter.
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)