flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > Macroinstruction to replace instruction?

Author
Thread Post new topic Reply to topic
Azu



Joined: 16 Dec 2008
Posts: 1159
Azu 22 Jul 2009, 21:03
pop <32bit register> does not compile for a 64bit executable.. so I thought I should make a macroinstruction that replaces it with pop <64bit register> when I compile my program in 64bit mode.. but it does not work.. what am I doing wrong?
Code:
if defined 64bit
       oldpop = pop
        macro pop reg{
         if reg=eax oldpop rax end if
                if reg=ebx oldpop rbx end if
                if reg=ecx oldpop rcx end if
                if reg=edx oldpop rdx end if
                if reg=esi oldpop rsi end if
                if reg=edi oldpop rdi end if
        }
end if    



P.S. I also tried a similar solution for push.
Post 22 Jul 2009, 21:03
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4079
Location: vpcmpistri
bitRAKE 23 Jul 2009, 01:35
I've posted part of solution here:
http://board.flatassembler.net/topic.php?p=98098#98098
Code:
macro pop [reg] {
  local ..reg
  ; assume reg is okay
  ..reg equ reg
  ; update only if reg is R32
  R64FromR32 ..reg,reg
  ; do the POP
  pop ..reg
}    
...haven't tested it, but it seems like it would work. Also, all the work is done by the pre-processor, so the listing will just show the POP instruction with the correct register, iirc. Cool
Post 23 Jul 2009, 01:35
View user's profile Send private message Visit poster's website Reply with quote
Azu



Joined: 16 Dec 2008
Posts: 1159
Azu 23 Jul 2009, 02:02
bitRAKE wrote:
I've posted part of solution here:
http://board.flatassembler.net/topic.php?p=98098#98098
Code:
macro pop [reg] {
  local ..reg
  ; assume reg is okay
  ..reg equ reg
  ; update only if reg is R32
  R64FromR32 ..reg,reg
  ; do the POP
  pop ..reg
}    
...haven't tested it, but it seems like it would work. Also, all the work is done by the pre-processor, so the listing will just show the POP instruction with the correct register, iirc. Cool


Thank you

I run into the same problem though.. it says the push in it is illegal Sad

"push ..reg
Error: illegal instruction."
Post 23 Jul 2009, 02:02
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4079
Location: vpcmpistri
bitRAKE 23 Jul 2009, 02:13
Bah, I tested it and it works fine.

You show me yours because I already showed you mine.
Post 23 Jul 2009, 02:13
View user's profile Send private message Visit poster's website Reply with quote
Azu



Joined: 16 Dec 2008
Posts: 1159
Azu 23 Jul 2009, 02:17
I meant with yours, it is giving the same error I got with mine which I posted in the first post in this topic.

The changes I made to yours are only semantic see for yourself.

Code:
e64 equ 1

if defined e64
 macro R64FromR32 [r64,r32] { 
          match A:=r32==B:C,::eax=rax:edx=rdx:ecx=rcx:ebx=rbx:ebp=rbp:esi=rsi:edi=rdi:esp=rsp:r8d=r8:r9d=r9:r10d=r10:r11d=r11:r12d=r12:r13d=r13:r14d=r14:r15d=r15:: \{ 
                     r64 equ B 
          \} 
   }
      macro pop [reg] {
              local ..reg
         ..reg equ reg           ; assume reg is okay
                R64FromR32 ..reg,reg    ; update only if reg is R32
         pop ..reg               ; do the POP
        }
      macro push [reg] {
             local ..reg
         ..reg equ reg           ; assume reg is okay
                R64FromR32 ..reg,reg    ; update only if reg is R32
         push ..reg              ; do the PUSH
       }
end if


push        eax
pop      eax    
Post 23 Jul 2009, 02:17
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4079
Location: vpcmpistri
bitRAKE 23 Jul 2009, 02:26
First, the IF is done by the assembler - after the pre-processor is finished. I.E. the MACROs are defined no matter what "e64" is. Second, I'm guessing you have another PUSH macro somewhere because the exact same code works here. (You aren't really showing all the code.) You could further debug with the .FAS output to be sure.

See section 2.3.7 Order of Processing in the FASM manual.
Post 23 Jul 2009, 02:26
View user's profile Send private message Visit poster's website Reply with quote
Azu



Joined: 16 Dec 2008
Posts: 1159
Azu 23 Jul 2009, 03:13
No other macro, nothing. That's all I have in the file. It doesn't compile. I tried removing the IF, and it still fails to compile with the same error I mentioned above. I took out all of my code to make sure it's a problem with the macro and not something else.. Confused

Code:
macro R64FromR32 [r64,r32] { 
      match A:=r32==B:C,::eax=rax:edx=rdx:ecx=rcx:ebx=rbx:ebp=rbp:esi=rsi:edi=rdi:esp=rsp:r8d=r8:r9d=r9:r10d=r10:r11d=r11:r12d=r12:r13d=r13:r14d=r14:r15d=r15:: \{ 
             r64 equ B 
  \} 
}
macro pop [reg] {
       local ..reg
 ..reg equ reg           ; assume reg is okay
        R64FromR32 ..reg,reg    ; update only if reg is R32
 pop ..reg               ; do the POP
}
macro push [reg] {
   local ..reg
 ..reg equ reg           ; assume reg is okay
        R64FromR32 ..reg,reg    ; update only if reg is R32
 push ..reg              ; do the PUSH
}


push eax
pop      eax    





Edit: I think I found the problem. In the little example I forgot to put use64. Very strange that it ran for you Confused



I'm not sure why it isn't working in my program though. It fails with my invoke macro
Code:
macro invo func,[args]{
      reverse push    args
        common  call    func
}    
which worked fine until I added your push macro. Is there any way to make them compatible?


Last edited by Azu on 23 Jul 2009, 03:30; edited 1 time in total
Post 23 Jul 2009, 03:13
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4079
Location: vpcmpistri
bitRAKE 23 Jul 2009, 03:28
Of course you'll need a USE64 - FASM defaults to 16-bit instructions.
Post 23 Jul 2009, 03:28
View user's profile Send private message Visit poster's website Reply with quote
Azu



Joined: 16 Dec 2008
Posts: 1159
Azu 23 Jul 2009, 03:31
Whoops I was editing my post right when you replied Embarassed

Could you respond to my edited post please ^^
Post 23 Jul 2009, 03:31
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4079
Location: vpcmpistri
bitRAKE 23 Jul 2009, 03:48
How are you using "invo" MACRO?

What kind of error are you getting?

What diagnostic measures have you taken to resolve the error?

(Go ahead and post these questions after your posts to save me some time.)
Post 23 Jul 2009, 03:48
View user's profile Send private message Visit poster's website Reply with quote
Azu



Joined: 16 Dec 2008
Posts: 1159
Azu 23 Jul 2009, 07:06
bitRAKE wrote:
How are you using "invo" MACRO?
No special way, it is just a simplified version of the invoke macro that comes with FASM.
invo function,arg1,arg2,arg3 etc..

bitRAKE wrote:
What kind of error are you getting?
"push ..reg
Error: illegal instruction."

bitRAKE wrote:
What diagnostic measures have you taken to resolve the error?
Looked in the docs, found vague answer of "it means you tried to use an undocumented instruction", decided this didn't fit since my CPU has both the push and the pop instructions, so asked here in this thread what was up with the error.


Oh and also since I can't use the if statement for toggling this off and on, what should I use?
Post 23 Jul 2009, 07:06
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4079
Location: vpcmpistri
bitRAKE 23 Jul 2009, 13:46
Yet, you are still unwilling to post the complete code, or a smaller version demonstrating the same effects.

The PREPSRC tool that comes with FASM can show you exactly what is happening with the macros. Use the -S switch to output .FAS file and then use PREPSRC on the .FAS data.

Toggling will require a pre-processor directive (obviously) - MATCH seems the easiest, but others can work. (An example exists in the manual, iirc.)
Post 23 Jul 2009, 13:46
View user's profile Send private message Visit poster's website Reply with quote
Azu



Joined: 16 Dec 2008
Posts: 1159
Azu 23 Jul 2009, 18:39
Thanks. All is well now. Smile
Post 23 Jul 2009, 18:39
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger ICQ Number 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.