flat assembler
Message board for the users of flat assembler.

Index > Main > feature request OR question how to do separate mnemonics

Author
Thread Post new topic Reply to topic
matefkr



Joined: 02 Sep 2007
Posts: 1291
Location: Ukraine, Beregovo
matefkr 26 Jan 2012, 10:48
Is there a way to explicitly use separate mnemonic for the operations with implicit operand, and for those using reg/rm byte? Like for the implicit operand mov(e)ax/al "some value" would have a moveax mnemonic (movax for the one whiith operand size preffix) and mov would always mean mov with operand info byte. And similarly to all operations (i don't know them all from head). Also for short/normal jumps (but i guess it can be stated with short long words before label).

i would imagine its possible with macro instructions (im not fasm expert, maybe even everything is described so?).
Post 26 Jan 2012, 10:48
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20333
Location: In your JS exploiting you and your system
revolution 26 Jan 2012, 10:58
Please give some examples of what you want to do.
Post 26 Jan 2012, 10:58
View user's profile Send private message Visit poster's website Reply with quote
matefkr



Joined: 02 Sep 2007
Posts: 1291
Location: Ukraine, Beregovo
matefkr 26 Jan 2012, 11:33
suppose, i want self modifing code, so that the operands would be modfied
so i would modify operand info byte, like increase some part of it (to use registers as continious memory). But anyhow, if thats a low level language, i just want better control over what i write (and defining it in place when i write it). You know that for mov eax, some thing there is two version for example. similarly with add etc.

so is it possible to define such instructions which would translate exactly, or if not it would be a good featuer.
Post 26 Jan 2012, 11:33
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20333
Location: In your JS exploiting you and your system
revolution 26 Jan 2012, 11:35
I meant to give examples of how you want the instructions to look and what they would replace.
Post 26 Jan 2012, 11:35
View user's profile Send private message Visit poster's website Reply with quote
matefkr



Joined: 02 Sep 2007
Posts: 1291
Location: Ukraine, Beregovo
matefkr 26 Jan 2012, 16:41
of course.

for example: if you write mov op1,op2 then it would always be translated to the opcode where the operands are placed in operand info byte (and sig if necessary), plus imm if necessary. if you write moveax op, then it would use the one by implicit eax operand opcode (i think the op here is alway imm, but whatever). so the thing is, if there is two ways to code an instruction (some have two ways, one with operand implicit in opcode) then there should be two forms, where the implicit opcode one would have the operation and implicit operand named in the opcode together such as above. obviously if there is to and from version then some word would be used to distinquesh them. I think relative jumps, where there is short and normal jump is already possible to be forced.
Post 26 Jan 2012, 16:41
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4332
Location: Now
edfed 26 Jan 2012, 17:01
Code:
macro moveax op
{
mov eax,op
}

moveax ebx ;mov eax,ebx
moveax 4323;mov eax,4323
    

?
Post 26 Jan 2012, 17:01
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: 20333
Location: In your JS exploiting you and your system
revolution 26 Jan 2012, 17:05
matefkr: I think I understand what you are asking now.
Code:
mov eax,ebx ;can be encoded in two ways    
Because of the 'd' bit we can swap the reg and r/m fields and invert the d bit to get the same effective operation but encoded differently.

Is that what you want to have control over?
Post 26 Jan 2012, 17:05
View user's profile Send private message Visit poster's website Reply with quote
matefkr



Joined: 02 Sep 2007
Posts: 1291
Location: Ukraine, Beregovo
matefkr 26 Jan 2012, 19:17
Revolution: Indeed also this one, but not just that one. so every kind of encoding an instruction should be separate mnemonic or prefix at lest. so to make it more close to hex coding, but with mnemonics and stuff.
Post 26 Jan 2012, 19:17
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20333
Location: In your JS exploiting you and your system
revolution 26 Jan 2012, 19:43
I have previously discussed this in PM before with another poster on this board.

Inventing new custom mnemonics might alienate new users to assembly. Perhaps there is a way where you can use just the operands to describe the desired order of placement in the encoding. e.g.:
Code:
mov eax(r/m),ebx(reg) ;encoding 1
mov eax(reg),ebx(r/m) ;encoding 2    
Perhaps you can think of a "nicer" way to do it.
Post 26 Jan 2012, 19:43
View user's profile Send private message Visit poster's website Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4332
Location: Now
edfed 26 Jan 2012, 20:57
Code:
(32|16) mov (r1,r2|r2,r1|r,m|m,r|r,i|m,i) r1,r2 
with 
16 mov r2,r1 eax,edx
;to give
use16
mov edx,eax
    


it might be possible with a sort of macro + maybe modifications of fasm preprocessor + a lot of things very strange to identify.
Post 26 Jan 2012, 20:57
View user's profile Send private message Visit poster's website Reply with quote
l_inc



Joined: 23 Oct 2009
Posts: 881
l_inc 26 Jan 2012, 21:15
matefkr
There's a thing called "epimorphic assembler". It's implemented as a macro altm for an assembly/disassembly engine provided there. It allows to choose different opcodes for same mnemonic which could be helpful, if you need a binary identical reassembly, but it uses a numeric encoding scheme instead of providing additional mnemonics which is not quite human-friendly (however, it's also hard to do it better). You could use the same encoding scheme to implement a fasm macro with same capabilities.
Post 26 Jan 2012, 21:15
View user's profile Send private message Reply with quote
uart777



Joined: 17 Jan 2012
Posts: 369
uart777 02 Feb 2012, 03:27
FASM always generates the smallest instruction format: jmp i8, push i8 (extended to 32), etc, and register (opcode+r) and al/ax/eax specific versions that do not have a modr/m or [s*i+b] byte. Why would you want it to do anything else?

As for custom instructions, it's very easy to encode them manually if you know Intel machine code. Example:

Code:
macro bug { db 0CCh } ; int3 breakpoint exception

macro cmp_eax_i32 i {
        ; no prefix
db 03Dh ; opcode, 1 byte
        ; no modrm or sib
        ; no displacement
dd i    ; immediate, 4 bytes
}
    
Post 02 Feb 2012, 03: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.