flat assembler
Message board for the users of flat assembler.

Index > Main > Help about muti struct

Author
Thread Post new topic Reply to topic
goldenspider



Joined: 16 May 2011
Posts: 38
goldenspider 10 Oct 2011, 03:46
I want to know ,fasm can complete the code like test function?

Code:
#include <stdio.h>

typedef struct{
    int A;
    int B;
}*myStruct0;

typedef struct{
    int A;
    int C;
    int B;
}*myStruct1;

int AAr[3]={11,12,13};
int test(void * lp,int flag)
{
     if(flag==0)
            return ((myStruct0)lp)->B;
        
     return ((myStruct1)lp)->B;
}
int main()
{   
    myStruct0 AA;
    myStruct1 BB;
    
    printf("%d\n",test(AAr,1));
    printf("%d\n",test(AAr,0));

     return 0;
}
    
Post 10 Oct 2011, 03:46
View user's profile Send private message Reply with quote
AsmGuru62



Joined: 28 Jan 2004
Posts: 1617
Location: Toronto, Canada
AsmGuru62 10 Oct 2011, 11:25
FASM can do any C/C++ code, like any other assembler.
Code:
virtual at 0
myStruct0:
  .A dd ?
     .B dd ?
end virtual

virtual at 0
myStruct1:
        .A dd ?
     .C dd ?
     .B dd ?
end virtual
;
; DATA SECTION
;
AAr dd 11,12,13
;
; CODE SECTION
;
   mov     esi, AAr
    push    1
   pop     ecx
 call    test
        nop             ; <-- STOP IN DEBUGGER HERE AND SEE EAX

      dec     ecx
 call    test
        nop             ; <-- STOP IN DEBUGGER HERE AND SEE EAX
;
; FUNCTION test
;
test:
;
; ESI = lp
; ECX = flag
;
        jecxz   .esi_ptr_to_myStruct0

   mov     eax, [esi + myStruct1.B]
    ret

.esi_ptr_to_myStruct0:
       mov     eax, [esi + myStruct0.B]
    ret
    
Post 10 Oct 2011, 11:25
View user's profile Send private message Send e-mail Reply with quote
goldenspider



Joined: 16 May 2011
Posts: 38
goldenspider 10 Oct 2011, 11:40
Thanks AsmGuru62, cool.
Post 10 Oct 2011, 11:40
View user's profile Send private message 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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.