Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9204563
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T23:44:19+00:00 2026-06-17T23:44:19+00:00

This is purely a homework assignment question, since I’m aware that you really shouldn’t

  • 0

This is purely a homework assignment question, since I’m aware that you really shouldn’t be trying to do this in real life. But I’ve been trying to get this right. Say we know the permanent start position of where we want to copy and the exact size of the chunk of memory we want to copy. So say our source is a stack from 0x28000 to 0x2C0000. The stack grows downwards, so we’re given a pointer to the top of the stack (0x2C0000). We want to copy STACK_SIZE bytes over to a second stack, the top of which is at 0x30000. Basically something like this:

                Stack 1            Stack 2
       /--+-------------------+-------------------+--/
          |        ABXLQPAOSRJ|                   |
       /--+-------------------+-------------------+--/
      0x280000           0x2C0000            0x300000
                              ^                   ^
                              |                   |
                         Top of stack 1     Top of Stack 2

If we have to use memcpy, we would have to start at 0x28000 right? (I’m not entirely sure in which direction memcpy reads; from higher address to lower or vice versa) Would this be correct?

void* s = (void *)source_stack_bottom      //where source_stack_bottom is 0x280000 in this case
void* d = (void *)dest_stack_bottom    //which is 0x2C0000
memcpy(d, s, STACK_SIZE)          //STACK_SIZE is just a variable with the stack size

I can’t think of why it shouldn’t work, but then again I’m still rather confused about how C allocates memory at times so…

EDIT:: Oops, variable confusion. Fixed now.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T23:44:20+00:00Added an answer on June 17, 2026 at 11:44 pm

    A naive implementation of memcpy() would be something like this:

    void naive_memcpy(void *destt, void *sourcet, size_t size)
    {
       char *source = (char *)sourcet;
       char *dest = (char *)destt;
       for(size_t s = 0; s < size; s++){ *dest++ = *source++; }
    }
    

    So yes, it counts upwards from the start of source and dest

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is purely theoretical question, I'm not doing anything, but I plan to. Is
This question is coded in pseudo-PHP, but I really don't mind what language I
This is a purely theoretical 'what if' question, so no pressure to rush to
This question is purely out of curiosity. I am off school for the summer,
This is purely a puzzling curiosity. I know that Opera supports IE's advanced event
I understand this is purely a coding related forum, but i believe techies can
I'm asking this question purely from a usability standpoint ! Should a website expand/stretch
This is purely out of curiosity, but why does this occur? >>> a =
This is purely a math question! I simply can't get my head around this
This is purely a coding practice question concerning VB.NET structures. Where do you keep

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.