java OVERVIEW In this project, you will be implementing a program called tacsim. a simple, limited simulator for a hypothetical CPU called the Tiny Accumulator
java
OVERVIEW In this project, you will be implementing a program called tacsim. a simple, limited simulator for a hypothetical CPU called the Tiny Accumulator Computer, or TAC. The simulator takes in a simplified text based object file (full of TAC instructions encoded as decimal bytes) and then simulates the execution of a CPU. This program's task is simple: to simulate the execution of a single program in memory, one instruction at a time. The input to the program is a text file with object codes and data with one byte per line. This is chosen for this exercise to keep the project simple. I don't want you getting bogged down in how to read binary file formats. The simulator, tacsim, will first load the instructions from the program into a simulated memory. Then, it will start the main loop that simulates the CPU: fetch, decode, execute. It will continue to do this until it reaches the special instruction HLT, that we will use to indicate the program should be finished. To simulate a CPU, you'll have to keep track of these things: register state (i.e., what's in each of the CPU registers, such as ACC, X, etc.), memory state (what's in each byte of memory), and a few other things (e.g., the branching condition code). Each instruction just updates some subset of machine state. Because the simulated computer is rather simple, you won't have to spend too much effort decoding the instructions. Each instruction is represented by two bytes, the first is the opcode, the second is the operand. Let's start by taking a look at the CPU instruction set. CPU INSTRUCTION SET The instructions for this machine are limited to the following eight basic instructions with one special instruction, HLT, used to tell the simulator to stop executing and to report the machine state back to the user. In an accumulator instruction set architecture, all computation moves through the accumulator. For example, suppose that we wanted to add two numbers together, we could execute the following code: LD 225 ADD 15 ST 255 HLT ; load the number 25 into the accumulator ; add the number 15 to the accumulator ; Store the result in the last memory byte ; stop the simulator This series of instructions would assemble to the following opcodes and operands using the table below. Pay careful attention to the addressing mode, review your assembler textbook if you have forgotten these ideas. 06 25 01 15 10 255 15 00 You would then want these instructions one byte, in decimal, per line in the "object" file listed below. Note, and object file format does not have to be a binary file. In our case it will be a simple text file that will contain the following data. --------snip------ 225 15 ----------snip------ After executing these instructions, the result, 240, will still be stored in the accumulator, but also in memory location 255, and the simulator will stop running. Assuming that you named your object file test.obj, then your run should produce output that looks something like the following: foobar:/working_dir$ java -jar tacsim.jar test.obj Tacsim v0.1 - running test.obj Memory Dump 6 225 1 15 10 255 15 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 240 You may limit the run of your simulator to 10,000 cycles. You may find this helpful for debugging. If you choose to do this then you must print an error that indicates that the simulator exceeded 10,000 cycles. There are several examples of assembler in your book that use the accumulator architecture, e.g., Example 8.2 on page 318. The accumulator architecture was very common in the early days of computing because it is relatively simple to implement in hardware You may find it helpful to study elementary assembly language examples for the 6500 family of microprocessors. The 6500 family was used in the original Atari 2600 and the most capable processor in the family, the 6502, was used in the Apple Il+ and the Commodore 64, among others. I'll list a few resources below that may give you additional insight into assembly language programming with an accumulator architecture. I will point out however, that the 6500 family offers many more instructions than our simple architecture. The instruction set for TAC is listed below. Note that this is almost identical to the table in your book on page 317. A few additional instructions have been added to make this ISA a little bit more interesting. TAC INSTRUCTION SET Op-Code Instruction Addressing Mode Example Action (Microcode) NOP ADD CMP IGT JMP ID Immediate Direct Immediate Immediate Immediate Immediate Direct Indexed Register Direct Immediate Immediate Immediate Immediate NOP ADD data ADD (address) CMP data JGT address JMP address LD data LD (address) LD X(address) MVX ST(address) AND data OR data XOR data JLE address | HLT Do Nothing ACC data) PP java TacSim
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance