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!

June 26th, 2013, 12:08 AM

pbrockway2

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.