Jonnycake Posted February 2, 2009 Share Posted February 2, 2009 Okay, so I was just messing around with some ASM (linux x86) and using the stack. I have a basic understanding of the stack, but can't figure out one thing. So, let's say I have this: .section .text .globl _start _start: pushl $0x0a414141 pushl $0x41 movl %esp,%ecx movl $8,%edx movl $4,%eax movl $1,%ebx int $0x80 movl $1,%eax movl $0,%ebx int $0x80 My question is why do i put the value 8 into edx instead of 5 since the actual string length is 5. I understand that each part of the stack holds 4 bytes (hence esp+4, esp+8, etc.), but I think it would just make more sense to have 5. I assume it's because with that the stack looks like: +8 0x0a414141 +4 0x00000041 +0 esp So you go from +4 and go forward 8 bytes ignoring the null bytes. Am I right in assuming this or is there another reason? Quote Link to comment Share on other sites More sharing options...
stingwray Posted February 2, 2009 Share Posted February 2, 2009 Its word aligned, for a number of reasons, including simplicity and speed. If you were to allow mutiple pieces of data to be stored in the same word how would you tell where the first ended and the second began? You can't without more data to signify so, given this is small bits of data much cleaner to keep things word aligned. Quote Link to comment Share on other sites More sharing options...
Jonnycake Posted February 3, 2009 Author Share Posted February 3, 2009 Ahhh, okay, I understand now. So, basically, you have to have a specific amount of bytes in a certain position on the stack or else you'd have to have another piece of data that tells where the string ends and begins which would be completely inefficient because it uses memory? Quote Link to comment Share on other sites More sharing options...
stingwray Posted February 3, 2009 Share Posted February 3, 2009 Yes Quote Link to comment Share on other sites More sharing options...
Jonnycake Posted February 3, 2009 Author Share Posted February 3, 2009 Okay thanks :). Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.