Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > cast a label into a char array....

Reply
Thread Tools

cast a label into a char array....

 
 
s88
Guest
Posts: n/a
 
      01-29-2007
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.

 
Reply With Quote
 
 
 
 
mark_bluemel@pobox.com
Guest
Posts: n/a
 
      01-29-2007

On 29 Jan, 17:27, "s88" <dave...@gmail.com> wrote:
> 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...

 
Reply With Quote
 
 
 
 
s88
Guest
Posts: n/a
 
      01-29-2007


On 1月30日, 上午1時51分, mark_blue...@pobox.com wrote:
> On 29 Jan, 17:27, "s88" <dave...@gmail.com> wrote:
>
> > 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...


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.

 
Reply With Quote
 
Nick Keighley
Guest
Posts: n/a
 
      01-31-2007
On 29 Jan, 18:33, "s88" <dave...@gmail.com> wrote:
> On 130, 銝151, mark_blue...@pobox.com wrote:
> > On 29 Jan, 17:27, "s88" <dave...@gmail.com> wrote:


> > > * * 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...

>
> 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)

 
Reply With Quote
 
santosh
Guest
Posts: n/a
 
      01-31-2007
s88 wrote:
> On 1月30日, 上午1時51分, mark_blue...@pobox.com wrote:
> > On 29 Jan, 17:27, "s88" <dave...@gmail.com> wrote:
> >
> > > 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...

>
> 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>

 
Reply With Quote
 
Dietmar Schindler
Guest
Posts: n/a
 
      02-06-2007
s88 wrote:
> 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[];

--
Dietmar
 
Reply With Quote
 
Peter Nilsson
Guest
Posts: n/a
 
      02-06-2007
On Jan 30, 4:51 am, mark_blue...@pobox.com wrote:
> <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.

--
Peter

 
Reply With Quote
 
mark_bluemel@pobox.com
Guest
Posts: n/a
 
      02-07-2007
On 6 Feb, 21:30, "Peter Nilsson" <a...@acay.com.au> wrote:
> On Jan 30, 4:51 am, mark_blue...@pobox.com wrote:
>
> > <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.


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...


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Cast from int to char + char concatenation Konx C++ 0 03-11-2010 03:23 PM
(const char *cp) and (char *p) are consistent type, (const char **cpp) and (char **pp) are not consistent lovecreatesbeauty C Programming 1 05-09-2006 08:01 AM
how to cast unsigned char to char? zl2k C++ 1 03-17-2006 04:48 AM
/usr/bin/ld: ../../dist/lib/libjsdombase_s.a(BlockGrouper.o)(.text+0x98): unresolvable relocation against symbol `std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostre silverburgh.meryl@gmail.com C++ 3 03-09-2006 12:14 AM
error C2440: 'return' : cannot convert from 'const char *' to 'const unsigned short *' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast Abhijit Bhadra C++ 2 12-01-2004 04:43 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57