nasm gcc basic problem for

  • Follow


I downloaded nasm and GCC for use on Winxp.  I created the small
helloworld.asm test program as posted on the nasm site and it compiles
fine.

code below:
;
----------------------------------------------------------------------------
; helloworld.asm
;
; This is a Win32 console program that writes "Hello, World" on one
line and
; then exits.  It needs to be linked with a C library.
;
----------------------------------------------------------------------------

	global	_main
	extern	_printf

	section .text
_main:
	push	message
	call	_printf
	add	esp, 4
	ret
message:
	db	'Hello, World', 10, 0


I then use the gcc command to link the resulting object file.  Again,
all is fine.  I should point out here that I tested the GCC compiler
and linker with a short hello.c file and I get the expected output.

Anyway, if I run the assembled and linked code in a dos box (command
prompt) under XP, no output from the assembler program.  No errors,
etc.  Haven't tried native dos yet.

Any hints?  library problem?  Tried all libraries distributed with gcc
djgpp.  16 bit vs 32 bit?   Calling?

This started as a simple test to see if I could improve the performance
of a CAM application that drives a CNC mill and turned into a real
excercise.

thanks

0
Reply spamtrap2 (1628) 6/15/2005 3:54:11 AM

I took your code and it worked fine on my XP system using cygwin's nasm
and gcc. Can you show exactly the commands you used to assemble and
link?

This is what I used:
$ nasm -f win32 bug.asm
$ gcc bug.obj
$./a.exe

0
Reply Paul 6/16/2005 1:20:44 AM


same commands except -fwin32 (all one word) - don't think it makes a
difference.

What version of nasm and gcc are you using?  When I looked at the code
using debug, all the addresses are off.  The call to printf is at
printf + 16 or so.  


Thanks for your help.

0
Reply jerry 6/16/2005 5:58:05 AM


Paul Carter wrote:
> I took your code and it worked fine on my XP system using cygwin's nasm
> and gcc. Can you show exactly the commands you used to assemble and
> link?
>
> This is what I used:
> $ nasm -f win32 bug.asm
> $ gcc bug.obj
> $./a.exe


little more input.  When I look at it with FSDB, the first instruction
at _main is a push main+17.  So it looks like it is pushing the offset
of the message using the code segement as a base?  It then does a call
to printf+10 instead of printf which one might think it is assuming
that the printf function is loaded after the message bytes.

Environment settings in nasm?

0
Reply jerry 6/16/2005 5:58:13 AM

I'm using the ones that come with cgywin:

gcc (GCC) 3.3.3 (cygwin special)
NASM version 0.98.39 compiled on Feb 18 2005

-- 
Paul Carter

0
Reply Paul 6/17/2005 1:03:24 AM

jerry wrote:
> I downloaded nasm and GCC for use on Winxp.  I created the small
> helloworld.asm test program as posted on the nasm site and it compiles
> fine.
> 
> code below:
> ;
> ----------------------------------------------------------------------------
> ; helloworld.asm
> ;
> ; This is a Win32 console program that writes "Hello, World" on one
> line and
> ; then exits.  It needs to be linked with a C library.
> ;
> ----------------------------------------------------------------------------
> 
> 	global	_main
> 	extern	_printf
> 
> 	section .text
> _main:
> 	push	message
> 	call	_printf
> 	add	esp, 4
> 	ret
> message:
> 	db	'Hello, World', 10, 0
> 
> 
> I then use the gcc command to link the resulting object file.  Again,
> all is fine.  I should point out here that I tested the GCC compiler
> and linker with a short hello.c file and I get the expected output.
> 
> Anyway, if I run the assembled and linked code in a dos box (command
> prompt) under XP, no output from the assembler program.  No errors,
> etc.  Haven't tried native dos yet.

I doubt if it'll run in native dos. "-f win32" defaults to 32-bit code. 
I have seen console-mode programs assemble and link without any errors 
(that the tools mention), but not produce any output, if 
"-subsystem:console" is not given on the linker command line. I doubt if 
that's your problem, since gcc's calling the linker for you.

> Any hints?  library problem?  Tried all libraries distributed with gcc
> djgpp.  16 bit vs 32 bit?   Calling?

Your mention of djgpp concerns me. Are we talking about cygwin/mingw or 
djgpp here??? Both are 32-bit, but otherwise very different. If it's 
djgpp gcc (and libraries) you're using, try "nasm -f coff" instead of 
"-f win32" (the space is optional, as you mention). (just tried it with 
"-f win32" and djgpp's gcc... still worked!)

> This started as a simple test to see if I could improve the performance
> of a CAM application that drives a CNC mill and turned into a real
> excercise.

If you can get the CNC mill to say "hello" back, *then* I'll be 
impressed! :) (only thing I know about that is: start the spindle 
*before* you feed into the workpiece!)

I don't think it'll make any difference, but you might try putting the 
message in its own ".data" section... AFAIK, it should work with the 
data in a code section (and will result in a smaller executable) but... 
I'm discovering that Linux *does* care in kernel 2.6.11 (maybe *any* 2.6 
kernel???)... still looking into that...

I tried your code both in Cygwin (with "-f win32") and djgpp (with "-f 
coff) - both worked. Let us know if you discover the problem!

Best,
Frank

0
Reply comcast 6/17/2005 6:44:19 PM

thanks for all the input.  I gave up and found the ucr assembler
library and I am coding it in native masm without the c calls.  I tried
everything, multiple options for object files, etc., even tried
creating the code in masm and linking in gcc.  I tried a separate data
segment and could think of a number of other things to try but I am
losing the focus on the objective.

I am using djgpp 4 and the prior release was tried along with nasm
98.39.  I am running it in a dos box window (command prompt) under
winxp sp1.  Should work.

The push statement is resolving to a push message+10.  the call is call
_printf+10.  So it looks like nasm would need the .data segment but I
tried it and don't remember the outcome other than no output.

tracing through the printf routine is very long so I didn't get very
far.

go figure, I've seen this example and good results on about 100 posts.

now I just need some graphics routines to use a raster font and I can
convert this code and run it on an old laptop.

0
Reply jerry 6/17/2005 10:06:19 PM

6 Replies
269 Views

(page loaded in 0.088 seconds)

Similiar Articles:













7/23/2012 2:52:51 AM


Reply: