Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

There is more to this assignment, but I don\'t even know where to start. This is

ID: 675495 • Letter: T

Question

There is more to this assignment, but I don't even know where to start. This is also a C programming assignment

Concepts Covered

Pointers

Memory Concepts

String Manipulations

Formatted I/O

This assignment has you creating your own virtual computer with its own limited instruction set and language. The program you write will accept as input programs written in this language, “compile” it into the computer's instruction set and execute the program.

The computer has a 100 word memory, where each word is a signed 4 digit integer. Instructions and stored values share the same 100 word memory. It also contains an accumulator, which acts as a register that operations are performed upon. The current instruction to be executed is kept in the instructionCounter and the current instruction is kept in the instructionRegister. There is also two additional registers used for splitting up the data in the instruction, an operationCode and operand. When the program in memory is executed, it starts with the instruction at memory location 0, and stops when the halt instruction is reached.

The computer is capable of handling instructions, 4 digit signed integer values, and strings. Each word when interpreted as an instruction can be broken down into two, 2 digit chunks. The first 2 digits represents the instruction (operationCode), the second represents the memory address that instruction uses (operand). When a word is interpreted as a value, the entire 4 digits is the value. When interpreted as a string each 2 digits represents the ASCII character of the string. The only characters that are understood are NULL (00), newline (10) and A-Z (65-90). Each instruction is followed by a newline.

The language consists of a number of commands, each representing an instruction in the computer. Each command is on a line of its own, and is preceded by the 2 digit address in memory it is to be placed and followed by a single value, typically an address in memory.

Explanation / Answer

using System; namespace SYSTEM.cpu { // NOTE: Only level-trigger interrupts are planned right now // To implement: // - microcode // - execution unit // - etc // This is the "core"; think of the CPU core like a building. You have several departments; flags, memory and registers // Microcode is external class core { public cpu_flags flags; public cpu_registers registers; public cpu_memory memory; public core(byte[] ROM, byte[] PRG) { flags = new cpu_flags(); registers = new cpu_registers(); memory = new cpu_memory(ROM, PRG); return; } } } using System; namespace SYSTEM.cpu { class cpu_flags { // SYSTEM is not a 6502 emulator. The flags here, however, are exactly named as in 6502's SR // They do NOT, however, WORK the same as in 6502. They are intended to similar uses, but the only identity is the naming. // I just like the 6502's naming and whatnot. // This would otherwise be a register in SYSTEM.cpu_core.cpu_registers. SR, with the bits used correctly. // This would be less readable, code-wise, so I've opted to dedicate an entire CLASS to the status register // Though, I should implement here a function for putting the flags in a byte, so "SR" can be pushed when servicing interrupts public bool negative, // set if the high bit of the result of the last operation was 1 // bit 7, then so on overflow, // says whether the last arithmetic operation resulted in overflow (NOTE: No subtraction opcodes available in SYSTEM) // NO FLAG brk, // break flag, set when a BREAK instruction is executed // NO FLAG (would be decimal flag, but I don't see why anyone would want BCD. If you want it, go implement it in my emulator; in software) // i.e. don't implement it in SYSTEM; write it in SYSTEM ASM and run it in SYSTEM's DEBUGGER irq, // whether or not an interrupt should begin at the next interrupt period (if false, no interrupt) zero, // says whether the last arithmetic operation resulted in zero carry; // set when alpha rolls from 0xFFFF to 0x0000, or when a 1 is rotated/shifted during arithmetic public cpu_flags() { negative = true; // all arithmetic registers are FFFF by default, so of course they are negative overflow = false; // obviously, because no arithmetic operation has been performed yet brk = false; irq = true; // interrupts are enabled by default of course zero = false; // obviously, since all arith regs are not zero by default carry = false; // obviously, since no carry operation was performed return; } // Explain: // These flags are public. No point putting much management on them here, since they are boolean // The opcodes that SYSTEM supports, will act on these flags. This is just here for code clarity/organisation } } using System; // This implements the memory controller // NOTE: NO BANK SWITCHING IMPLEMENTED, AND NOT PLANNED AT THE MOMENT, SO MAKE DO WITH TEH 64 // SYSTEM has a 16-bit address bus (and the maximum memory supported; 64K) // SYSTEM also has a 16-bit data bus; 8-bit operations are also performed here, they just use the low bits // 0x0000-0x00FF is stack // 0xF000-0xFFFF is mapped to BIOS ROM, and read-only; this is where BIOS is loaded on startup. // (meaning PROGRAM ROM can be up to 4096B, or 4K. Normally this will be used for loading a BIOS) // Mapping other PROGRAM ROM should start from 0x0100, but execution should start from 0xF000, where ROM/BIOS is mapped // NOTE: PROGRAM ROM IS 32K, and mapped from 0x0100 to 0x80FF // ;-) namespace SYSTEM.cpu { class cpu_memory { // to implement: // device interaction (certain addresses in ROM should be writeable by external device, connected to the controller) // anything else that comes to mind. // Oh, and bank switching, if feasible private byte[] RAM; // As in the bull? ... public cpu_memory(byte[] ROM, byte[] PRG) { // Some code here can be condensed, but for the interest of readability, it is optimized for readability. Not space. // Checking whether environment is sane... SYSTEM is grinning and holding a spatula. Guess not. if(ROM.Length > 4096) throw new Exception("****SYSINIT PANIC****: BIOS ROM size INCORRECT. MUST be within 4096 BYTES. STOP"); if (PRG.Length > 32768) throw new Exception("****SYSINIT PANIC**** PROGRAM ROM size INCORRECT. MUST be within 61184 BYTES. STOP"); if(ROM.Length != 4096) // Pads ROM to be 4096 bytes, if size is not exact { // This would not be done on a physical implementation of SYSTEM, but I feel like being kind to the lazy this.RAM = ROM; ROM = new byte[4096]; for(int i = 0x000; i
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote