Author Topic: Linux and LIBC  (Read 126 times)

nidud

  • Member
  • *****
  • Posts: 1359
    • https://github.com/nidud/asmc
Linux and LIBC
« on: June 19, 2017, 02:25:10 AM »
I've added _LINUX and _WIN64 to switch -elf, -elf64, and -win64

-elf --> _LINUX = 1
-elf64 --> _LINUX = 2 + _WIN64 = 1
-win64 --> _WIN64 = 1

libc.inc use SYSCALL if elf is defined.
Code: [Select]
ifdef _LINUX
_CType equ <syscall>
_CDecl equ <syscall>
__cdecl equ <syscall>

This enables use of the include files for LIBC functions.

Test case used for 64-bit:
Code: [Select]
include stdio.inc

    .code

main proc argc:SINT, argv:ptr

    .for r12d=argc, r13=argv, ebx=0: r12d: r12d--, ebx++, r13+=size_t
       
    printf("[%d]: %s\n", ebx, [r13])
    .endf
    xor eax,eax
    ret
main endp

    end

Output:
Code: [Select]
nidud@nidud-VB ~/asmc $ ./asmc -q -Iinclude -elf64 arg64.asm
nidud@nidud-VB ~/asmc $ gcc -o arg64 arg64.o
nidud@nidud-VB ~/asmc $ ./arg64 1 2 3
[0]: ./arg64
[1]: 1
[2]: 2
[3]: 3

Test case used for 32-bit:
Code: [Select]
include stdio.inc

    .code

main proc argc:SINT, argv:ptr

    .for ebx=argc, esi=argv, edi=0: ebx: ebx--, edi++, esi+=size_t

    printf("[%d]: %s\n", edi, [esi])
    .endf
    xor eax,eax
    ret
main endp

    end

Output:
Code: [Select]
nidud@nidud-VB ~ $ cd asmc
nidud@nidud-VB ~/asmc $ ./asmc -elf -Iinclude arg32.asm
Asmc Macro Assembler Version 2.24
Portions Copyright (c) 1992-2002 Sybase, Inc. All Rights Reserved.

 Assembling: arg32.asm
nidud@nidud-VB ~/asmc $ gcc arg32.o -o arg32
nidud@nidud-VB ~/asmc $ ./arg32
[0]: ./arg32
nidud@nidud-VB ~/asmc $ ./arg32 1 2 3
[0]: ./arg32
[1]: 1
[2]: 2
[3]: 3

I also changed the default size of indirect addressing using register in 64-bit. This was 4 but now 8. This effect :VARARG arguments using -elf64 and -win64.
Code: [Select]
    printf("[%d]: %s\n", ebx, [r13])