flat assembler
Message board for the users of flat assembler.

Index > Main > Use of structs in stack based procedure-calling

Author
Thread Post new topic Reply to topic
yazper



Joined: 20 Nov 2003
Posts: 4
Location: at home
yazper
Hi everyone

Im trying to acomplish the following in fasm...
In TASM you can use structs like so:

Code:
screenAddress   equ     0a000h

para1   struc
        oldbp   dw      ?
        retadr  dw      ?
        color   dw      ?
        ykoord  dw      ?
        xkoord  dw      ?
para1   ends

plot proc near
        push    bp              ;save reg
        mov     bp,sp

        mov     ax,screenAddress
        mov     es,ax

        mov     bx,[bp].ykoord
        mov     di,[bp].xkoord
        mov     ax,[bp].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   ;plot it

        pop     bp

        ret     6
plot endp
    


Is it possible to use the struct of fasm to do the same kind of thing?

thanks

_________________
--------------------
Light speed is faster then the speed of sound - that's why ppl look smart until they talk!
Post 20 Nov 2003, 18:15
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7750
Location: Kraków, Poland
Tomasz Grysztar
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.
Post 20 Nov 2003, 18:41
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on YouTube, Twitter.

Website powered by rwasa.