flat assembler
Message board for the users of flat assembler.

Index > Main > [fasmg] $ = $ - 123

Author
Thread Post new topic Reply to topic
_shura



Joined: 22 May 2015
Posts: 61
_shura 03 Aug 2017, 15:21
Ohai,
is there a way to set the current pointer in file/virtual, so a `db num` would overwrite already written data?
I can get the current position in virtual with `$`, but if i change its value, it does change the value of `$`, but this neither change the actual position, nor `$` points to the current position anymore.
Well, I could replace `db` with a custom macro, which allocates some bytes with `rb` and then use `store` instead. I already solved it that way, but I really do not like it this way. Its a mess,
I guess, this is the only way?
Post 03 Aug 2017, 15:21
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8358
Location: Kraków, Poland
Tomasz Grysztar 03 Aug 2017, 19:01
STORE is the only way to modify already assembled data. But you could use some nice wrapper macro to make this less clunky:
Code:
macro at? address
        virtual at address
        macro end?.at?
                local buffer,size
                load buffer:$-$$ from $$
                end virtual
                store buffer:lengthof buffer at address
                purge end?.at?
        end macro
end macro    
Code:
; example of use:

repeat 256
        db %-1
end repeat

at 30h
        db 'test'
        dd 0
end at    
The macro can also be extended to allow modifying other addressing spaces:
Code:
macro at? target
        local place,addr
        match space:address, target
                virtual at address
        else
                virtual at target
        end match
        macro end?.at?
                local buffer,size
                load buffer:$-$$ from $$
                end virtual
                store buffer:lengthof buffer at target
                purge end?.at?
        end macro
end macro    
Code:
; example of use:

first::
repeat 128
        db %-1
end repeat

org 0

second::
repeat 128
        db %-1
end repeat

at first:30h
        db 'test'
        dd 0
end at    
Post 03 Aug 2017, 19:01
View user's profile Send private message Visit poster's website Reply with quote
_shura



Joined: 22 May 2015
Posts: 61
_shura 03 Aug 2017, 23:05
ohai,
thank you, but I solved it a bit different now.
With virtuals too, but in a non-generic way.
I do not overwrite existing data, I create data only if finally done.
Anyway, I like your solution too^^, but it could be a nice-to-have if I just have to set another value to $/$% to change the position.
Post 03 Aug 2017, 23:05
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.