flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > How can i define data right?

Author
Thread Post new topic Reply to topic
terex



Joined: 31 Dec 2003
Posts: 16
Location: Saint-Petersburg, Russia
terex
I mean following. To define any internal type of data i can wtite something like this:
Code:
db 'a'
    

Is it possible to do so with user defined types?

I have defined structure:
Code:
; sructure for interrupt-gate descriptor
struc idts sel, off
{
   .loff dw off mod 0x10000
   .sel  dw sel
         db 0x0
         db 0xEE
   .hoff dw off / 0x10000
}
    

Now i want to use it with 'times' or 'repeat ... end repeat' directives. I write:
Code:
times 0x100 idts selector, handler_offset
    

The result is 'illegal instruction'. Then i write
Code:
repeat 0x100 
  idts selector, handler_offset
end repeat
    

'illegal instruction' again. One more variant:
Code:
repeat 0x20
    .d#% idts selector, handler_offset
end repeat
    

causes 'illegal instruction'. Last variant:
Code:
repeat 0x20
    .d% idts selector, handler_offset
end repeat
    

'symbol already defined'

I hope u understood what i want to do. How must i write it?

_________________
sorry for my english
Post 09 Jan 2004, 19:51
View user's profile Send private message Visit poster's website Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3500
Location: Bulgaria
JohnFound
Well you can't define labels inside <repeat> structure.
The reason for this is that on the stage where repeat is executed (assembling) all labels are already created (in preprocessing/parsing stage), you simply can't create new.

The simplest solution, if you want to create repeated static data, is to use macroses instead of structs:

Code:
; Note that there are no labels.
macro MyStruc  fld1, fld2, fld3 {
  dd fld1
  db fld2
  db fld3
}

repeat 10000
  MyStruc 3424, 32, 27
end repeat

    


BTW: IMHO in 99.9% of the cases, creating of this kind of data is not very good style of programming. Better create not initialized data and then fill it on run-time.

Regards
Post 09 Jan 2004, 23:14
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
terex



Joined: 31 Dec 2003
Posts: 16
Location: Saint-Petersburg, Russia
terex
Thanks, but i have allready suspected for this way too Wink

JohnFound wrote:
Well you can't define labels inside <repeat> structure.
BTW: IMHO in 99.9% of the cases, creating of this kind of data is not very good style of programming. Better create not initialized data and then fill it on run-time.

It's exactly that 1 percent! I write a simple code for get understanding of pmode interrupts handle. I define selectors for code, data & stack segments so that base = address of place where dos loads my .com app, and size = 64k. I do it spesial for cansel need for calculate addresses of interrupts handlers on run-time. Ofcause, in a real code it is not very good.

_________________
sorry for my english
Post 10 Jan 2004, 01:10
View user's profile Send private message Visit poster's website Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7108
Location: Slovakia
vid
privalov: couldn't you slightly modify 'struc' so it can be used without label preceding it? strutures defined with 'struc' should beheave in my opinion like all other data defines. You can use 'db 5' and 'name db 5' both, but you cant define data with structure without preceding it with label.

Nice workaround for structures without preceding name is just to append all symbol starting with dot to some dummy (local) label.
Post 11 Jan 2004, 11:07
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
terex



Joined: 31 Dec 2003
Posts: 16
Location: Saint-Petersburg, Russia
terex
vid, it's really good idea. Privalov, isn't it? Wink

_________________
sorry for my english
Post 11 Jan 2004, 14:54
View user's profile Send private message Visit poster's website Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3500
Location: Bulgaria
JohnFound
terex wrote:
vid, it's really good idea. Privalov, isn't it? Wink


Well I am not Privalov, but IMHO it is not good idea. Every structure have local labels inside. These labels needs parent label. If you define structure without main label, the local labels inside will be attached to the last global label, that is not very correct.

Regards.
Post 11 Jan 2004, 15:32
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
Tommy



Joined: 17 Jun 2003
Posts: 492
Location: Norway
Tommy
I agree with John! If you need to define data without parent label, use macros instead! Wink
Post 11 Jan 2004, 15:36
View user's profile Send private message Visit poster's website Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7108
Location: Slovakia
vid
john, tommy: i think i explained it badly. I meant, that 'struc' when used withuot label should set current global label to some dummy (local) name, and reset it on the end of struc. Defining both macro and struc for one structure is not very good method.
Post 11 Jan 2004, 16:25
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
terex



Joined: 31 Dec 2003
Posts: 16
Location: Saint-Petersburg, Russia
terex
Hehe Smile I push 'new post' button to write that it may be easy to attach child labels of structures defined without labels to nothing. But later i thinked that i this way we have no prefers defing data as structures without labels. So, we can use macros with no decrase of comfortable. Like Tommy said.

_________________
sorry for my english
Post 11 Jan 2004, 16:29
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 7489
Location: Kraków, Poland
Tomasz Grysztar
The idea behind the current mechanism is that you can define both struc and macro of the same name, with whatever contents (and even syntax) you want in both cases, for example:
Code:
struc RECT left,top,right,bottom
 {
   .left   dd left+0
   .top    dd top+0
   .right  dd right+0
   .bottom dd bottom+0
 }

macro RECT left,top,right,bottom
 {
   .left   dd left
   .top    dd top
   .right  dd right
   .bottom dd bottom
 }
    

First one to use with label, second without it (and in second case its defined the way that forces you to initialize it with some values - just as an example).
Changing it would hurt the whole logic of current fasm's macro system and even make some of the current macro solutions not working (when it started to treat unlabelled RECT at a struc instead of a macro, for instance).
Post 12 Jan 2004, 19:00
View user's profile Send private message Visit poster's website 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-2019, Tomasz Grysztar.

Powered by rwasa.