Hello James!
07 May 97 21:06, James Vahn wrote to Sylvain Lauzon about assembly & linux:
JV> But something is wrong here. This produces a clean executable when
inked
JV> with gcc (the compiler), but when linked with ld (the linker) directly
JV> (ld -o int80 int80.o), the program segfaults and dumps core. Now if I
JV> could just figure out the debugger....
you'll need to terminate the process in a clean way. This means use a signal
or (preferred) the exit() systemcall. When you link with gcc, it'll add the
startup code found in crt?.o which contains an exit call, but when using ld
directly it just sees your object file. Remember, if you don't use _start or
some other default, you'll have to pass an entry point to the linker, too. In
the next messages are the disassembly listings to illustrate he differences.
In the gcc version the label is changed to , of course.
I added a working version, but my nasm 0.90 is probably a bit different from
yours, since i couldn't get it to assemble as-is. no guarantees though, i
don't speak nasm.
JV> ;nasm -f elf int80.asm -o int80.o
JV> ;gcc int80.o -o int80
JV> ;
JV> section .text
JV> global _start
JV> _start:
JV> mov edx, 07h ; write 0x07 characters
JV> mov ecx, msg ; address of msg
JV> mov ebx, 0h ; write to stdout
JV> mov eax, 4h ; syscall write (see asm/unistd.h)
JV> int 80h ; trap
JV> ret
JV> msg:
JV> db 'Hello!', 0Ah
------------------------------
[SECTION .text]
[BITS 32]
[GLOBAL _start]
_start:
mov edx, 07h ; write 0x07 characters
mov ecx, msg ; address of msg
mov ebx, 0h ; write to stdout
mov eax, 4h ; syscall write (see asm/unistd.h)
int 80h ; trap
mov ebx, 0h ; zero exit value
mov eax, 1h ; syscall exit
int 80h ; trap
ret ;shouldn't get here
msg:
db 'Hello!', 0Ah
----------------------
Bye , Pieter
--- GoldED 2.41+
---------------
* Origin: __Pigs On The Wing__ Leiden, NL. (pjs@xs4all.nl) (2:281/214.7)
|