flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
JohnFound 18 Oct 2004, 10:53
x0r wrote: Why this code won't compile ?? Check for macroses struct...ends in FASM package includes. Actually in is included in win32ax.inc Use it this way: Code:
include '%fasminc%/win32ax.inc'
.data
struct tmp
.x db ?
.y db ?
ends
fred tmp
Another question: How can I create a variable pointing to the struct tmp ? Like this in C: You can't (of course) because structures are abstractions and pointer to it is not actually possible. On other hand, FASM doesn't use type checking and casts, so you simply don't need such features. If you have instance of given structure, you can get pointer to it very easy, using the nama of the field: Code: struct test a db ? b db ? ends testinstance test ; variable of type "test" mov eax, testinstance.a ; now eax contains pointer to testinstance. lea eax, [testinstance.b] ; the same using lea instructions. btw, if testinstance is local variable of the procedure, this is the only way. mov [eax], 'A' ; store character "A" in the testinstance.b ; Another way, more readable, especially for complex structures: lea eax, [testinstance] ; pointer to the whole structure. mov [eax+test.b], "A" ; offset to needed field. Regards |
|||
![]() |
|
vid 18 Oct 2004, 11:17
without macro features:
Code: ;defines struct struct tmp { .x dd ? .y dd ? } ;defines virtual structure "tmp" named "tmp" ;so labels "tmp.x" and "tmp.y" get defined, tmp.x = 0, tmp.y = 4 virtual at 0 tmp tmp sizeof.tmp = $ ;size of tmp end virtual ;defines static structure fred tmp ;defines pointer to structure ptr_tmp dd 0 ;pointer is just normal dword like any other ;code mov [tmp.x],0 mov eax,[ptr_tmp] ;load address of structure from pointer mov [eax + tmp.x],5 ;eg. mov [eax + 0],5 mov [eax + tmp.y],10 ;eg. mov [eax + 4],10 |
|||
![]() |
|
x0r 18 Oct 2004, 12:30
Ok thanks for your help, my problem was on the structure declaration.
@+ |
|||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.