User Tag List

Results 1 to 10 of 23

Thread: Problem Writing a Function

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    The Time-Loop Continues ZC Developer
    Gleeok's Avatar
    Join Date
    Apr 2007
    Posts
    4,826
    Mentioned
    259 Post(s)
    Tagged
    10 Thread(s)
    vBActivity - Stats
    Points
    12,961
    Level
    33
    vBActivity - Bars
    Lv. Percent
    26.42%
    No wait, 0 means register! #$%^ dammit. :mad:

    Also, DarkDragon is much more knowledgeable about the ZScript compiler than I am.


    Quote Originally Posted by ZoriaRPG View Post
    What's the best way to inspect the stack without a live stack debuger? Throw out ZConsole messages with the values of the expression accumulators?

    I'm sort of in the 'how does Gleeok do this' mode...which is why I was hoping for a procedural list from you, on what the flidd you would do; or some kind of step-by-step details on how to build this kind of function in the frrst place.
    Honestly, I usually half forget some of this stuff, so I just go in order of: 1) Declare constants and opcodes; update script tables; implement compiler procedure as needed; update bytecode in ffscript.cpp; and finally, implement function that gets called.


    [edit]
    Also, what compiler are you using that doesn't have a debugger?
    This post contains the official Gleeok seal of approval. Look for these and other posts in an area near you.

  2. #2
    Administrator DarkDragon's Avatar
    Join Date
    Oct 2001
    Posts
    6,228
    Mentioned
    70 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    11,030
    Level
    31
    vBActivity - Bars
    Lv. Percent
    8.74%
    ZoriaRPG, to answer your question in your commented lines: the ZScript calling convention is more or less equivalent to C's. The caller first pushes the return address onto the stack, then all of the function's explicit argument, and finally, if the function is a member function, the "this" pointer is implicitly pushed as the last argument.

    The return value of the function is by convention stored in EXP1.

    The callee, then, before it can return, must pop all of the arguments (including the "this" pointer) off of the stack. That's what the lines are doing that you've commented about. The ZASM instruction uses the top 4 entries of the stack, but leaves them untouched, so ZScript pops them off, then pops off the return address and jumps to it. You could use NUL instead of EXP2 for these pops if you wanted.

    The reason EXP2 is used as scratch space instead of EXP1 is simply to avoid accidentally tampering with the return value of the function.

  3. #3
    The Timelord
    QDB Manager
    ZC Developer

    Join Date
    Oct 2006
    Location
    Prydon Academy
    Posts
    1,396
    Mentioned
    112 Post(s)
    Tagged
    1 Thread(s)
    vBActivity - Stats
    Points
    4,765
    Level
    21
    vBActivity - Bars
    Lv. Percent
    69.7%
    Quote Originally Posted by DarkDragon View Post
    ZoriaRPG, to answer your question in your commented lines: the ZScript calling convention is more or less equivalent to C's. The caller first pushes the return address onto the stack, then all of the function's explicit argument, and finally, if the function is a member function, the "this" pointer is implicitly pushed as the last argument.

    The return value of the function is by convention stored in EXP1.

    The callee, then, before it can return, must pop all of the arguments (including the "this" pointer) off of the stack. That's what the lines are doing that you've commented about. The ZASM instruction uses the top 4 entries of the stack, but leaves them untouched, so ZScript pops them off, then pops off the return address and jumps to it. You could use NUL instead of EXP2 for these pops if you wanted.

    The reason EXP2 is used as scratch space instead of EXP1 is simply to avoid accidentally tampering with the return value of the function.

    Got it. Good stuff there; and I put it into the docs. :)

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Armageddon Games is a game development group founded in 1997. We are extremely passionate about our work and our inspirations are mostly drawn from games of the 8-bit and 16-bit era.
Social