NASM - The Netwide Assembler

NASM Forum => Programming with NASM => Topic started by: nobody on November 03, 2007, 01:18:36 AM

Title: %arg with 64 bit
Post by: nobody on November 03, 2007, 01:18:36 AM
Has it been considered to extend the support of the %arg directive for 64 bit? Currently (0.99.05) %arg functions the same whether compiling 64 or 32 bit code, which isn't correct. The different calling conventions between Unix and Windows could be conveniently abstracted by %arg. ie, we're talking about %1, %2, ... being resolved to rds, rsi, ... on Unix; rcx, rdx, ... on Windows.

I'm deciding if I should go about patching my NASM sources to accomplish this or attempt writing some messy macros to similarly abstract the calling conventions. Any opinions?
Title: Re: %arg with 64 bit
Post by: Keith Kanios on November 05, 2007, 07:16:25 PM
What you are suggesting would clutter NASM with unnecessary platform-specific implementation code. Think about the common scenario where someone uses ELF for their own operating system kernel development and doesn't adhere to the UNIX ABI.

What you want is already being accomplished with the main include file (nasmx.inc) found in the NASMX package.

NASMX can be found at http://www.asmcommunity.net/projects/nasmx/ (http://www.asmcommunity.net/projects/nasmx/)
Title: Re: %arg with 64 bit
Post by: nobody on November 08, 2007, 01:16:43 AM
I started writing support for 64-bit proc declaration with my own macros. nasmx.inc doesn't actually cover this. Look at its argd macro, it just identifies labels with offsets. There's some logic for the register conventions in its invoke macro, maybe that's what you're thinking of.

Now I think I discovered %local is incorrect for 64 bit builds, it identifies labels with ebp offsets instead of rbp. Not only that, the offsets seem to be incorrect in general. Here's a 32-bit case:

%local l1:qword, l2:dword, l3:dword, l4:qword
mov eax, l1
mov eax, l2
mov eax, l3
mov eax, l4

generates:

mov eax, (ebp-4)
mov eax, (ebp-12)
mov eax, (ebp-16)
mov eax, (ebp-20)

Shouldn't those be ebp-8, ebp-12, ebp-24, respectively. I checked the preproc.c file, what looks wrong is it advances the offset after defining the label.
Title: Re: %arg with 64 bit
Post by: nobody on November 08, 2007, 01:20:14 AM
I meant shouldn't those be: ebp-8, ebp-12, ebp-16, ebp-24.