title: x86 assembly: Pass parameter to a function through stack
body: <p>I'm trying to make a subprogram in assembly which will draw a square on the screen. I don't think I can pass parameters to the subprogram like I would do in C++, so I figured that I could use stack to store and access the parameters (I can't use the common data registers because there are too many variables to pass). </p>
  
  <p>The problem is (I remember reading somewhere) that when I use the call command to the address of the current "program" it is saved on the stack, so that when it's used the "ret" command it would know where to return. But if I store something on the stack and then call the function, I will have to save somewhere the address (that is on the top of stack) and then safely pop the parameters. Then after the code has finished and before calling "ret", I would have to push back the address. </p>
  
  <p>Am I right? And, if yes, where can I store the address (I don't think the address is only 1 byte long so that it would fit in AX or BX or any other data register). Can I use IP to do this (although I know this is used for something else)?</p>
  
  <p>This is what I imagine:</p>
  
  <pre><code>[BITS 16]
  ....
  main:
    mov ax,100b
    push ax
    call rectangle ;??--pushes on the stack the current address?
  
  jml $
  
  rectangle:
    pop ax ;??--this is the addres of main right(where the call was made)?
    pop bx ;??--this is the real 100b, right?
    ....
    push ax
  ret ;-uses the address saved in stack
  </code></pre>