flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > About postpone

Author
Thread Post new topic Reply to topic
Roman



Joined: 21 Apr 2012
Posts: 1852
Roman 09 Apr 2023, 08:11
Fasmw 1.73
My question: postpone in fasm1 is implemented fully and without bugs ?
And did is normally using often postpone in code ?

How i understand pponn = only can support numbers or address(data label names)
Code:
;this ok
mov eax,pponn
   postpone {
        pponn = counn
   }
   counn = 11

;this fasm error
mov eax,pponn
   postpone {
        pponn = counn2 ;fasm error pponn=edx
   }
   counn2 equ edx

;this ok
mov eax,pponn
Couple macros
   arrr equ 1
   postpone {
   if arrr = 1
        pponn = counn
   end if
   if arrr = 0
        pponn = 16
   end if
   }
   counn = 7
    
Post 09 Apr 2023, 08:11
View user's profile Send private message Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 1043
Location: Russia
macomics 09 Apr 2023, 12:38
Code:
postpone { display '1', 13, 10 }
conn db 1
postpone { display '2', 13, 10 }
postpone { display '3', 13, 10
  ponn = '0' }
display ponn, 13, 10
postpone { display '4', 13, 10}    


Code:
$ fasm -m 1024 main.asm
flat assembler  version 1.73.30  (1024 kilobytes memory)
0
1
2
3
4
2 passes, 1 bytes.

$ hexdump -C main.bin
00000000  01                                                |.|
00000001
    
Post 09 Apr 2023, 12:38
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20459
Location: In your JS exploiting you and your system
revolution 09 Apr 2023, 12:44
You can't forward reference in the preprocessor.

Since all postpone blocks are placed at the end, then anything in them must allow forward referencing, or it won't work.
Post 09 Apr 2023, 12:44
View user's profile Send private message Visit poster's website Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 1043
Location: Russia
macomics 09 Apr 2023, 14:27
Code:
postpone { display '1', 13, 10 }
conn db 1
postpone { display '2', 13, 10 }
display ponn, 13, 10 ; forward reference
postpone { display '3', 13, 10
  ponn = '0' } ; once assigned
postpone { display '4', 13, 10}    


Code:
$ fasm -m 1024 main.asm
flat assembler  version 1.73.30  (1024 kilobytes memory)
0
1
2
3
4
2 passes, 1 bytes.

$ hexdump -C main.bin
00000000  01                                                |.|
00000001    
Post 09 Apr 2023, 14:27
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1852
Roman 09 Apr 2023, 15:04
Interesting this.
Code:
define    cii iipp1
          cii equ iipp2
          cii equ [esi+iipp3]
irpv v,cii { mov eax,v
                display 'pon;;',13,10
                }

postpone {
                iipp1 = 1 ;this work without postpone too for irpv.
                iipp2 = 2
                iipp3 = 8
                } 
    


Last edited by Roman on 09 Apr 2023, 16:22; edited 2 times in total
Post 09 Apr 2023, 15:04
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20459
Location: In your JS exploiting you and your system
revolution 09 Apr 2023, 15:15
Sorry, I'll try to be more clear.

You can forward reference in the assembler, so using "=" works fine. The assembler is multi-pass.

You can't forward reference in the preprocessor. So "equ", "define", etc. can't be forward referenced. The preprocessor is single-pass.
Post 09 Apr 2023, 15:15
View user's profile Send private message Visit poster's website Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1852
Roman 09 Apr 2023, 19:41
https://github.com/tgrysztar/fasm/blob/master/FASM.TXT?ysclid=lg9sw0tcgl458992975#L4342
Quote:

The "postpone" directive can be used to define a special type of
macroinstruction that has no name or arguments and will get automatically
called when the preprocessor reaches the end of source:

postpone
{
code_size = $
}

It is a very simplified kind of macroinstruction and it simply delegates a
block of instructions to be put at the end.

Cool , but I'm confused and don't understand why it's useful and when it's necessary ?

Quote:
will get automatically
called when the preprocessor reaches the end of source

And why is profitable, do this in the end of source ?
Code:
mov eax,pponn ;ida pro show mov eax,11 , but absent inc edi
   postpone {
        pponn = counn
        inc edi ;this ignored or put in another place ?
   }
   counn = 11
    
Post 09 Apr 2023, 19:41
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4079
Location: vpcmpistri
bitRAKE 09 Apr 2023, 21:16
Do you ever create a resource you want to clean up later? Sometimes we don't know when is later. So, we can setup for cleanup later - whenever that is. This could be the finalization of a symbol based on prior work - this is rather common.
Code:
tally = 0
postpone { TOTAL = tally }
macro bit_gravy count {
        tally = tally + count
}

; we don't know how many bits are needed
; (imagine many consumers)

bit_gravy 23
bit_gravy 11
bit_gravy 71

rb (TOTAL+7) shr 3 ; enough space dynamically    
* Sorry, I always run out of gravy - no telling how much people want. Very Happy
Post 09 Apr 2023, 21:16
View user's profile Send private message Visit poster's website Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 1043
Location: Russia
macomics 09 Apr 2023, 21:42
Code:
macro proc name, [args] { name:
    postpone \{ if definite name#.stackFrame
            name#.stackFrameSize = name#.stackFrame
        end if \}
...

macro invoke name, args& { ...

        call    name
    if ~ args eq
        if .count <> 0 & name#.stackFrame < .count
            name#.stackFrame = .count
...
        end if
        .count = 0
    end if    
Here, for example, what postpone can be used. Each function has a label name that contains a cumulative value for routines that do not release arguments from the stack. Whereas when declaring a function, a situation may arise when referring to an unknown value. To do this, another variable is declared, the value of which is assigned at the very end of the program only once. In this way, you can calculate the maximum number of bytes that you want to reserve in the stack of this function, so that you do not have to constantly align the stack pointer.

P.S. This is an example of my macros that I use. In standard macros, the same operation is calculated in the end macro.
Post 09 Apr 2023, 21:42
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1852
Roman 10 Apr 2023, 04:08
BitRake
Code:
tally = 0
postpone { TOTAL = tally }
macro bit_gravy count {
        tally = tally + count
}

; we don't know how many bits are needed
; (imagine many consumers)

bit_gravy 23
bit_gravy 11
bit_gravy 71
rb (TOTAL+7) shr 3
;why not used this? Without postpone
rb (tally+7) shr 3
    
Post 10 Apr 2023, 04:08
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4079
Location: vpcmpistri
bitRAKE 10 Apr 2023, 05:10
Roman, We can always unwrap macros and just list the instructions we want to use. Why use any macro? Think about it this way then:
Code:
postpone {
  purge bit_gravy ; no more gravy
  Gravy db (tally+7) shr 3  ; enough space dynamically
}
tally = 0
macro bit_gravy count {
  tally = tally + count
}    
... we never need to change the above code. It's done - no matter how we want to use it. We just include it and use the macro. We would need to assume that bit_gravy is the only thing changing tally, and then we have this encapsulated abstraction. It could always be broken/circumvented depending on how we want to use the abstraction. It's just a toy example.

Not all abstractions are [always] useful.

There are also some good examples in the fasm package - have you looked at those?

_________________
¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup
Post 10 Apr 2023, 05:10
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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.