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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With