cast a label into a char array....

S

s88

Hi all:
I have a memory area fill will 0x90(NOP). This area is allocated
by the linker. I want to transfer this area into a char array. I have
already known the size of this area and the beginning address with the
label MY_AREA.
I mean, the char array looks like "char
my_area[THE_SIZE_OF_THIS_AREA];", and how to use the label MY_AREA and
THE_SIZE_OF_THIS_AREA to create pointer like my_area?

Thanx!!


Dave.
 
M

mark_bluemel

Hi all:
I have a memory area fill will 0x90(NOP). This area is allocated
by the linker. I want to transfer this area into a char array. I have
already known the size of this area and the beginning address with the
label MY_AREA.

I think the memcpy() function is what you actually need to do the task
(or perhaps not, see my second comment), but in this context, I can't
understand what you mean by "label" - as far as I know the only use of
the term in the C language is to denote a destination for a "goto".

I'd also comment that if the memory is full of a known value, I don't
see why you need to transfer it to a char array - you could use the
memset() function to initialise your array.

It may be worth showing us some real code to show what you actually
have... A more detailed explanation of what you are trying to achieve
by filling the char array with 0x90 would be good too...
 
S

s88

(or perhaps not, see my second comment), but in this context, I can't
understand what you mean by "label" - as far as I know the only use of
the term in the C language is to denote a destination for a "goto".

I'd also comment that if the memory is full of a known value, I don't
see why you need to transfer it to a char array - you could use the
memset() function to initialise your array.

It may be worth showing us some real code to show what you actually
have... A more detailed explanation of what you are trying to achieve
by filling the char array with 0x90 would be good too...

A seg. of my text section in my a.out
27229 0805fdbc <__do_global_ctors_aux>:
27230 805fdbc: 55 push %ebp
27231 805fdbd: 89 e5 mov %esp,%ebp
27232 805fdbf: 53 push %ebx
27233 805fdc0: bb f8 33 16 08 mov $0x81633f8,%ebx
27234 805fdc5: 83 ec 04 sub $0x4,%esp
27235 805fdc8: a1 f8 33 16 08 mov 0x81633f8,%eax
27236 805fdcd: eb 07 jmp 805fdd6
<__do_global_ctors_aux+0x1a>
27237 805fdcf: 83 eb 04 sub $0x4,%ebx
27238 805fdd2: ff d0 call *%eax
27239 805fdd4: 8b 03 mov (%ebx),%eax
27240 805fdd6: 83 f8 ff cmp $0xffffffff,
%eax
27241 805fdd9: 75 f4 jne 805fdcf
<__do_global_ctors_aux+0x13>
27242 805fddb: 83 c4 04 add $0x4,%esp
27243 805fdde: 5b pop %ebx
27244 805fddf: 5d pop %ebp
27245 805fde0: c3 ret
27246 805fde1: 90 nop
27247 805fde2: 90 nop
27248 805fde3: 90 nop
27249
27250 0805fde4 <MY_AREA>:
27251 805fde4: 90 nop
27252 805fde5: 90 nop
27253 805fde6: 90 nop
27254 805fde7: 90 nop
27255 805fde8: 90 nop
27256 805fde9: 90 nop
27257 805fdea: 90 nop

This MY_LABEL is setting up in the linker script!! The label not only
for the goto statement, it also can treat as a "function", if you deal
with the related stack operations!
In C lang, I could get the address of the MY_AREA by &MY_AREA.
Actually, I want to manage this area as my system memory, allocate by
myself, so I got the
http://www.thescripts.com/forum/thread214637.html
The author introduce a simple memory allocator, and I want to port
this program on MY_AREA.

any idea?
Dave.
 
N

Nick Keighley

A seg. of my text section in my a.out
  27229 0805fdbc <__do_global_ctors_aux>:
  27230  805fdbc:       55                      push   %ebp
  27231  805fdbd:       89 e5                   mov    %esp,%ebp
  27232  805fdbf:       53                      push   %ebx
  27233  805fdc0:       bb f8 33 16 08          mov    $0x81633f8,%ebx
  27234  805fdc5:       83 ec 04                sub    $0x4,%esp
  27235  805fdc8:       a1 f8 33 16 08          mov    0x81633f8,%eax
  27236  805fdcd:       eb 07                   jmp    805fdd6

<snip>

well as soon as you went to assembler you moved away from standard C
(which is what comp.lang.c deals with)
I *think* you are trying to mix C and assembler. You need to find a
news
group that is more specific to your problem. Perhaps an assembler ng.
This MY_LABEL is setting up in the linker script!!

what's a linker script? Again not standard C.
The label not only
for the goto statement, it also can treat as a "function", if you deal
with the related stack operations!

not in C it can't
In C lang, I could get the address of the MY_AREA by &MY_AREA.
Actually, I want to manage this area as my system memory, allocate by
myself, so I got thehttp://www.thescripts.com/forum/thread214637.html
The author introduce a simple memory allocator, and I want to port
this program on MY_AREA.

any idea?

--
Nick Keighley

Egon: Try to imagine all life as you know it stopping instantaneously
and
every molecule in your body exploding at the speed of light.
Ray: Total protonic reversal....
Venkman: Right, that's bad...OK.. important safety tip. Thanks, Egon.
(Ghost Busters)
 
S

santosh

s88 said:
A seg. of my text section in my a.out

<snip assembler code>

Why don't you post to comp.lang.asm.x86?

<OT> If you want to write your own memory manager, use the brk() and
sbrk() functions under *NIX OSes. For Windows, try VirtualAlloc(). No
need to fiddle with assembler. </OT>
 
D

Dietmar Schindler

s88 said:
I have a memory area fill will 0x90(NOP). This area is allocated
by the linker. I want to transfer this area into a char array. I have
already known the size of this area and the beginning address with the
label MY_AREA.
I mean, the char array looks like "char
my_area[THE_SIZE_OF_THIS_AREA];", and how to use the label MY_AREA and
THE_SIZE_OF_THIS_AREA to create pointer like my_area?

Try

extern char MY_AREA[];
 
P

Peter Nilsson

<snip> ...I can't understand what you mean by "label" - as far as I
know the only use of the term in the C language is to denote a
destination for a "goto".

That is a label name. Labeled-statements include case and default.
 
M

mark_bluemel

That is a label name. Labeled-statements include case and default.

OK - I'll qualify my comment. The only use of the term in the original
K&R text (to which I refered before posting) is as a destination for a
goto...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top