flat assembler
Message board for the users of flat assembler.
Index
> Main > strict keyword like in NASM available? |
Author |
|
revolution 17 Aug 2018, 15:07
Just omit the "strict" and you will get the sizes specified.
Code: add ax,byte 3 ; ==> 83 C0 03 add ax,word 3 ; ==> 05 03 00 |
|||
17 Aug 2018, 15:07 |
|
LowLevelMahn 17 Aug 2018, 15:11
it does not work
Code: ;fasm fasm_dos_exe.asm format MZ entry main:start stack 100h segment main start: add ax,3 ; assembles add ax,byte 3 ; fails this is the error i get Code: flat assembler version 1.73.04 (1048576 kilobytes memory) fasm_dos_exe.asm [8]: add ax,byte 3 processed: add ax,byte 3 error: operand sizes do not match. |
|||
17 Aug 2018, 15:11 |
|
DimonSoft 17 Aug 2018, 18:57
LowLevelMahn wrote: it does not work There’s no add reg16, imm8 in IA-32 ISA. I wonder why would any decent x86 assembler allow that. |
|||
17 Aug 2018, 18:57 |
|
LowLevelMahn 17 Aug 2018, 19:03
sorry its for IA-16 (DOS real mode)
https://c9x.me/x86/html/file_module_x86_id_5.html ... 05 iw, ADD AX, imm16, Add imm16 to AX ... 83 /0 ib, ADD r/m16, imm8, Add sign-extended imm8 to r/m16 nasm can assemble it using the strict keyword add ax,strict byte 3 ; ==> 83 C0 03 add ax,strict word 3 ; ==> 05 03 00 its for an reverse engineering project where i first try to reproduce the very same executable (100% identical) |
|||
17 Aug 2018, 19:03 |
|
DimonSoft 17 Aug 2018, 19:41
LowLevelMahn wrote: sorry its for IA-16 (DOS real mode) 16 bits have been part of IA-32 for ages by now but I see your point. It actually is a sign-extension version and the operand is still 16-bit before addition. Since any immediate can be extended to the required size there’s no need to specify the size of an immediate if you write a program. Your case is somewhat different: another compiler made a bad job choosing an encoding that is longer than the one FASM uses by default (since FASM generally chooses the shortest encoding possible). So, if your want to have a particular encoding, just do it the way you should have done it in any assembler: make it up by hand with db. The strict keyword you’re asking for is a very custom solution for a way more general problem. If you want to still have the instruction in human-readable form, you can write a macro. Something like (not tested): Code: macro add op1, op2 { regIdx = ... ; I have to think about a smarter way to calculate it if (op1 eqtype ax) & (op2 eqtype 0) & (op2 < $FF) db $83, $C0 or regIdx, op2 else add op1, op2 end if } The way I can think off the top of my head is to define numeric constants for registers and use concatenation to build their names within macro. Although that’s too much work that would better be done by placing a comment next to db. |
|||
17 Aug 2018, 19:41 |
|
Tomasz Grysztar 17 Aug 2018, 19:51
LowLevelMahn wrote: this is the error i get Code: add ax,3 ; 83 C0 03 (automatically optimized to short imm whenever possible) add ax,word 3 ; 05 03 00 (forced long immediate) This touches a general problem: how to allow to somehow influence the choice of encoding when a syntax is intended to be abstraction focused solely on what the instruction does. Ultimately this led me to the design of prototype fasm 2 syntax that is currently only implemented in form of experimental macros for fasmg. You mentioned that your aim is to generate identical executable to the reverse engineered one. I would strongly suggest use of fasmg in place of fasm 1 for such task - fasm 1 leaves a footprint in the instruction encoding choices that cannot be easily altered, while with fasmg you can even modify macros to get the exactly encoding that you need (or perhaps x86-2.inc prototype in its current form might be enough). |
|||
17 Aug 2018, 19:51 |
|
LowLevelMahn 18 Aug 2018, 05:22
thanks - a little strage that byte isn't allowed but still works for my case
fasmg looks very promising |
|||
18 Aug 2018, 05:22 |
|
revolution 18 Aug 2018, 06:23
LowLevelMahn wrote: thanks - a little strage that byte isn't allowed but still works for my case |
|||
18 Aug 2018, 06:23 |
|
LowLevelMahn 18 Aug 2018, 14:07
Quote: It is just a quirk of the instruction encoding no i mean that fasm just don't accepts "add,byte 3" (because its already the default) and giving an operand size error lets see how fasmg perform |
|||
18 Aug 2018, 14:07 |
|
DimonSoft 18 Aug 2018, 17:48
LowLevelMahn wrote:
FASM performs type checking (in a sense applicable to low-level programming) and since adding 16-bit to 8-bit is impossible with IA-32 (it’s not the same as instruction encoding with implied sign extension) the error message is what should be shown. Source code is for people, not processor, so it should better conform with program logic, not encoding logic. The same way it should complain in add ax, dword 3 case. |
|||
18 Aug 2018, 17:48 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.