flat assembler
Message board for the users of flat assembler.

Index > Main > Using virtual in macro

Author
Thread Post new topic Reply to topic
hellomachine



Joined: 18 May 2023
Posts: 22
Location: I don't even exist
hellomachine 19 May 2023, 20:41
Hello, i tried to create a macro for virtual process but i got illegal instruction error
Code:
macro virtual_define_size \
 [v_label] {
  forward
   virtual #v_label
    #v_label#.size = $ - $$
   end virtual
}    

What is the problem?

_________________
JESUS _F_ CHRIST
Post 19 May 2023, 20:41
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20355
Location: In your JS exploiting you and your system
revolution 19 May 2023, 21:21
"virtual #v_label" get joined to a single "virtualv_label". Remove the leading #.
Post 19 May 2023, 21:21
View user's profile Send private message Visit poster's website Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 978
Location: Russia
macomics 19 May 2023, 22:28
Code:
macro virtual_define_size [v_label] { forward label v_label#.size at ( $ - v_label ) }    
Post 19 May 2023, 22:28
View user's profile Send private message Reply with quote
hellomachine



Joined: 18 May 2023
Posts: 22
Location: I don't even exist
hellomachine 20 May 2023, 05:38
revolution wrote:
"virtual #v_label" get joined to a single "virtualv_label". Remove the leading #.


Is this correct (for defining a virtual and using
Code:
db    
to define its bytes) ?

Code:
macro v_define \
[virtual_label] {
  forward
   virtual virtual_label#
    #virtual_label#.size = $ - $$
   end virtual
   #virtual_label#.start:
   repeat virtual_label#.size
    load a BYTE from virtual_label#:%-1
    db a
   end repeat }
    


I got no error from this, but i afraid there might be a hidden problem !

_________________
JESUS _F_ CHRIST
Post 20 May 2023, 05:38
View user's profile Send private message Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 978
Location: Russia
macomics 20 May 2023, 11:16
Code:
macro v_define [virtual_label] { common label virtual_label#.size at ( $ - $$ )
  forward virtual_label#.start: repeat virtual_label#.size
    load a BYTE from virtual_label: ( % - 1 )
    db a
   end repeat }

virtual
a::
db 256 dup $
end virtual
v_define a    
Code:
~ $ fasm -m 1024 test.asm
flat assembler  version 1.73.30  (1024 kilobytes memory)
1 passes, 0 bytes.    

0 bytes - because $ - $$ = 0
It is necessary to calculate the size inside the virtual block, then the value will be correct (256)

Code:
macro v_define [virtual_label] { common local a
  forward virtual_label#.start: repeat virtual_label#.size
    load a BYTE from virtual_label: ( % - 1 )
    db a
   end repeat }

virtual
a::
db 256 dup $
label a.size at ( $ - $$ )
end virtual
v_define a    

Code:
~ $ fasm -m 1024 test.asm
flat assembler  version 1.73.30  (1024 kilobytes memory)
1 passes, 256 bytes.    
Code:
~ $ hexdump -C ./test.bin
00000000  00 01 02 03 04 05 06 07  08 09 0a 0b 0c 0d 0e 0f  |................|
00000010  10 11 12 13 14 15 16 17  18 19 1a 1b 1c 1d 1e 1f  |................|
00000020  20 21 22 23 24 25 26 27  28 29 2a 2b 2c 2d 2e 2f  | !"#$%&'()*+,-./|
00000030  30 31 32 33 34 35 36 37  38 39 3a 3b 3c 3d 3e 3f  |0123456789:;<=>?|
00000040  40 41 42 43 44 45 46 47  48 49 4a 4b 4c 4d 4e 4f  |@ABCDEFGHIJKLMNO|
00000050  50 51 52 53 54 55 56 57  58 59 5a 5b 5c 5d 5e 5f  |PQRSTUVWXYZ[\]^_|
00000060  60 61 62 63 64 65 66 67  68 69 6a 6b 6c 6d 6e 6f  |`abcdefghijklmno|
00000070  70 71 72 73 74 75 76 77  78 79 7a 7b 7c 7d 7e 7f  |pqrstuvwxyz{|}~.|
00000080  80 81 82 83 84 85 86 87  88 89 8a 8b 8c 8d 8e 8f  |................|
00000090  90 91 92 93 94 95 96 97  98 99 9a 9b 9c 9d 9e 9f  |................|
000000a0  a0 a1 a2 a3 a4 a5 a6 a7  a8 a9 aa ab ac ad ae af  |................|
000000b0  b0 b1 b2 b3 b4 b5 b6 b7  b8 b9 ba bb bc bd be bf  |................|
000000c0  c0 c1 c2 c3 c4 c5 c6 c7  c8 c9 ca cb cc cd ce cf  |................|
000000d0  d0 d1 d2 d3 d4 d5 d6 d7  d8 d9 da db dc dd de df  |................|
000000e0  e0 e1 e2 e3 e4 e5 e6 e7  e8 e9 ea eb ec ed ee ef  |................|
000000f0  f0 f1 f2 f3 f4 f5 f6 f7  f8 f9 fa fb fc fd fe ff  |................|
00000100    
Post 20 May 2023, 11:16
View user's profile Send private message Reply with quote
hellomachine



Joined: 18 May 2023
Posts: 22
Location: I don't even exist
hellomachine 20 May 2023, 17:55
macomics wrote:
Code:
macro v_define [virtual_label] { common label virtual_label#.size at ( $ - $$ )
  forward virtual_label#.start: repeat virtual_label#.size
    load a BYTE from virtual_label: ( % - 1 )
    db a
   end repeat }

virtual
a::
db 256 dup $
end virtual
v_define a    
Code:
~ $ fasm -m 1024 test.asm
flat assembler  version 1.73.30  (1024 kilobytes memory)
1 passes, 0 bytes.    

0 bytes - because $ - $$ = 0
It is necessary to calculate the size inside the virtual block, then the value will be correct (256)

Code:
macro v_define [virtual_label] { common local a
  forward virtual_label#.start: repeat virtual_label#.size
    load a BYTE from virtual_label: ( % - 1 )
    db a
   end repeat }

virtual
a::
db 256 dup $
label a.size at ( $ - $$ )
end virtual
v_define a    

Code:
~ $ fasm -m 1024 test.asm
flat assembler  version 1.73.30  (1024 kilobytes memory)
1 passes, 256 bytes.    
Code:
~ $ hexdump -C ./test.bin
00000000  00 01 02 03 04 05 06 07  08 09 0a 0b 0c 0d 0e 0f  |................|
00000010  10 11 12 13 14 15 16 17  18 19 1a 1b 1c 1d 1e 1f  |................|
00000020  20 21 22 23 24 25 26 27  28 29 2a 2b 2c 2d 2e 2f  | !"#$%&'()*+,-./|
00000030  30 31 32 33 34 35 36 37  38 39 3a 3b 3c 3d 3e 3f  |0123456789:;<=>?|
00000040  40 41 42 43 44 45 46 47  48 49 4a 4b 4c 4d 4e 4f  |@ABCDEFGHIJKLMNO|
00000050  50 51 52 53 54 55 56 57  58 59 5a 5b 5c 5d 5e 5f  |PQRSTUVWXYZ[\]^_|
00000060  60 61 62 63 64 65 66 67  68 69 6a 6b 6c 6d 6e 6f  |`abcdefghijklmno|
00000070  70 71 72 73 74 75 76 77  78 79 7a 7b 7c 7d 7e 7f  |pqrstuvwxyz{|}~.|
00000080  80 81 82 83 84 85 86 87  88 89 8a 8b 8c 8d 8e 8f  |................|
00000090  90 91 92 93 94 95 96 97  98 99 9a 9b 9c 9d 9e 9f  |................|
000000a0  a0 a1 a2 a3 a4 a5 a6 a7  a8 a9 aa ab ac ad ae af  |................|
000000b0  b0 b1 b2 b3 b4 b5 b6 b7  b8 b9 ba bb bc bd be bf  |................|
000000c0  c0 c1 c2 c3 c4 c5 c6 c7  c8 c9 ca cb cc cd ce cf  |................|
000000d0  d0 d1 d2 d3 d4 d5 d6 d7  d8 d9 da db dc dd de df  |................|
000000e0  e0 e1 e2 e3 e4 e5 e6 e7  e8 e9 ea eb ec ed ee ef  |................|
000000f0  f0 f1 f2 f3 f4 f5 f6 f7  f8 f9 fa fb fc fd fe ff  |................|
00000100    


Hello, thanks for your codes, but your second v_define is equal to mine. Right ? Or I missed something ? I also, calculated the virtual's size in virtual ... end virtual ...

_________________
JESUS _F_ CHRIST
Post 20 May 2023, 17:55
View user's profile Send private message Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 978
Location: Russia
macomics 20 May 2023, 18:16
Here are the comments for the second code
Code:
macro v_define [virtual_label] ; Declaring the v_define macro
{
  common ; The following lines will be executed once per macro call
    local a ; Declare the local name [b]a[/b] in the macro in order to use it as a variable and not overwrite the value of the global variable [b]a[/b]
  forward ; The following lines will be executed for each macro argument (*)
    virtual_label#.start: ; Declaring the block start label (*)
      repeat virtual_label#.size ; Byte-by-byte block copy cycle (*)
        load a BYTE from virtual_label: ( % - 1 ) ; Reading the next byte (*)
        db a ; Copying the value of the next byte (*)
   end repeat ; End of cycle (*)
}

virtual ; Declaring data in the virtual block
a:: ; Data access label from the virtual block
; <- $$
db 256 dup $ ; 256 arbitrary bytes
; <- $
label a.size at ( $ - $$ ) ; Calculating the length of data in the virtual block
end virtual ; End of virtual
; * In this example, the macro lines will be repeated once
v_define a ; Calling a macro with the [b]a[/b] parameter    


Code:
macro v_define [virtual_label] ; Declaring the v_define macro
{
  common ; The following lines will be executed once per macro call
    local a ; Declare the local name [b]a[/b] in the macro in order to use it as a variable and not overwrite the value of the global variable [b]a[/b]
  forward ; The following lines will be executed for each macro argument (*)
    virtual_label#.start: ; Declaring the block start label (*)
      repeat virtual_label#.size ; Byte-by-byte block copy cycle (*)
        load a BYTE from virtual_label: ( % - 1 ) ; Reading the next byte (*)
        db a ; Copying the value of the next byte (*)
   end repeat ; End of cycle (*)
}

virtual ; Declaring data in the virtual block
a:: ; Data access label from the virtual block
; <- $$
db 128 dup $ ; 128 arbitrary bytes
; <- $
label a.size at ( $ - $$ ) ; Calculating the length of data in the virtual block
end virtual ; End of virtual
virtual ; Declaring data in the virtual block
b:: ; Data access label from the virtual block
; <- $$
db 128 dup $ ; 128 arbitrary bytes
; <- $
label b.size at ( $ - $$ ) ; Calculating the length of data in the virtual block
end virtual ; End of virtual
; * In this example, the macro lines will be repeated twice
v_define a, b ; Calling a macro with the [b]a[/b] and [b]b[/b] parameters    
Code:
~ $ fasm -m 1024 test1.asm
flat assembler  version 1.73.30  (1024 kilobytes memory)
1 passes, 256 bytes.
~ $ hexdump -C ./test1.bin
00000000  00 01 02 03 04 05 06 07  08 09 0a 0b 0c 0d 0e 0f  |................|
00000010  10 11 12 13 14 15 16 17  18 19 1a 1b 1c 1d 1e 1f  |................|
00000020  20 21 22 23 24 25 26 27  28 29 2a 2b 2c 2d 2e 2f  | !"#$%&'()*+,-./|
00000030  30 31 32 33 34 35 36 37  38 39 3a 3b 3c 3d 3e 3f  |0123456789:;<=>?|
00000040  40 41 42 43 44 45 46 47  48 49 4a 4b 4c 4d 4e 4f  |@ABCDEFGHIJKLMNO|
00000050  50 51 52 53 54 55 56 57  58 59 5a 5b 5c 5d 5e 5f  |PQRSTUVWXYZ[\]^_|
00000060  60 61 62 63 64 65 66 67  68 69 6a 6b 6c 6d 6e 6f  |`abcdefghijklmno|
00000070  70 71 72 73 74 75 76 77  78 79 7a 7b 7c 7d 7e 7f  |pqrstuvwxyz{|}~.|
00000080  80 81 82 83 84 85 86 87  88 89 8a 8b 8c 8d 8e 8f  |................|
00000090  90 91 92 93 94 95 96 97  98 99 9a 9b 9c 9d 9e 9f  |................|
000000a0  a0 a1 a2 a3 a4 a5 a6 a7  a8 a9 aa ab ac ad ae af  |................|
000000b0  b0 b1 b2 b3 b4 b5 b6 b7  b8 b9 ba bb bc bd be bf  |................|
000000c0  c0 c1 c2 c3 c4 c5 c6 c7  c8 c9 ca cb cc cd ce cf  |................|
000000d0  d0 d1 d2 d3 d4 d5 d6 d7  d8 d9 da db dc dd de df  |................|
000000e0  e0 e1 e2 e3 e4 e5 e6 e7  e8 e9 ea eb ec ed ee ef  |................|
000000f0  f0 f1 f2 f3 f4 f5 f6 f7  f8 f9 fa fb fc fd fe ff  |................|
00000100
~ $ fasm -m 1024 test2.asm
flat assembler  version 1.73.30  (1024 kilobytes memory)
1 passes, 256 bytes.
~ $ hexdump -C ./test2.bin
00000000  00 01 02 03 04 05 06 07  08 09 0a 0b 0c 0d 0e 0f  |................|
00000010  10 11 12 13 14 15 16 17  18 19 1a 1b 1c 1d 1e 1f  |................|
00000020  20 21 22 23 24 25 26 27  28 29 2a 2b 2c 2d 2e 2f  | !"#$%&'()*+,-./|
00000030  30 31 32 33 34 35 36 37  38 39 3a 3b 3c 3d 3e 3f  |0123456789:;<=>?|
00000040  40 41 42 43 44 45 46 47  48 49 4a 4b 4c 4d 4e 4f  |@ABCDEFGHIJKLMNO|
00000050  50 51 52 53 54 55 56 57  58 59 5a 5b 5c 5d 5e 5f  |PQRSTUVWXYZ[\]^_|
00000060  60 61 62 63 64 65 66 67  68 69 6a 6b 6c 6d 6e 6f  |`abcdefghijklmno|
00000070  70 71 72 73 74 75 76 77  78 79 7a 7b 7c 7d 7e 7f  |pqrstuvwxyz{|}~.|
00000080  00 01 02 03 04 05 06 07  08 09 0a 0b 0c 0d 0e 0f  |................|
00000090  10 11 12 13 14 15 16 17  18 19 1a 1b 1c 1d 1e 1f  |................|
000000a0  20 21 22 23 24 25 26 27  28 29 2a 2b 2c 2d 2e 2f  | !"#$%&'()*+,-./|
000000b0  30 31 32 33 34 35 36 37  38 39 3a 3b 3c 3d 3e 3f  |0123456789:;<=>?|
000000c0  40 41 42 43 44 45 46 47  48 49 4a 4b 4c 4d 4e 4f  |@ABCDEFGHIJKLMNO|
000000d0  50 51 52 53 54 55 56 57  58 59 5a 5b 5c 5d 5e 5f  |PQRSTUVWXYZ[\]^_|
000000e0  60 61 62 63 64 65 66 67  68 69 6a 6b 6c 6d 6e 6f  |`abcdefghijklmno|
000000f0  70 71 72 73 74 75 76 77  78 79 7a 7b 7c 7d 7e 7f  |pqrstuvwxyz{|}~.|
00000100    
Post 20 May 2023, 18:16
View user's profile Send private message Reply with quote
hellomachine



Joined: 18 May 2023
Posts: 22
Location: I don't even exist
hellomachine 20 May 2023, 19:27
macomics wrote:
Here are the comments for the second code
Code:
macro v_define [virtual_label] ; Declaring the v_define macro
{
  common ; The following lines will be executed once per macro call
    local a ; Declare the local name [b]a[/b] in the macro in order to use it as a variable and not overwrite the value of the global variable [b]a[/b]
  forward ; The following lines will be executed for each macro argument (*)
    virtual_label#.start: ; Declaring the block start label (*)
      repeat virtual_label#.size ; Byte-by-byte block copy cycle (*)
        load a BYTE from virtual_label: ( % - 1 ) ; Reading the next byte (*)
        db a ; Copying the value of the next byte (*)
   end repeat ; End of cycle (*)
}

virtual ; Declaring data in the virtual block
a:: ; Data access label from the virtual block
; <- $$
db 256 dup $ ; 256 arbitrary bytes
; <- $
label a.size at ( $ - $$ ) ; Calculating the length of data in the virtual block
end virtual ; End of virtual
; * In this example, the macro lines will be repeated once
v_define a ; Calling a macro with the [b]a[/b] parameter    


Code:
macro v_define [virtual_label] ; Declaring the v_define macro
{
  common ; The following lines will be executed once per macro call
    local a ; Declare the local name [b]a[/b] in the macro in order to use it as a variable and not overwrite the value of the global variable [b]a[/b]
  forward ; The following lines will be executed for each macro argument (*)
    virtual_label#.start: ; Declaring the block start label (*)
      repeat virtual_label#.size ; Byte-by-byte block copy cycle (*)
        load a BYTE from virtual_label: ( % - 1 ) ; Reading the next byte (*)
        db a ; Copying the value of the next byte (*)
   end repeat ; End of cycle (*)
}

virtual ; Declaring data in the virtual block
a:: ; Data access label from the virtual block
; <- $$
db 128 dup $ ; 128 arbitrary bytes
; <- $
label a.size at ( $ - $$ ) ; Calculating the length of data in the virtual block
end virtual ; End of virtual
virtual ; Declaring data in the virtual block
b:: ; Data access label from the virtual block
; <- $$
db 128 dup $ ; 128 arbitrary bytes
; <- $
label b.size at ( $ - $$ ) ; Calculating the length of data in the virtual block
end virtual ; End of virtual
; * In this example, the macro lines will be repeated twice
v_define a, b ; Calling a macro with the [b]a[/b] and [b]b[/b] parameters    
Code:
~ $ fasm -m 1024 test1.asm
flat assembler  version 1.73.30  (1024 kilobytes memory)
1 passes, 256 bytes.
~ $ hexdump -C ./test1.bin
00000000  00 01 02 03 04 05 06 07  08 09 0a 0b 0c 0d 0e 0f  |................|
00000010  10 11 12 13 14 15 16 17  18 19 1a 1b 1c 1d 1e 1f  |................|
00000020  20 21 22 23 24 25 26 27  28 29 2a 2b 2c 2d 2e 2f  | !"#$%&'()*+,-./|
00000030  30 31 32 33 34 35 36 37  38 39 3a 3b 3c 3d 3e 3f  |0123456789:;<=>?|
00000040  40 41 42 43 44 45 46 47  48 49 4a 4b 4c 4d 4e 4f  |@ABCDEFGHIJKLMNO|
00000050  50 51 52 53 54 55 56 57  58 59 5a 5b 5c 5d 5e 5f  |PQRSTUVWXYZ[\]^_|
00000060  60 61 62 63 64 65 66 67  68 69 6a 6b 6c 6d 6e 6f  |`abcdefghijklmno|
00000070  70 71 72 73 74 75 76 77  78 79 7a 7b 7c 7d 7e 7f  |pqrstuvwxyz{|}~.|
00000080  80 81 82 83 84 85 86 87  88 89 8a 8b 8c 8d 8e 8f  |................|
00000090  90 91 92 93 94 95 96 97  98 99 9a 9b 9c 9d 9e 9f  |................|
000000a0  a0 a1 a2 a3 a4 a5 a6 a7  a8 a9 aa ab ac ad ae af  |................|
000000b0  b0 b1 b2 b3 b4 b5 b6 b7  b8 b9 ba bb bc bd be bf  |................|
000000c0  c0 c1 c2 c3 c4 c5 c6 c7  c8 c9 ca cb cc cd ce cf  |................|
000000d0  d0 d1 d2 d3 d4 d5 d6 d7  d8 d9 da db dc dd de df  |................|
000000e0  e0 e1 e2 e3 e4 e5 e6 e7  e8 e9 ea eb ec ed ee ef  |................|
000000f0  f0 f1 f2 f3 f4 f5 f6 f7  f8 f9 fa fb fc fd fe ff  |................|
00000100
~ $ fasm -m 1024 test2.asm
flat assembler  version 1.73.30  (1024 kilobytes memory)
1 passes, 256 bytes.
~ $ hexdump -C ./test2.bin
00000000  00 01 02 03 04 05 06 07  08 09 0a 0b 0c 0d 0e 0f  |................|
00000010  10 11 12 13 14 15 16 17  18 19 1a 1b 1c 1d 1e 1f  |................|
00000020  20 21 22 23 24 25 26 27  28 29 2a 2b 2c 2d 2e 2f  | !"#$%&'()*+,-./|
00000030  30 31 32 33 34 35 36 37  38 39 3a 3b 3c 3d 3e 3f  |0123456789:;<=>?|
00000040  40 41 42 43 44 45 46 47  48 49 4a 4b 4c 4d 4e 4f  |@ABCDEFGHIJKLMNO|
00000050  50 51 52 53 54 55 56 57  58 59 5a 5b 5c 5d 5e 5f  |PQRSTUVWXYZ[\]^_|
00000060  60 61 62 63 64 65 66 67  68 69 6a 6b 6c 6d 6e 6f  |`abcdefghijklmno|
00000070  70 71 72 73 74 75 76 77  78 79 7a 7b 7c 7d 7e 7f  |pqrstuvwxyz{|}~.|
00000080  00 01 02 03 04 05 06 07  08 09 0a 0b 0c 0d 0e 0f  |................|
00000090  10 11 12 13 14 15 16 17  18 19 1a 1b 1c 1d 1e 1f  |................|
000000a0  20 21 22 23 24 25 26 27  28 29 2a 2b 2c 2d 2e 2f  | !"#$%&'()*+,-./|
000000b0  30 31 32 33 34 35 36 37  38 39 3a 3b 3c 3d 3e 3f  |0123456789:;<=>?|
000000c0  40 41 42 43 44 45 46 47  48 49 4a 4b 4c 4d 4e 4f  |@ABCDEFGHIJKLMNO|
000000d0  50 51 52 53 54 55 56 57  58 59 5a 5b 5c 5d 5e 5f  |PQRSTUVWXYZ[\]^_|
000000e0  60 61 62 63 64 65 66 67  68 69 6a 6b 6c 6d 6e 6f  |`abcdefghijklmno|
000000f0  70 71 72 73 74 75 76 77  78 79 7a 7b 7c 7d 7e 7f  |pqrstuvwxyz{|}~.|
00000100    


Thank you, a useful example.

_________________
JESUS _F_ CHRIST
Post 20 May 2023, 19:27
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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.