flat assembler
Message board for the users of flat assembler.
Index
> Main > Use of structs in stack based procedure-calling |
Author |
|
Tomasz Grysztar 20 Nov 2003, 18:41
There are various options. You can just use just "virtual" and your code will look like:
Code: screenAddress = 0a000h virtual at bp oldbp dw ? retadr dw ? color dw ? ykoord dw ? xkoord dw ? end virtual plot: push bp mov bp,sp mov ax,screenAddress mov es,ax mov bx,[ykoord] mov di,[xkoord] mov ax,[color] mov dx,cx mov cl,6 shl bx,cl mov cx,bx shl bx,1 shl bx,1 add bx,cx mov cx,dx mov [es:bx+di],al pop bp ret 6 you could also define it with struc and virtual, like: Code: screenAddress = 0a000h struc para1 { .oldbp dw ? .retadr dw ? .color dw ? .ykoord dw ? .xkoord dw ? } virtual at bp bppara1 para1 end virtual plot: push bp mov bp,sp mov ax,screenAddress mov es,ax mov bx,[bppara1.ykoord] mov di,[bppara1.xkoord] mov ax,[bppara1.color] mov dx,cx mov cl,6 shl bx,cl mov cx,bx shl bx,1 shl bx,1 add bx,cx mov cx,dx mov [es:bx+di],al pop bp ret 6 But the best option would be just to use 16-bit version of standard STDCALL macros for fasm: Code: macro proc name,[arg] ; define procedure { common name: virtual at bp+4 if ~ arg eq forward local ..arg ..arg dw ? arg equ ..arg common end if ..ret = $ - (bp+4) end virtual local ..dynamic_data,..dynamic_size dynamic_data equ ..dynamic_data dynamic_size equ ..dynamic_size virtual at ebp - dynamic_size dynamic_data: } macro enter size,level ; begin procedure instructions { if size eq & level eq rb (2 - ($-dynamic_data) and 1) and 1 dynamic_size = $ - dynamic_data end virtual push bp mov bp,sp if dynamic_size sub sp,dynamic_size end if else enter size,level end if } macro return ; return from procedure { leave ret ..ret } macro stdcall proc,[arg] ; call procedure { reverse pushw arg common call proc } with those macros, your code can become much simpler: Code: screenAddress = 0a000h proc plot, xkoord,ykoord,color enter mov ax,screenAddress mov es,ax mov bx,[ykoord] mov di,[xkoord] mov ax,[color] mov dx,cx mov cl,6 shl bx,cl mov cx,bx shl bx,1 shl bx,1 add bx,cx mov cx,dx mov [es:bx+di],al return If you need to use the reverse order of parameters on the stack (with this one you have to push the "color" first and the "xkoord" last), replace "forward" in the definition of "proc" macro with "reverse" word. |
|||
20 Nov 2003, 18:41 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.