flat assembler
Message board for the users of flat assembler.

Index > Main > using struct?

Author
Thread Post new topic Reply to topic
dosin



Joined: 24 Aug 2007
Posts: 337
dosin
I ran across this is the manual..
Code:
struc point x,y
     {
  .x dw x
     .y dw y
     }
    


would it be possible to:

Code:
struct 3d
{

.x dd 0
.y dd 0
.z dd 0

}3d_points
    


and how to use a struct with the regs..

mov eax,[3d_points.x]?
Post 11 Dec 2007, 04:50
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4242
Location: 2018
edfed
when building a dot, you know the structure, X,Y
when building a box, you know the structure X,Y,XL,YL,color
when building a 3D poligon, you know the structure P1,P2,P3
etc etc...
i don't use the struct macro.
structure can be done with memory directive and a related equate ??.
Code:
point:     ;related equate
X=0
Y=4
points:   ;structure
.1 dd 0,0 ;one point
.2 dd 4,8 
onedot dd 10,10

mov esi,points
mov eax,[esi+point.X]
add esi,8
mov ebx,[esi+point.Y]
mov esi,onedot
mov ecx,[esi+point.Y]

    


there are frequent bugs when structure is not clear
but with this i don't need the struct directive... Smile
Post 11 Dec 2007, 05:52
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17665
Location: In your JS exploiting you and your system
revolution
dosin: struc and struct are entirely different things. you have mixed them together in your post.

struc is an assembler preprocessor directive. It is similar to 'macro' with one minor difference that the expanded structure must have a naming label.

struct (with the extra 't') is a macro if you include the standard fasm file 'struct.inc'. If you don't include this file then struct is undefined. Also the struct macro as used in the fasm include file does not use the curly braces {}, you should terminate it with 'ends' and don't use the dots for the internal labels.
Code:
;define the macro structure
struct THREE_D
 x dd ?
 y dd ?
 z dd ?
ends

;instantiate it
my_point THREE_D

;access a value
mov rax,[my_point.x]
    
Post 11 Dec 2007, 07:21
View user's profile Send private message Visit poster's website Reply with quote
dosin



Joined: 24 Aug 2007
Posts: 337
dosin
lol! struct from programming C/C++... from typing it so much I added the t.

I just have never used the struct in asm I have seen it a few times but not known how to use it!

Well I can't use macros.. I am thinking I have a way around not using it!


Thanks for both the post!
Post 11 Dec 2007, 08:04
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-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.