public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* AMD 64 Problem with assembling
@ 2005-07-09 21:23 Florian Michel
  2005-07-10 16:29 ` Ian Lance Taylor
  0 siblings, 1 reply; 2+ messages in thread
From: Florian Michel @ 2005-07-09 21:23 UTC (permalink / raw)
  To: gcc-help


Hello,

I have a question concerning successfully assembling and linking the following assembly program on a linux AMD 64 machine:

#cpuid2.s View the CPUID Vendor ID string using C library calls
.section .datatext
output:
.asciz "The processor Vendor ID is '%s'\n"
.section .bss
.lcomm buffer, 12
.section .text
.globl main
main:
movl $0, %eax
cpuid
movl $buffer, %edi
movl %ebx, (%edi)
movl %edx, 4(%edi)
movl %ecx, 8(%edi)
push $buffer
push $output
call printf
addl $8, %esp
push $0
call exit

This part of a book on assembly programming I am reading.

Compile and Link: gcc -o cpuid2 cpuid2.s
When running cpuid2 it crashes with a segmentation fault.
Which switches do I have to add to call gcc?

Thanks a lot!

Greetings,
Florian

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: AMD 64 Problem with assembling
  2005-07-09 21:23 AMD 64 Problem with assembling Florian Michel
@ 2005-07-10 16:29 ` Ian Lance Taylor
  0 siblings, 0 replies; 2+ messages in thread
From: Ian Lance Taylor @ 2005-07-10 16:29 UTC (permalink / raw)
  To: Florian Michel; +Cc: gcc-help

Florian Michel <florian__michel@web.de> writes:

> I have a question concerning successfully assembling and linking the
> following assembly program on a linux AMD 64 machine:

The gcc-help mailing list is for questions about using gcc.  It is not
for general questions about how to write correct programs, or correct
assembly code.  Thanks.

That said, the easiest way to write correct assembly code is to copy
at gcc output, as generated by -S or --save-temps.

And the bug here is in this line:

> .section .datatext

You want something like:

.section .datatext,"a"

Ian

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2005-07-10 16:29 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-07-09 21:23 AMD 64 Problem with assembling Florian Michel
2005-07-10 16:29 ` Ian Lance Taylor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).