flat assembler
Message board for the users of flat assembler.

Index > Main > Question about calminstructions

Author
Thread Post new topic Reply to topic
the_coder



Joined: 30 Jan 2025
Posts: 2
the_coder 30 Jan 2025, 17:53
Hi all!
I ma trying to use calminstructions in fasmg to create some bytecode, but I ran into some problem. Firstly here the code:
Code:
element reg
element reg.r8  : reg + 0
element reg.r16 : reg + 1
element reg.r32 : reg + 2
element reg.r64 : reg + 3
element reg.f32 : reg + 4
element reg.f64 : reg + 5

repeat 32
        element r#%#b?  : reg.r8 + %
        element r#%#w?  : reg.r16 + %
        element r#%#d?  : reg.r32 + %
        element r#%#q?  : reg.r64 + %
        element r#%#f?  : reg.f32 + %
        element r#%#fd? : reg.f64 + %
end repeat

calminstruction parse_operand op
        local size_byte, second_byte
        local reg_index, reg_size
        compute reg_index, 0 scaleof op
        compute reg_size, 1 metadataof (1 metadataof op) - reg

        arrange size_byte, =db reg_size
        arrange second_byte, =db reg_index

        assemble size_byte
        assemble second_byte
end calminstruction

org 0
parse_operand r3f
    

In this code I have defined 32 registers, each of which can be used in 8, 16, 32 and 64-bit modes. Also here is calminstruction "parse_operand" which I use to parse register. This calminstruction must assemble two bytes: first byte defines size (8,16,32 or 64-bit) and second byte defines register index. In this example I use "parse_operand r3f", it compiles successful and first byte is correct. But second byte always zero and does not depend on register number. To get register number in "parse_operand" I use command "compute reg_index, 0 scaleof op", where I am wrong?
Post 30 Jan 2025, 17:53
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8367
Location: Kraków, Poland
Tomasz Grysztar 30 Jan 2025, 18:36
"r3f" is the same as "0+1*r3f". "0 scaleof" is always 0. You need to apply it to "1 metadataof r3f", which gives "reg.f32 + 3". Try:
Code:
        compute reg_index, 0 scaleof 1 metadataof op    
Post 30 Jan 2025, 18:36
View user's profile Send private message Visit poster's website Reply with quote
the_coder



Joined: 30 Jan 2025
Posts: 2
the_coder 30 Jan 2025, 21:38
Thank you! It works!
Post 30 Jan 2025, 21:38
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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.