Post Reply 
Executing FOCAL programs from ROM vs. RAM
04-11-2019, 12:22 PM
Post: #5
RE: Executing FOCAL programs from ROM vs. RAM
Thanks guys.

I'll call the pointer to the next FOCAL instruction the interpreter pointer (IP) to distinguish it from the CPU's program counter (PC). I'd argue that the IP is 16 bits where the top 4 bits indicate whether the program is in RAM or ROM. The fact that the CPU uses flag 10 to indicate whether those bits are 0 is an optimization.

I see that I wrote incorrectly about the RAM addresses. The max address is 0x3ff which is 10 bits, not 12. But it sounds like FOCAL programs must reside within the bottom half of the address space (0x000-0x1ff). That's because when executing from RAM there are only 12 bits available to specify a byte. 3 are used to indicate the byte within a register, leaving 9 to select a register within RAM.

So if I understand right, it gets the next byte in the FOCAL program like this C pseudo-code:
Code:
if (flag10) {   // flag10 true of top 4 bits of IP are non-zero
    // Program is in ROM
    word = readRomWord(IP);
    byte = word & 0xff;    // & is bit-wise AND. Truncates 10-bit word to 8 bits.
} else {
   // Program is in RAM
   byteOffset = IP & 7;  // shave off lower 3 bits for byte offset
   RAMaddr = IP >> 3;  // Get the address within RAM. >> is right shift
   register = readRamRegister(RAMaddr);
   byte = getNthByteInRegister(register, byteOffset);
}
// Now "byte" contains the next byte of the FOCAL program.
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Executing FOCAL programs from ROM vs. RAM - David Hayden - 04-11-2019 12:22 PM



User(s) browsing this thread: 1 Guest(s)