flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > delayed references

Author
Thread Post new topic Reply to topic
afw2004



Joined: 16 Jun 2005
Posts: 49
Location: Kharkov, Ukraine
afw2004
Suppose I have some macro like this:

Code:
macro m1
{
    dd some_counter
}
    


and

Code:
macro m2
{
   ...
   some_counter = some_counter + 1
   ...
}
    


I want macro m1 to write last value of 'some_counter' (regardless of the position of m1 in the source code).

How to do that?
Post 27 Sep 2006, 07:35
View user's profile Send private message ICQ Number Reply with quote
afw2004



Joined: 16 Jun 2005
Posts: 49
Location: Kharkov, Ukraine
afw2004
Thanks, I guess.

macro m1
{
dd some_counter_complete
}

macro m2
{
...
some_counter = some_counter + 1
...
}

macro m3
{
some_counter_complete = some_counter
}
Post 27 Sep 2006, 08:16
View user's profile Send private message ICQ Number Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7797
Location: Kraków, Poland
Tomasz Grysztar
Section 2.2.1 of manual contains an example of this, BTW.
Post 27 Sep 2006, 08:37
View user's profile Send private message Visit poster's website Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
it's easy:
- numeric constants that are defined only once in source can be forward-referenced, their value is same in entire source
- numeric constants that are defined more than once in source cannot be forward referenced.

so this trick works nice:
Code:
dd final_value
value = 1
value = value + 1
value = value + 1
final_value = value    
Post 27 Sep 2006, 09:48
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
afw2004



Joined: 16 Jun 2005
Posts: 49
Location: Kharkov, Ukraine
afw2004
Thanks
Post 27 Sep 2006, 11:21
View user's profile Send private message ICQ Number Reply with quote
afw2004



Joined: 16 Jun 2005
Posts: 49
Location: Kharkov, Ukraine
afw2004
And one more question.

Suppose i have a counter variable:

macro m1
{
counter = counter + 1
}

Can I generate variables named as some_name#counter (some_name1, some_name2 ...) if counter variable has integer type?
Post 27 Sep 2006, 15:30
View user's profile Send private message ICQ Number Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
Post 27 Sep 2006, 15:46
View user's profile Send private message Reply with quote
afw2004



Joined: 16 Jun 2005
Posts: 49
Location: Kharkov, Ukraine
afw2004
I trying to define symbols such as page1_has_fixup, page2_has_fixup and so on.

Code:
        repeat module_page_count_complete
                dw 0
                dw %
                match curpage,%
                \{
                        page\#curpage\#_has_fixup = 0
                \}
        end repeat

    


And later I retrieve this symbols:

Code:
        fixup_page = offset_from_fsection shr module_shift
        match curpage, fixup_page
        \{
                if page\#curpage\#_has_fixup = 0
                        page\#curpage\#_has_fixup = 1
                        page\#curpage\#_fixup_offset = start_fixup - fixup_records
                end if
        \}
    


But the line "if page\#curpage\#_has_fixup = 0" generates error "Undefined symbol". What is wrong?
Post 29 Sep 2006, 07:07
View user's profile Send private message ICQ Number Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7797
Location: Kraków, Poland
Tomasz Grysztar
afw2004 wrote:
Code:
        repeat module_page_count_complete
                dw 0
                dw %
                match curpage,%
                \{
                        page\#curpage\#_has_fixup = 0
                \}
        end repeat

    

You are mixing the preprocessor code with an assembler code in a way that suggests you think of them at happening at the same time. The preprocessing is a separate process and is done before the actual assembly happens - it also has a different kind of syntax to make it distinguishable, the assembly constructs are block ended with "end" directive, while preprocessor constructs are the block enclosed within braces (also, in general, assembler uses more textual operators, while preprocessor uses a bunch of "cryptic" characters for its additional operations).

I recommend reading the Understanding fasm article first (even though it may still be unfinished), otherwise you'll get constantly confused with how the things work (or don't work) if you make a false assumptions about what should be happening. You must remember you are dealing with two separate layers and languages here.
Post 29 Sep 2006, 07:44
View user's profile Send private message Visit poster's website Reply with quote
afw2004



Joined: 16 Jun 2005
Posts: 49
Location: Kharkov, Ukraine
afw2004
I trying to develop macroses for building VxD files in FASM, but I have not experience with FASM macro processing, so I can't resolve few errors.
The one problem remaining is a building fixup page table table.

If somebody also wants to build VxD drivers, but don't want to use Microsoft DDK, please help me to finish the job.


Description: This is a test source for VxD file
Download
Filename: outptest.asm
Filesize: 552 Bytes
Downloaded: 115 Time(s)

Description: This is a macroses for building VxD files (yet not completed)
Download
Filename: outptest.inc
Filesize: 6.65 KB
Downloaded: 84 Time(s)

Post 29 Sep 2006, 08:13
View user's profile Send private message ICQ Number Reply with quote
afw2004



Joined: 16 Jun 2005
Posts: 49
Location: Kharkov, Ukraine
afw2004
Code:
repeat module_page_count_complete
  dw 0
  dw %
  match curpage,%
  \{
     display 'Init page ', curpage+30h, 0dh, 0ah
     page\#curpage\#_has_fixup = 'no'
     display 'Init page ', page\#curpage\#_has_fixup, 0dh, 0ah; <-- error
  \}
end repeat
    


Line "page\#curpage\#_has_fixup = 'no'" defines some symbol.
But line "display 'Init page ', page\#curpage\#_has_fixup, 0dh, 0ah" generates error. How can I view the value of symbol defined in previus line?
Post 29 Sep 2006, 10:54
View user's profile Send private message ICQ Number Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
afw2004, the "match" gets executed before "%" exists as a number ("repeat" is not in action here). The example I posted is just to use with integers generated by REPT (which is handled by the preprocessor). If you can't generate the number at preprocessor time in any way then forget it but try to make counters using equates (and the REPT trick) or use another approach to get what you want.

remember, preprocessor directives doesn't handle assembly time values (like "%" on "repeat")

Regards

PS: display 'Init page ', page\#curpage\#_has_fixup, 0dh, 0ah; <-- error . Possibly because at assembly time it gets interpreted as
Code:
display 'Init page ', page%_has_fixup, 0dh, 0ah; <-- error    


[edit]
Well Actually the error is a value out of range anyway looks what happens here
Code:
module_page_count_complete = 3

repeat module_page_count_complete
  dw 0 
  dw %
  page%_has_fixup = 'n'
  match curpage,% 
  {
     display 'Init page ', curpage+30h, 0dh, 0ah 
     page#curpage#_has_fixup = page#curpage#_has_fixup + 1
     display 'Init page ', page#curpage#_has_fixup, 0dh, 0ah; <-- error
  }
end repeat    

You will see that clearly "%" has no effect and is always a plain "%" on the three iterations.[/edit]
Post 29 Sep 2006, 13:16
View user's profile Send private message Reply with quote
afw2004



Joined: 16 Jun 2005
Posts: 49
Location: Kharkov, Ukraine
afw2004
Thanks, locodelassembly Smile
Post 29 Sep 2006, 14:16
View user's profile Send private message ICQ Number Reply with quote
afw2004



Joined: 16 Jun 2005
Posts: 49
Location: Kharkov, Ukraine
afw2004
repeat module_page_count_complete
dw 0
dw %
curpage = %
page#curpage#_has_fixup = 'no'
end repeat

Is this code correct?

If curpage = 1 (integer, not string), then what is page#curpage#_has_fixup ? Is it page1_has_fixup or something else?

Is there some way to define symbols such as page1_has_fixup, page2_has_fixup ... page#module_page_count_complete#_has_fixup if module_page_count_complete depend on compiled file size?
Post 29 Sep 2006, 14:33
View user's profile Send private message ICQ Number Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
afw2004, the "#" works only AT PREPROCESSOR TIME and the "=" at assembler time, you defenitivelty can't use the "%" to generate a symbol you must use the REPT trick that Tomasz point me out the past year. I don't know if there is another way but you can't generate new symbols at assembler time for sure.
Post 29 Sep 2006, 16:23
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.