flat assembler
Message board for the users of flat assembler.

Index > Compiler Internals > Advanced x86 Encoder - operand sizes

Author
Thread Post new topic Reply to topic
m_stery



Joined: 08 Nov 2024
Posts: 4
m_stery 17 Dec 2025, 03:13
I want to improve Advanced x86 Encoder so that it is not necessary to specify the operand size when using a segment register (in mode 16)
Code:
mov [word 0x0092],cs    

Is there only one instruction for this code, or did I miss something?

But it needs to be written like this
Code:
mov word [word 0x0092],cs    



In cases where I specify the operand size I get the message "operand sizes do not match".
Code:
add di,byte 0x50    

But without "byte" the instruction will be optimized (add signed byte to word register)

I want to solve the first case by adding the size, as is the case with other registers, but I'm not sure if there would be a conflict somewhere when using a different CPU/modes.

I want to solve the second case so that the size is checked after optimization (For example, use nopedantic option).
What do you think?
Post 17 Dec 2025, 03:13
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20805
Location: In your JS exploiting you and your system
revolution 17 Dec 2025, 03:21
I tried these four variants and had no trouble:
Code:
mov [0],cs
mov [word 0],cs
mov word [0],cs
mov word [word 0],cs    
Code:
flat assembler  version 1.73.31  (16384 kilobytes memory)
1 passes, 16 bytes.    
Code:
00000000  8C0E0000          mov [0x0],cs
00000004  8C0E0000          mov [0x0],cs
00000008  8C0E0000          mov [0x0],cs
0000000C  8C0E0000          mov [0x0],cs    
Post 17 Dec 2025, 03:21
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8495
Location: Kraków, Poland
Tomasz Grysztar 17 Dec 2025, 07:55
There was a bug in fasm2, causing an incompatibility with fasm. I fixed it and now fasm2 gives the same result as the one shown by revolution.
Post 17 Dec 2025, 07:55
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8495
Location: Kraków, Poland
Tomasz Grysztar 17 Dec 2025, 08:10
As for the second problem, it's a common theme of fasm and fasm2: to add additional checks and constraints you usually insert ASSERT or, for more complex ones, write a macro. With fasm2/fasmg you could also tweak the actual encoder parts, but that's a more advanced thing.

See also my old legacy source assembly for examples of customized encoders (in that case, emulating some old DOS assemblers). I have not updated them for fasm2, but one day I might.

PS. With fasm2 there is also this option:
Code:
include 'macro/inline.inc'

inlinemacro signed_byte value*
        assert value >= -80h & value < 80h
        return = value
end inlinemacro

add di,signed_byte(0x50)    
Post 17 Dec 2025, 08: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.