flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > possible FASM bug with conditional compile

Author
Thread Post new topic Reply to topic
Mark Larson



Joined: 04 Nov 2006
Posts: 13
Mark Larson 09 Nov 2006, 21:06
I am adding support for doing both 64-bit and 32-bit fasm code in one .asm file. I have some conditional assembly that gets done. But it doesn't seem to be working right. This is at the very top of my file. the macro at the very end is designed so I can just use "syscall" in all my code. In 32-bit code it will get translated correctly to "int 80h". In 64-bit code there will be no macro and it will use the new instruction for 64-bit processors "syscall". However for some reason it's doing the "int 80h" part even though USE_32_BIT is 0. I am not using any include files.

Code:
USE_32_BIT                      equ                     0

if USE_32_BIT
format ELF
else
format ELF64
end if



if USE_32_BIT
SYSCALL_EXIT                            equ                     1               ;32-bit
else
SYSCALL_EXIT                            equ                     60              ;64-bit
end if

if USE_32_BIT
SYSCALL_WRITE                           equ                     4               ;32-bit
else
SYSCALL_WRITE                           equ                     1               ;64-bit
end if

if USE_32_BIT
macro   syscall
{
        int      80h
}
end if

    


Here's the actual .asm code
Code:
        mov                     eax,SYSCALL_EXIT
        syscall 
    


From the conditional compile SYSCALL_EXIT gets set to a 60 correctly instead of a 1. However the macro for syscall that converts it to an int 80 also gets compiled in. Here's the dump ( generated by using a objdump under linux)
Code:
( the syntax is AT&T from the objdump program)

  41:  b8 3c 00 00 00           mov    $0x3c,%eax
  46:  cd 80                    int    $0x80
    


the SYSTEM_EXIT is correctly getting set to 60 from having USE_32_BIT set to 0. But it should just do the standard syscall for the last part.

_________________
BIOS programmers do it fastest! Wink
Post 09 Nov 2006, 21:06
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8351
Location: Kraków, Poland
Tomasz Grysztar 09 Nov 2006, 21:26
Read the answer to fourth question in FAQ.
If you've got more free time for I recommend also reading this. And chapter 2.3.7 of manual as some general reference.

And if you don't want to waste time for reading anything more than this post: replace every EQU with = in your source.
Post 09 Nov 2006, 21:26
View user's profile Send private message Visit poster's website Reply with quote
Mark Larson



Joined: 04 Nov 2006
Posts: 13
Mark Larson 09 Nov 2006, 22:59
Tomasz Grysztar wrote:
Read the answer to fourth question in FAQ.
If you've got more free time for I recommend also reading this. And chapter 2.3.7 of manual as some general reference.

And if you don't want to waste time for reading anything more than this post: replace every EQU with = in your source.


Thanks for the help. I'd rather read the links you provide, so I can become an expert. I am reading it now.

_________________
BIOS programmers do it fastest! Wink
Post 09 Nov 2006, 22:59
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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.