Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Trick to store 1030 in a byte?

  1. #1
    Member
    Join Date
    Feb 2013
    Posts
    78
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Question Trick to store 1030 in a byte?

    Hey guys. So, I am writing an emulator for a cpu similar to a 6502. I have a byte array of size 8192 for the memory. Now, if I need to store a memory address in memory, once i get to 127, im screwed right? Because if a byte goes from -128 to 127, i cant store my memory address of 1030. So... i am trying to figure out how to do this. I assume I would have to use some sort of flag and do some special stuff to make it work, but im wondering how a real cpu would do it. This is of course supposed to be an emulator so I would like to do it the way the cpu does instead of cheat and use an int array. If anyone can shed some light on this for me, it would be greatly appreciated. Thanks for reading and replying!


  2. #2
    Super Moderator pbrockway2's Avatar
    Join Date
    Jan 2012
    Posts
    987
    Thanks
    6
    Thanked 206 Times in 182 Posts

    Default Re: Trick to store 1030 in a byte?

    Sorry, I don't know anything about a "real" 6502 compiler or assembler. But however you slice it or dice it a byte is only going to hold 256 distinct values. If you want to address >256 memory locations you will have to represent them as two bytes.

    Too many years ago I used an Archimedes computer which happily addressed an address space of 2^32 locations (a big deal in those days) - but it used a 27 bit address bus! What it did was specify addresses using an address + offset. This baroque arrangement was hidden from the C/C++ programmer except for the detail that structs were (for efficiency) aligned on four byte boundries (so the offsets weren't needed). Google will probably reveal how the 6502 did things.

Similar Threads

  1. Trick - How to build a button to switch between panel colors
    By vividMario52 in forum Java Swing Tutorials
    Replies: 6
    Last Post: May 23rd, 2013, 06:55 AM
  2. [B instead of byte[]
    By rfabbc in forum Android Development
    Replies: 0
    Last Post: February 21st, 2013, 08:21 PM
  3. Trick question?
    By Kungpaoshizi in forum Java Theory & Questions
    Replies: 4
    Last Post: August 30th, 2011, 07:20 AM
  4. Byte Operation
    By tcstcs in forum Java Theory & Questions
    Replies: 4
    Last Post: March 27th, 2011, 11:19 PM
  5. I/O and byte arrays.
    By LDM91 in forum File I/O & Other I/O Streams
    Replies: 4
    Last Post: March 1st, 2011, 08:36 PM