flat assembler
Message board for the users of flat assembler.

Index > Main > Type conversion and an out of topic question

Author
Thread Post new topic Reply to topic
Rookie



Joined: 21 Aug 2003
Posts: 44
Location: Planet Romania
Rookie
1) Is there anyway of performing type convesion in fasm? What I mean is how can I code
pointer->member (for C) or (pointer as type).member (for pascal) in fasm? The way I currently do it is [pointer+manually calculated offset], which does the job, but I was wondering if there is a more elegant way to do it.

2) This question I couldn't decide whether it should be in Compiler Internals or in IDE develomepent, as it concerns both (I think), but not fasm. I was wondering what is the optimal way of storing variables and their values when writing a compiler or interpreter. The solution I stopped upon is a binary tree (I hope this is the right term for it), but I'm just wondering how the professionals do it.

_________________
This is who I choose to be.
Post 18 Aug 2004, 19:41
View user's profile Send private message Reply with quote
mike.dld



Joined: 03 Oct 2003
Posts: 235
Location: Belarus, Minsk
mike.dld
Code:
struct aaa
 .member1 db ?
 .member2 dd ?
ends

mov ebx,[pointer_var]
mov eax,[ebx+aaa.member1]    

or
Code:
struct aaa
 .member1 db ?
 .member2 dd ?
ends
virtual at ebx
 obj aaa
end virtual

mov ebx,[pointer_var]
mov eax,[obj.member1]    
Post 18 Aug 2004, 20:00
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
madmatt



Joined: 07 Oct 2003
Posts: 1045
Location: Michigan, USA
madmatt
To answer your first question, use the rb,rw,rd,rq, .etc, (reserve byte,word,dword,qword, .etc) to create just the offsets into the structure object rather than defining data, like so:
Code:
struct OFFSETS
     .offsetq rq 4 ;reserve 4 offset containing 4 qwords 
     .offsetd rd 1 ;reserve 1 dword offset
     .offsetw rw 5 ;reserve offset containing 5 words
     .offsetb rb 64 ;reserve offset containing 64 bytes, for a string.
ends

mystruc OFFSETS
then to access use, mov ecx,[eax+mystruc.offsetw+(3*2)] ;third offset, 3rd word size data item (    


About your second question, I have some texts that tell you the steps you need to write a compiler, they are fairly old, but you may get some use out of them.
Post 20 Aug 2004, 10:08
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.

Powered by rwasa.