flat assembler
Message board for the users of flat assembler.

Index > Main > How to use address space identifiers?

Author
Thread Post new topic Reply to topic
Roman



Joined: 21 Apr 2012
Posts: 1969
Roman 20 Jun 2025, 05:49
fasmw 1.73
Code:
dat1 dd 2 ;main code can dynamically changed dat1

macro a0 { inc eax }
macro a1 { dec eax }
macro a2 { sub eax,10 }

macro get { load b byte from dat1:0
a#b }

    


I try this and get 0
Code:
section '.code' code  writeable executable
curmacr:: db 2
      


Start:  load brr byte from curmacr:0
        display brr+48  ;=0 but must be 2
    
Post 20 Jun 2025, 05:49
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20689
Location: In your JS exploiting you and your system
revolution 20 Jun 2025, 06:11
The offset inside "curmacr" must point to the value to read:
Code:
format pe 
section '.code' code  writeable executable
my_value:
curmacr:: db 2

Start:  load brr byte from curmacr:my_value
        display brr+48  ;="2"    
"curmacr" is an address space identifier. It isn't a label value.
Post 20 Jun 2025, 06:11
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20689
Location: In your JS exploiting you and your system
revolution 20 Jun 2025, 06:20
Note that the original code gives an error, the "0" is just an artefact of the way the assembler works by using zero as a place-holder for all unknown values. So the actual result is a value out of range at offset 0 in the currmac address space. The assembler say exactly that:
Code:
flat assembler  version 1.73.31  (16384 kilobytes memory)
0
test.asm [8]:
Start:  load brr byte from curmacr:0
processed: Start:load brr byte from curmacr:0
error: value out of range.    
Post 20 Jun 2025, 06:20
View user's profile Send private message Visit poster's website Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1969
Roman 20 Jun 2025, 08:38
this variant not working.
Code:
my_value:
curmacr:: db 2
macro kk  {  load tuu byte from curmacr:my_value
     mov ebp,tuu
 }  
kk 
         inc byte [my_value]
         kk  
    

I get two times mov ebp,2

I expected mov ebp,2 and mov ebp,3


Last edited by Roman on 20 Jun 2025, 08:41; edited 2 times in total
Post 20 Jun 2025, 08:38
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20689
Location: In your JS exploiting you and your system
revolution 20 Jun 2025, 08:46
load is evaluated at assembly time.
inc is evaluated at runtime.

Use store to update a value at assembly time.
Post 20 Jun 2025, 08:46
View user's profile Send private message Visit poster's website Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1969
Roman 20 Jun 2025, 08:52
this work.
Code:
macro kk v {  load tuu byte from curmacr:my_value
          
     mov ebp,tuu
     tuu = tuu+1
     store byte tuu  at curmacr:my_value
 }    
Post 20 Jun 2025, 08:52
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1969
Roman 20 Jun 2025, 08:53
this not work.
Post 20 Jun 2025, 08:53
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20689
Location: In your JS exploiting you and your system
revolution 20 Jun 2025, 08:54
Roman wrote:
this not work.
What "not work"?
Post 20 Jun 2025, 08:54
View user's profile Send private message Visit poster's website Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1969
Roman 20 Jun 2025, 08:58
Shutdown electricy.
Code:
macro a0 { inc eax }
macro a1 { dec eax }
macro a2 { sub eax,10 }
macro kk v {  load tuu byte from curmacr:my_value
          a\#\tuu ;fasm error
     mov ebp,tuu
     tuu = tuu+1
     store byte tuu  at curmacr:my_value
 }    

    


Last edited by Roman on 20 Jun 2025, 09:01; edited 1 time in total
Post 20 Jun 2025, 08:58
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20689
Location: In your JS exploiting you and your system
revolution 20 Jun 2025, 09:00
tuu is a variable, not an equ. So that can never work.

Use if ... else ... end if.
Code:
if tuu = 0
  a0
else if tuu = 1
...    


Last edited by revolution on 20 Jun 2025, 09:02; edited 1 time in total
Post 20 Jun 2025, 09:00
View user's profile Send private message Visit poster's website Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1969
Roman 20 Jun 2025, 09:02
Its bad news for me.
Post 20 Jun 2025, 09:02
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20689
Location: In your JS exploiting you and your system
revolution 20 Jun 2025, 09:03
This is the same problem again. Mixing assembler with the preprocessor.
Post 20 Jun 2025, 09:03
View user's profile Send private message Visit poster's website Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1969
Roman 20 Jun 2025, 09:15
Quote:

Mixing assembler with the preprocessor.

sometimes its needed.
Post 20 Jun 2025, 09:15
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20689
Location: In your JS exploiting you and your system
revolution 20 Jun 2025, 09:17
It is really just a matter of choosing to use either the preprocessor or the assembler, but not both together.

It is, of course, possible to use both together, but often is causes much confusion, so I recommend to not do it without a full understanding of everything involved.

The code above could be written to use the preprocessor completely (no load, store, if, etc.), or it could be written to be all assembler (with load, store, if, else, end. etc.).
Post 20 Jun 2025, 09:17
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8434
Location: Kraków, Poland
Tomasz Grysztar 20 Jun 2025, 10:22
Roman wrote:
Quote:

Mixing assembler with the preprocessor.

sometimes its needed.
And that's why I needed to make a new engine (fasmg) for fasm 2. The first one is stuck with its preprocessor separation.
Post 20 Jun 2025, 10:22
View user's profile Send private message Visit poster's website Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1969
Roman 20 Jun 2025, 10:47
Quote:
And that's why I needed to make a new engine (fasmg) for fasm 2. The first one is stuck with its preprocessor separation.

https://board.flatassembler.net/topic.php?t=23831

This is important accent! And main goal!
And show main difference between fasm1 and fasmg.

I study fasm1 15 years. And today I found out about main difference between fasm1 and fasmg.
Post 20 Jun 2025, 10:47
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20689
Location: In your JS exploiting you and your system
revolution 20 Jun 2025, 11:56
Regarding the topic title: Address space identifiers reference the address space, and not the offset within the space. For example the following uses four address space identifiers, and the output shows that all four identifiers end up being the same thing. A single address space identifier can be placed anywhere within the space and it will reference the entire space.
Code:
virtual at 0x12345678
        address_space_identifier_0::
        var0 db '0'
        address_space_identifier_1::
        var1 db '1'
        address_space_identifier_2::
        var2 db '2'
        address_space_identifier_3::
end virtual

load v00 from address_space_identifier_0:var0
load v01 from address_space_identifier_0:var1
load v02 from address_space_identifier_0:var2
load v10 from address_space_identifier_1:var0
load v11 from address_space_identifier_1:var1
load v12 from address_space_identifier_1:var2
load v20 from address_space_identifier_2:var0
load v21 from address_space_identifier_2:var1
load v22 from address_space_identifier_2:var2

display v00, v01, v02, v10, v11, v12, v20, v21, v22    
Code:
flat assembler  version 1.73.31  (16384 kilobytes memory)
012012012
1 passes, 0 bytes.    
Post 20 Jun 2025, 11:56
View user's profile Send private message Visit poster's website Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1969
Roman 20 Jun 2025, 12:05
Quote:

virtual at 0x12345678
address_space_identifier_0::
var0 db '0'
address_space_identifier_1::
var1 db '1'
address_space_identifier_2::
var2 db '2'
address_space_identifier_3::
end virtual


load v20 from address_space_identifier_2:var0
load v21 from address_space_identifier_2:var1
load v22 from address_space_identifier_2:var2

get '012'. Very unusual logic.
expected in address_space_identifier_2 only var2
Post 20 Jun 2025, 12:05
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20689
Location: In your JS exploiting you and your system
revolution 20 Jun 2025, 12:12
I forgot to include the final identifier:
Code:
...
load v30 from address_space_identifier_3:var0
load v31 from address_space_identifier_3:var1
load v32 from address_space_identifier_3:var2

display v00, v01, v02, v10, v11, v12, v20, v21, v22, v30, v31, v32    
Code:
flat assembler  version 1.73.31  (16384 kilobytes memory)
012012012012
1 passes, 0 bytes.    
It only ever requires one identifier per space, and it can be placed anywhere.
Post 20 Jun 2025, 12:12
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.