Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

undefined reference to WinMain@16

Tags:

nasm

segment .data

msg db "Enter your ID", 0xA, 0xD
len equ $ - msg

segment .bss

id resb 10

segment .text

global _start

_start:

    mov eax, 4
    mov ebx, 1
    mov ecx, msg
    mov edx, len
    int 0x80

    mov eax, 3
    mov ebx, 0
    mov ecx, id
    mov edx, 10
    int 0x80

    mov eax, 4
    mov ebx, 1
    int 0x80

_exit:

    mov eax, 1;
    xor ebx, ebx
    int 0x80

    ;End

I am trying to compile this file in c using gcc, but the program gives me an error and I have absolutely no idea where the problem is. Does it have anything to do with my OS?

like image 322
prog Avatar asked Jan 31 '13 05:01

prog


1 Answers

This program will work only in 32 bit Linux . Still there are issues in this program.

Change '_start' to 'main' Also, ecx and edx might not be preserved after a system call (int 0x80)

Plz try the below example.

Assemble & link with:
nasm -felf hello.asm
gcc -o hello hello.o

segment .data

msg db "Enter your ID", 0xA
len equ $ - msg

segment .bss

id resb 10

segment .text

global main

main:

    mov eax, 4
    mov ebx, 1
    mov ecx, msg
    mov edx, len
    int 0x80

    mov eax, 3
    mov ebx, 0
    mov ecx, id
    mov edx, 10
    int 0x80

    mov edx, eax  ;; length of the string we just read in.
    mov eax, 4
    mov ebx, 1
    mov ecx, id
    int 0x80

_exit:

    mov eax, 1;
    xor ebx, ebx
    int 0x80

    ;End
like image 106
user1911887 Avatar answered Sep 27 '22 18:09

user1911887