All of lore.kernel.org
 help / color / mirror / Atom feed
* Declare strings on stack, gas
@ 2012-04-18 14:58 Daniel Hilst
  2012-04-18 18:14 ` JIA Zhongye
  2012-04-18 19:34 ` Robert Plantz
  0 siblings, 2 replies; 4+ messages in thread
From: Daniel Hilst @ 2012-04-18 14:58 UTC (permalink / raw)
  To: linux-assembly

Is possible to declare strings on stack? I'm using mov + ebp offsets to 
do something like that.. Is there an easier way to do it?

Here is an sample off how I'm doing it: http://sprunge.us/UUZI

The hex numbers are a "Hello World" string..
I have tried .assci without success :(

Thanks in advance!


-- 
Follow the white rabbit!

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

* Re: Declare strings on stack, gas
  2012-04-18 14:58 Declare strings on stack, gas Daniel Hilst
@ 2012-04-18 18:14 ` JIA Zhongye
  2012-04-18 19:34 ` Robert Plantz
  1 sibling, 0 replies; 4+ messages in thread
From: JIA Zhongye @ 2012-04-18 18:14 UTC (permalink / raw)
  To: Daniel Hilst; +Cc: linux-assembly

Since the stack could be any arbitrary place in memory, I'm afraid you 
don't got too many choice but set-up the content by yourself.

When a local array of char is declared in C, i.e. something like:
void foo()
{
   char s[] = "hello world";
}
The compiler does just the same thing as you by MOVL, and when the 
string is rather long, the compiler would place the string in .data and 
call memcpy() to copy it to stack.

On 04/18/2012 10:58 PM, Daniel Hilst wrote:
> Is possible to declare strings on stack? I'm using mov + ebp offsets to
> do something like that.. Is there an easier way to do it?
>
> Here is an sample off how I'm doing it: http://sprunge.us/UUZI
>
> The hex numbers are a "Hello World" string..
> I have tried .assci without success :(
>
> Thanks in advance!
>
>

-- 
Regards,
Zhongye

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

* Re: Declare strings on stack, gas
  2012-04-18 14:58 Declare strings on stack, gas Daniel Hilst
  2012-04-18 18:14 ` JIA Zhongye
@ 2012-04-18 19:34 ` Robert Plantz
  2012-04-19 16:07   ` Daniel Hilst
  1 sibling, 1 reply; 4+ messages in thread
From: Robert Plantz @ 2012-04-18 19:34 UTC (permalink / raw)
  To: Daniel Hilst; +Cc: linux-assembly

On 4/18/2012 7:58 AM, Daniel Hilst wrote:
> Is possible to declare strings on stack? I'm using mov + ebp offsets 
> to do something like that.. Is there an easier way to do it?
>
> Here is an sample off how I'm doing it: http://sprunge.us/UUZI
>
> The hex numbers are a "Hello World" string..
> I have tried .assci without success :(
>
> Thanks in advance!
>
>
Basically, you're asking if the compiler/assembler can initialize the 
stack to some known value. Since memory on the stack is dynamically 
allocated by the instructions:

doit:
       push    %ebp              ; Save caller's base pointer
       mov    %esp, %ebp         ; Establish our base pointer

       sub    $12, %esp          ; Allocate memory on the stack



the answer is 'no.' After you allocate stack memory (which now has 
garbage values), you need to copy known values there. Write your code in 
C and use the '-S' gcc option to see how the compiler does this. The 
'-S' option will generate the assembly language file foo.s from the C 
source file foo.c.

--Bob




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

* Re: Declare strings on stack, gas
  2012-04-18 19:34 ` Robert Plantz
@ 2012-04-19 16:07   ` Daniel Hilst
  0 siblings, 0 replies; 4+ messages in thread
From: Daniel Hilst @ 2012-04-19 16:07 UTC (permalink / raw)
  Cc: linux-assembly

On 04/18/2012 07:34 PM, Robert Plantz wrote:
> On 4/18/2012 7:58 AM, Daniel Hilst wrote:
>> Is possible to declare strings on stack? I'm using mov + ebp offsets
>> to do something like that.. Is there an easier way to do it?
>>
>> Here is an sample off how I'm doing it: http://sprunge.us/UUZI
>>
>> The hex numbers are a "Hello World" string..
>> I have tried .assci without success :(
>>
>> Thanks in advance!
>>
>>
> Basically, you're asking if the compiler/assembler can initialize the
> stack to some known value. Since memory on the stack is dynamically
> allocated by the instructions:
>
> doit:
> push %ebp ; Save caller's base pointer
> mov %esp, %ebp ; Establish our base pointer
>
> sub $12, %esp ; Allocate memory on the stack
>
>
>
> the answer is 'no.' After you allocate stack memory (which now has
> garbage values), you need to copy known values there. Write your code in
> C and use the '-S' gcc option to see how the compiler does this. The
> '-S' option will generate the assembly language file foo.s from the C
> source file foo.c.
>
> --Bob
>
>
>

Thanks guys, the closest I got was use .text section and the %esi trick.
Now I know about stack dynamics.

Cheers!
-- 
Follow the white rabbit!

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

end of thread, other threads:[~2012-04-19 16:07 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-04-18 14:58 Declare strings on stack, gas Daniel Hilst
2012-04-18 18:14 ` JIA Zhongye
2012-04-18 19:34 ` Robert Plantz
2012-04-19 16:07   ` Daniel Hilst

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.