flat assembler
Message board for the users of flat assembler.

Index > Main > Structure & procedures

Author
Thread Post new topic Reply to topic
n0p



Joined: 06 Jan 2004
Posts: 10
Location: Russia,Novosibirsk
n0p
Hi, all! I've got another problem with structures... Very Happy
How can i put structure in the procedure, and then how to get access to the structure element? e.q.:
Code:
struc SS {
    .val1 rd 4
    .val2 dd ?
}
...
var SS
...
proc PP var
    enter
    mov eax,[var.val1+4*2]
    return
    

What's wrong in this code?

_________________
English isn't my native, so sorry for any mistakes I can make...
Post 09 Feb 2004, 18:38
View user's profile Send private message ICQ Number Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3502
Location: Bulgaria
JohnFound
If you are talking about local variables:
Code:
struc SS {
    .val1 rd 4
    .val2 dd ?
}

proc PP, arg1, arg1, arg3
; declare local variables here with "." in the begining:
.local1 SS
.local2 dd ?
    enter
    mov eax,[.local1.val1+4*2]
    sub eax, [.local1.val2]
    add eax, [.local2]
    return
    
Post 09 Feb 2004, 19:03
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
n0p



Joined: 06 Jan 2004
Posts: 10
Location: Russia,Novosibirsk
n0p
No, I want to deliver structure in procedure as argument and then to get acces to any element.
Code:
proc PP, arg1
    enter
    mov eax,[arg1.val1]
    return
    

How can i tell to compiler that the arg1 is structure?

_________________
English isn't my native, so sorry for any mistakes I can make...
Post 09 Feb 2004, 19:19
View user's profile Send private message ICQ Number Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3502
Location: Bulgaria
JohnFound
n0p wrote:
No, I want to deliver structure in procedure as argument and then to get acces to any element.
How can i tell to compiler that the arg1 is structure?


Actually arg1 can't be structure. stdcall parameter passing convention allows only dwords as arguments. You can pass pointer to your structure instead.

Code:

proc  MyProc1
.rect RECT
    enter
.....
    lea eax, [.rect]
    stdcall MyProc2, eax
....
    return

; returns: ecx - width, edx - height of rectangle.
proc MyProc2, ptrRect
    enter
    mov  eax, [ptrRect]
    mov  ecx, [eax+RECT.right]
    mov  edx, [eax+RECT.bottom]
    sub   ecx, [eax+RECT.left]
    sub    edx, [eax+RECT.top]
   return
    


Help this will help
Regards
Post 09 Feb 2004, 19:29
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
n0p



Joined: 06 Jan 2004
Posts: 10
Location: Russia,Novosibirsk
n0p
Thanks a lot! It's realy works and it is what I want! Very Happy

_________________
English isn't my native, so sorry for any mistakes I can make...
Post 09 Feb 2004, 20:13
View user's profile Send private message ICQ Number Reply with quote
Dryobates



Joined: 13 Jul 2003
Posts: 46
Location: Poland
Dryobates
Pushing whole structure on stack isn't good programing style, but if you want that modified macro I think should do this (I don't know is this works Razz ):

Code:
macro proc_ext name,[arg, type]                   ; define procedure
{
  common
    name:
    virtual at ebp+8
      if ~ arg eq
   forward
        arg type
   common
     end if
     ..ret = $ - (ebp+8)
    end virtual
    local ..dynamic_data,..dynamic_size
    dynamic_data equ ..dynamic_data
    dynamic_size equ ..dynamic_size
    virtual at ebp - dynamic_size
     dynamic_data: }

struc some_str {
    .val1 rd 4
    .val2 dd ?
}


proc_ext PP, var, some_str
    enter
    mov eax, [var.val1+4*2]
    return    


But how to push structure on stack you have to think.
Post 09 Feb 2004, 22:10
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger ICQ Number 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.