flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > Extending FASM syntax.

Author
Thread Post new topic Reply to topic
MHajduk



Joined: 30 Mar 2006
Posts: 6034
Location: Poland
MHajduk
However this theme was already discussed (http://board.flatassembler.net/topic.php?t=3592), I think, that I could present proposition of redefining choosen FASM instructions.

Macros presented below allow us to use three ways of determining source and destination of two-argument instructions:
    - instr dest, src ("old school" Wink),
    - instr src >> dest,
    - instr dest << src.
Code:
; File 'SyntaxExtension.inc' in which are presented
; macros for extending syntax of choosen two-argument
; FASM instructions (mov, add, adc, sub, sbb, and, or, xor).
;
; (C) Mikolaj Hajduk, 26.01.2007.
;

; For each value of 'instr' parameter from list
; 'mov add adc sub sbb and or xor' is defined a new
; macro, which helps in visualisation source and
; destination parameters.
;
irps instr, mov add adc sub sbb and or xor
{
        ; Redefinition of instruction 'instr'.
        ;
        macro instr par1, par2
        \{
                ; "Old school" Wink order.
                ;
                match a =, b, par1, par2 \\{instr a, b \\}

                ; Source parameter on the left side, destination
                ; on the right side.
                ;
                match a >> b, par1  par2 \\{instr b, a \\}

                ; Source parameter on the right side, destination
                ; on the left side.
                ;
                match a << b, par1  par2 \\{instr a, b \\}
        \}
}
    

Here is an example of using this extended syntax:
Code:
; File 'SyntaxExtensionTest.asm' in which is presented
; way of using extended syntax of choosen two-argument
; instructions.
;
; (C) Mikolaj Hajduk, 26.01.2007.
;

org 100h

; Including proper macros redefining choosen instructions.
;
include 'SyntaxExtension.inc'

;
; Examples of using redefined instructions.
;

; "Old school".
;
mov     eax, ebx
mov     [Mem], eax
mov     ebx, [Mem]

; New possibilities.
;
mov     eax << ebx
mov     ecx >> edx

mov     [Mem] << edx
mov     [Mem] >> ecx

mov     4C00h >> ax
int     21h

; Memory cell used in examples.
;
Mem     dd ?    

We could see how FASM preprocessor (FASMPRE) transforms it into Intel's "old school" syntax:
Code:






org 100h



;include 'SyntaxExtension.inc'












;irps instr,mov add adc sub sbb and or xor
;{
;
;
; macro instr par1,par2
; \{
;
;
; match a=,b,par1,par2 \\{ instr a,b \\}
;
;
;
;
; match a>>b,par1 par2 \\{ instr b,a \\}
;
;
;
;
; match a<<b,par1 par2 \\{ instr a,b \\}
; \}
;}



;macro mov par1,par2
;{
;
;
; match a=,b,par1,par2 \{ mov a,b \}
;
;
;
;
; match a>>b,par1 par2 \{ mov b,a \}
;
;
;
;
; match a<<b,par1 par2 \{ mov a,b \}
;}




;macro add par1,par2
;{
;
;
; match a=,b,par1,par2 \{ add a,b \}
;
;
;
;
; match a>>b,par1 par2 \{ add b,a \}
;
;
;
;
; match a<<b,par1 par2 \{ add a,b \}
;}




;macro adc par1,par2
;{
;
;
; match a=,b,par1,par2 \{ adc a,b \}
;
;
;
;
; match a>>b,par1 par2 \{ adc b,a \}
;
;
;
;
; match a<<b,par1 par2 \{ adc a,b \}
;}




;macro sub par1,par2
;{
;
;
; match a=,b,par1,par2 \{ sub a,b \}
;
;
;
;
; match a>>b,par1 par2 \{ sub b,a \}
;
;
;
;
; match a<<b,par1 par2 \{ sub a,b \}
;}




;macro sbb par1,par2
;{
;
;
; match a=,b,par1,par2 \{ sbb a,b \}
;
;
;
;
; match a>>b,par1 par2 \{ sbb b,a \}
;
;
;
;
; match a<<b,par1 par2 \{ sbb a,b \}
;}




;macro and par1,par2
;{
;
;
; match a=,b,par1,par2 \{ and a,b \}
;
;
;
;
; match a>>b,par1 par2 \{ and b,a \}
;
;
;
;
; match a<<b,par1 par2 \{ and a,b \}
;}




;macro or par1,par2
;{
;
;
; match a=,b,par1,par2 \{ or a,b \}
;
;
;
;
; match a>>b,par1 par2 \{ or b,a \}
;
;
;
;
; match a<<b,par1 par2 \{ or a,b \}
;}




;macro xor par1,par2
;{
;
;
; match a=,b,par1,par2 \{ xor a,b \}
;
;
;
;
; match a>>b,par1 par2 \{ xor b,a \}
;
;
;
;
; match a<<b,par1 par2 \{ xor a,b \}
;}









;mov eax,ebx



;match a=,b,eax,ebx{mov a,b}
mov eax,ebx




;match a>>b,eax ebx{mov b,a}




;match a<<b,eax ebx{mov a,b}

;mov[Mem],eax



;match a=,b,[Mem],eax{mov a,b}
mov[Mem],eax




;match a>>b,[Mem]eax{mov b,a}




;match a<<b,[Mem]eax{mov a,b}

;mov ebx,[Mem]



;match a=,b,ebx,[Mem]{mov a,b}
mov ebx,[Mem]




;match a>>b,ebx[Mem]{mov b,a}




;match a<<b,ebx[Mem]{mov a,b}




;mov eax<<ebx



;match a=,b,eax<<ebx,{mov a,b}




;match a>>b,eax<<ebx{mov b,a}




;match a<<b,eax<<ebx{mov a,b}
mov eax,ebx

;mov ecx>>edx



;match a=,b,ecx>>edx,{mov a,b}




;match a>>b,ecx>>edx{mov b,a}
mov edx,ecx




;match a<<b,ecx>>edx{mov a,b}


;mov[Mem]<<edx



;match a=,b,[Mem]<<edx,{mov a,b}




;match a>>b,[Mem]<<edx{mov b,a}




;match a<<b,[Mem]<<edx{mov a,b}
mov[Mem],edx

;mov[Mem]>>ecx



;match a=,b,[Mem]>>ecx,{mov a,b}




;match a>>b,[Mem]>>ecx{mov b,a}
mov ecx,[Mem]




;match a<<b,[Mem]>>ecx{mov a,b}


;mov 4C00h>>ax



;match a=,b,4C00h>>ax,{mov a,b}




;match a>>b,4C00h>>ax{mov b,a}
mov ax,4C00h




;match a<<b,4C00h>>ax{mov a,b}

int 21h



Mem dd ?
    
Regards.
Post 26 Jan 2007, 12:13
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-2020, Tomasz Grysztar.

Powered by rwasa.