You are not logged in.

#1 2012-11-26 11:30:54

leetow2003
Member
Registered: 2012-04-08
Posts: 25

How to correct it?

I push string into stack,I don't want to put it into data section
and then want to display it,but it doesn't display,how to correct it?
Look:

.text
.global _start
_start:
       pushl %ebp
       movl %esp,%ebp
       pushl $0x48494a00
       movl $4,%eax
       movl $1,%ebx
       movl %ebp,%ecx
       movl $4,%edx
       int $0x80
       popl %eax
       popl %ebp
       movl $1,%eax
       movl $0,%ebx
       int $0x80

Offline

#2 2012-11-26 11:31:48

Trilby
Forum Moderator
From: Massachusetts, USA
Registered: 2011-11-29
Posts: 14,202
Website

Re: How to correct it?

I'd start with a better thread title.

It would also probably help to give relevant information about which assembler you are using (and what machine it may be for).  I have an admittedly very minimal experience with assembly languages, but this does have some distinct differences from those I've used both in DOS and Linux.

EDIT: Is this GAS?  I suppose it does look like it - sorry, I'm used to NASM.

Last edited by Trilby (2012-11-26 11:52:19)


InterrobangSlider
• How's my coding? See this page.
• How's my moderating? Feel free to email any concerns, complaints, or objections.

Offline

#3 2012-11-26 13:16:43

bernarcher
Forum Fellow
From: Germany
Registered: 2009-02-17
Posts: 2,273

Re: How to correct it?

Moving to Programming & Scripting.
And please change the thread title to something more descriptive.


To know or not to know ...
... the questions remain forever.

Offline

#4 2012-11-26 15:05:03

Trent
Member
From: Baltimore, MD (US)
Registered: 2009-04-16
Posts: 987

Re: How to correct it?

I'd guess endianness problems. Looks like you're trying to print "HIJ", right? Well, which byte is placed at the address contained in %esp when you copy it to %ebp? Could be the null terminator. Could also be (part of) the last thing you placed on the stack... it's been a while since I did x86, but that's what I'd look for first. Draw a picture of the stack and see if you can figure out what really ends up in %ecx when you do the syscall. (I remember drawing lots of pictures last time I did assembly.)

Offline

#5 2012-11-26 16:26:35

tavianator
Member
From: Waterloo, ON, Canada
Registered: 2007-08-21
Posts: 858
Website

Re: How to correct it?

Indeed, after "pushl $0x48494a00", the stack contains, in order, 00 4a 49 48.

Offline

#6 2012-11-26 21:32:01

Trent
Member
From: Baltimore, MD (US)
Registered: 2009-04-16
Posts: 987

Re: How to correct it?

tavianator wrote:

Indeed, after "pushl $0x48494a00", the stack contains, in order, 00 4a 49 48.

What do you mean by "in order"?

Offline

#7 2012-11-27 03:59:46

tavianator
Member
From: Waterloo, ON, Canada
Registered: 2007-08-21
Posts: 858
Website

Re: How to correct it?

Lowest address to highest.  So instead of "HIJ\0" you're trying to print "\0JIH" which starts with a null byte.

Try "push $0x004a4948" instead

Last edited by tavianator (2012-11-27 04:00:26)

Offline

#8 2012-11-27 04:46:47

Trent
Member
From: Baltimore, MD (US)
Registered: 2009-04-16
Posts: 987

Re: How to correct it?

tavianator wrote:

Lowest address to highest.  So instead of "HIJ\0" you're trying to print "\0JIH" which starts with a null byte.

Try "push $0x004a4948" instead

Close, but it still won't work. I'm hoping OP can figure out why not...

Regarding my question, I just meant to clarify what it means for the stack to hold 4 bytes "in order", since the stack grows downward and the order of bytes within objects on the stack is independent of (and in this case reversed from) the order of objects in the stack. But it seems you had the right idea.

Offline

#9 2012-11-27 20:06:23

tavianator
Member
From: Waterloo, ON, Canada
Registered: 2007-08-21
Posts: 858
Website

Re: How to correct it?

Ah that's true, it should be

movl %esp,%ecx
movl $3,%edx

I just saw the endianness issue and thought that was it.

Offline

Board footer

Powered by FluxBB