flat assembler
Message board for the users of flat assembler.

Index > Linux > What Linux distro should I use...

Goto page Previous  1, 2, 3, 4, 5
Author
Thread Post new topic Reply to topic
HaHaAnonymous



Joined: 02 Dec 2012
Posts: 1178
Location: Unknown
HaHaAnonymous 01 Feb 2013, 17:12
[ Post removed by author. ]


Last edited by HaHaAnonymous on 28 Feb 2015, 21:48; edited 1 time in total
Post 01 Feb 2013, 17:12
View user's profile Send private message Reply with quote
Endre



Joined: 29 Dec 2003
Posts: 215
Location: Budapest, Hungary
Endre 02 Feb 2013, 13:11
Maybe these snippets help you admit your ignorance. And yes, this feature has been there since years.
Code:
/**
 * Compile with
 * gcc -g -masm=intel hello.c -o hello
 */

#include <unistd.h>
#include <sys/syscall.h>

int main(void)
{
    char message[] = "Hello World\n";

    asm("mov     eax, %0 \n\t"
        "mov     edi, %1 \n\t"
        "mov     rsi, %2 \n\t"
        "mov     edx, %3 \n\t"
        "syscall \n\t"
        :: "i" (__NR_write), "i" (STDOUT_FILENO), "g" (message), "i" (sizeof(message)-1)
        : "eax", "edi", "rsi", "edx");

    return 0;
}    


or a simple assembly code, which you can even debug with gdb, just set a break-point at _start, and run.

Code:
/**
 * Compile with
 * gcc -g -nostdlib hello.S -o hello
 */

        .if 0
#include <unistd.h>
#include <sys/syscall.h>
        .endif

        .line __LINE__
        .intel_syntax noprefix
        .text
        .globl _start

_start:
        mov     eax, __NR_write
        mov     edi, STDOUT_FILENO
        mov     rsi, offset message
        mov     edx, offset message.size
        syscall
        xor     edi, edi
        mov     rax, __NR_exit
        syscall

message:
        .ascii "Hello World\n"
message.size = . - message    


Note that in last example even C-headers are included. Try it with fasm. If you're wondering I can show you how you can reach C-structure members from assembly when you mix C and assembly codes.
Post 02 Feb 2013, 13:11
View user's profile Send private message Reply with quote
HaHaAnonymous



Joined: 02 Dec 2012
Posts: 1178
Location: Unknown
HaHaAnonymous 02 Feb 2013, 15:33
[ Post removed by author. ]


Last edited by HaHaAnonymous on 28 Feb 2015, 21:46; edited 1 time in total
Post 02 Feb 2013, 15:33
View user's profile Send private message Reply with quote
Endre



Joined: 29 Dec 2003
Posts: 215
Location: Budapest, Hungary
Endre 04 Feb 2013, 11:00
Free pascal? We were talking about gcc/gas. What mistake was expected? Sorry, I just don't understand what you want to say.
Post 04 Feb 2013, 11:00
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page Previous  1, 2, 3, 4, 5

< 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.