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

  • SEARCH
  • Home
  • 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 7676871
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T17:17:47+00:00 2026-05-31T17:17:47+00:00

I am still having issues copying the part of one array to another. I

  • 0

I am still having issues copying the part of one array to another. I am trying to check to contents of the array to make sure things are functioning but everything prints to zero. I initialize my array to zero first and as things happen in the program, different parts are copied into array called dataBlock which is part of the array called cache which is made of objects called SlotNodes.

Things are initialized in my simulator class as so

  public static SlotNode[] cache = new SlotNode[8];
  public static int cacheSize = 8;
  public static int memSize = 2048;
  public static byte[] main_Mem = new byte[memSize];

There’s a menu, if we try to read an address, we dissect the address:

      public static void readAddress() {
          System.out.println("What address? ");
         //String tmpAddress = keyboard.next();
          address = keyboard.nextInt(16);

          System.out.println("After parsing the string to base 16, you get ");
          System.out.printf("%X", 0xFF & address);
          System.out.println(" ");
          //get offset
          offset = address & 0x7;
          System.out.println(offset);
          //get tag
          int tmpTag = address >> 6;
          tag = tmpTag & 0x1F;
          System.out.println(tag);
          //get slot
          slot = (address >> 3) & 0x7;
          System.out.println(slot);

          //go to slot number and see what valid bit is
          if (cache[slot].getValidBit() == 0) {

When the validbit is 0, then we have to copy a block of data from the main_Mem array into the cache array’s dataBlock array.

System.out.println("Miss");
                  //copy block in main memory, 8 bytes
                  //address/8 gets address of block in mainmemory
                  int startAddress = address & 0x7F8;

                  System.out.println("The start address of " + address + " should be "  + startAddress);
                  cache[slot].setValidBit(1);
                  cache[slot].setTag(tag);
                 //Now need to copy from startAddress plus 8 bytes into cache[slot]
                 while (cacheSize < 8){
                 System.arraycopy(main_Mem, startAddress, cache[slot].dataBlock, 0, cacheSize);
          }

                  System.out.println();
                  System.out.println("The block of data is: ");
                  for (int i=0; i<8; i++) {
                      for (int j=0; j<7; j++){
                          System.out.println("Value: " + cache[i].dataBlock[j]);
                      }
                  }

          }

The valid bit that i set to ‘1’ prints out fine. It just seems like the numbers from the main_mem array aren’t being copied to where they need to be. 🙁

  • 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-05-31T17:17:48+00:00Added an answer on May 31, 2026 at 5:17 pm

    You initialize cacheSize to 8, but you copy only while cacheSize < 8. That is never true.

    Sorry to bash on this, but this is something you are supposed to find out about by using a debugger and stepping through your program, rather having people debug you code by reading it.

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

Sidebar

Related Questions

I'm trying to port the speakhere example into another app and I'm having issues.
Still having issues with this problem. Please help if you can. So I am
Following on from my earlier question , I am still having issues with loading
Im still having issues using HttpWebRequest . For some reason sometimes in my app
I've been playing around with references (I'm still having issues in this regard). 1-
I'm ( still ) having loads of issues with HSQLdb & OpenJPA. Exception in
I've asked a couple of questions here but am still having issues. I'd appreciate
I asked a question earlier on this same project but I'm still having issues
This would seem to be a simple .htaccess RewriteRule, yet I'm still having issues
I'm having issues with ob_start. Not sure what the deal is, but I've bubbled

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.