my nasm source/exe doesn't work in qnx? or is it just me?

i have made a simple hello world asm program in nasm
i have used these commands to make the file:

$ nasm -f elf [my source file]
$ ld -s -o [my output executable file] [my object file]

when i used the first command, an object file (*.o) was created, no errors
then i used the ld command to make an executable file, still no errors
i made sure that the executable file was executable and then ran it

$ ./[my executable file]

then it gave me a wierd error:

./hello[1]: syntax error: `(’ unexpected

(hello was the name of my executable file)

it did not run

here is my source code written in nasm and there should not be any errors in it because nasm made the object file with out returning any errors and i got the source code off of a linux nasm tutorial so the error it gave me was wierd.

if anyone could help me on this it would be greatly appreciated
thanks in advance

:exclamation: :exclamation: :exclamation: :exclamation: :exclamation:

I do not think your Linux example will run under QNX as the kernel calls are probably different (are they?).

I tried this example and got a memory fault when running the program.

I never used assembler under QNX, but it would be cool to have some examples. :wink:

You can use C library and forget the crappy linux INT 80H kernel function call interface.

example is below:

; hello.asm
; build using:
; nasm -f elf hello.asm
; gcc hello.o -o hello

[SECTION .text]

extern printf
global main

push ebp ; Set up stack frame
mov ebp, esp
push ebx ; Preserve ebx, esi, edi
push esi
push edi

push dword hellow
call printf
add esp, 4   ; Cleanup stack

pop edi
pop esi
pop ebx
mov esp, ebp 		; Destroy stack frame
pop ebp

[SECTION .data]

hellow: db ‘Helloworld’, 10, 0

playing around with gdb I encountered a problem:

Is it OK (i.e. legal) to reverse engineer e.g. a hello world program to gain knowledge about how QNX writes text on the screen at the lowest level? Is it OK to use this knowledge in my QNX programming?

(In this particular case: disassamble the printf or write function to see what happens next. Do it the same way next time I want to write text to screen.)

Any thoughts on this?

Thanks, Smee

im quite a new member and you guys are helping me out a lot, thanks for all the help, i will try your suggestions


thanks Jallu, your code works!!!
but i dont understand how
gcc hello.o -o hello did it and not ld

Actually ld is involved in the process. When you generate executable binary file from C source file with the gcc happens the following:

gcc first invokes a utility called the C preprocessor, cpp. When cpp is finished, gcc takes over and generates an assembly language equivalent of the C statements in the original .c file. Next it invokes GNU assembler, gas to assemble the .s file into an object code. The final step involves the GNU linker, ld.

So when you call gcc with the following command:
gcc hello.o -o hello

The only input file called out in the command is a .o file containing object code. This fact alone tells the gcc that all it needs to do is to link the file with the C library to produce the final executable.

Don’t know how “lowest” you are talking about. The C lib source (including the fuction printf() your are looking at) is in for public access.

Actually I wanted to write an assembler hello world without any libc calls.

Thanks, that is really a great source!

However I don’t think the code for MsgSend* calls is available as source (at least I didn’t find it), so I still need libc calls even for a hello world assmembler prog.

The kernel calls are all simply assembly stubs which are generated by the lib/c/inc/mkkercalls.c file.

There are a few exceptions in lib/c/kercovers though…

I’ll have a look at this, thanks.