Home > Archive > A86 Assembler > July 2007 > Need Hello World printf in 64 Bits
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Need Hello World printf in 64 Bits
|
|
| Steven Green 2007-07-03, 6:58 pm |
| Hi all. I am an assembly noob.
I want to call C routines from an assembly program.
I am using YASM and would like a basic hello world type program using
printf and 64 bit assembly.
I have googled a couple days away looking for a basic place to start, but
have found little for 64 bit and C interfacing.
Could someone please take a few seconds and post a simple printf hello
world program.
I would be grateful.
Thanks,
Steve
| |
|
| Steven Green wrote:
> Hi all. I am an assembly noob.
> I want to call C routines from an assembly program.
>
> I am using YASM and would like a basic hello world type program using
> printf and 64 bit assembly.
>
> I have googled a couple days away looking for a basic place to start, but
> have found little for 64 bit and C interfacing.
>
> Could someone please take a few seconds and post a simple printf hello
> world program.
You could study gcc's output.
$ cat ex.c
#include <stdio.h>
int main(void)
{
printf("Hello world\n");
return 0;
}
$ gcc -S ex.c
$ vim ex.s
Or did you want to call the underlying system call? (i.e. write)
| |
|
| Spoon <spamtrap@crayne.org> wrote:
> Steven Green wrote:
>
>
> You could study gcc's output.
>
> $ cat ex.c
> #include <stdio.h>
> int main(void)
> {
> printf("Hello world\n");
> return 0;
> }
>
> $ gcc -S ex.c
> $ vim ex.s
Compiled on 64-bit OpenBSD running on Athlon 64 3500+
.file "ex.c"
.section .rodata
...LC0:
.string "Hello world\n"
.text
.globl main
.type main, @function
main:
...LFB19:
pushq %rbp
...LCFI0:
movq %rsp, %rbp
...LCFI1:
movl $.LC0, %edi
movl $0, %eax
call printf
movl $0, %eax
leave
ret
...LFE19:
.size main, .-main
.section .eh_frame,"a",@progbits
...Lframe1:
.long .LECIE1-.LSCIE1
...LSCIE1:
.long 0x0
.byte 0x1
.string ""
.uleb128 0x1
.sleb128 -8
.byte 0x10
.byte 0xc
.uleb128 0x7
.uleb128 0x8
.byte 0x90
.uleb128 0x1
.align 8
...LECIE1:
...LSFDE1:
.long .LEFDE1-.LASFDE1
...LASFDE1:
.long .LASFDE1-.Lframe1
.quad .LFB19
.quad .LFE19-.LFB19
.byte 0x4
.long .LCFI0-.LFB19
.byte 0xe
.uleb128 0x10
.byte 0x86
.uleb128 0x2
.byte 0x4
.long .LCFI1-.LCFI0
.byte 0xd
.uleb128 0x6
.align 8
...LEFDE1:
|
|
|
|
|