Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Programming Project 1 NOTE: Please provide three classes one for each component: CPU, Memory, and Stack. Memory.java has a main method must have input and

Programming Project 1

NOTE: Please provide three classes one for each component: CPU, Memory, and Stack.

Memory.java has a main method

must have input and output file !!!!!!!!!!!!!!!!!!!!!!!!!!

Your Java computer simulator will be tested with your program and our program to make sure it works correctly.

Programming the Computer Simulator Due on or before 9.30am February 7th, 2023 (Tuesday) Points: 35 In this project we will extend the hypothetical machine discussed in the text on page 6. Our simulated computer has three components: CPU, memory, and stack. The CPU has four registers: PC, IR, AC, and REG, where REG is a special register for holding temporary data in the CPU. All registers are 16 bits wide. This computer has 16 bit instructions and 16 bit operands. The opcodes used by our computer are given below: Opcode Instruction 0001 Load AC from memory 0010 Store AC to memory 0011 Load AC from REG 0100 Store AC to REG 0101 Add to AC from memory 0110 Load REG with operand 0111 Add REG to AC 1000 Multiply REG to AC 1001 Subtract REG from AC 1010 Divide AC by REG value (integer division) 1011 Jump to subroutine starting at the address 1100 Return from subroutine 1111 Halt (end of program) You need to write Java code that will simulate the working of this computer. You will have three classes, one for each component: CPU, Memory, and Stack. The computer should be able to run programs that have subroutines. Every time a subroutine is called, contents of CPU registers are saved in the Stack and whenever the subroutine returns, contents of registers are restored by popping the Stack. Your program should also use three memory locations 940, 941, and 942 (all hexadecimal values). Stack memory starts at memory location zero and ends at memory location 3FF which gives a stack size of 1024 (decimal). All memory locations store 16 bit words. Your program should start from memory location hexa 400 (no overlap with stack memory) and user memory size is 3072 (decimal). This means total memory size = 1024 + 3072 = 4096 locations. The program syntax can be seen in the example input.txt. Each line of code including memory locations are numbered. Each line of code has a sequence number, the memory location, the instruction, and finally a comment that explains what the instruction does; comments start with ';'. Each field is separated by at least one space. The sequence number is in decimal while both memory location and instruction are in hexadecimal. Program sections are separated by lines starting with "=". Blank lines in the input file are ignored by the computer. You should also create own program that has the main section and two subroutines. One of your subroutines should do subtraction and the other one should do division (in input.txt, one does addition and the other does multiplication). Your computer should first read your program, execute instructions in your program line by line, and then produce relevant results in the output file. Each time a subroutine is invoked, your program should push the current values of PC, IR, AC, and REG on to the stack. The output of your program should give the contents of the stack, values of all registers (PC, IR, AC, and REG), and the values of the three memory locations, as shown in the file output.txt (produced by my computer when the program in input.txt was executed). You must also print the total number of instructions executed thus far. The outputs should be printed in hexadecimal except for the number of instructions, which is in decimal. You must print the outputs at the end of each subroutine (before returning from the subroutine) and at the end of the program. Make sure you use appropriate titles for each section of the output as shown in the example output.txt; especially, the subroutine number should appear as in "======Before Return from Subroutine 1 Status======" - you see '1' after the word 'Subroutine'. All hexadecimal values should be printed in uppercase. Your Java computer simulator will be tested with your program and our program to make sure it works correctly. The call to the simulator wiIl allow the input.txt and output.txt files to be provided as arguments to the program. Include your main method in the Memory class. If your simulator has a programming error you will get a grade of zero. Do NOT put your Java code in a package. Zip the three classes together and name the zip file as firstname_lastname.zip. Then upload the zip file to Canvas before the deadline. Also upload your program in a file named firstname_lastname_input.txt and save the output your computer gave in a file named firstname_lastname_output.txt. Be sure to follow the techniques of good programming style and use extensive comments to provide for internal documentation of your Java code. Deliverables: 1. Zip file named firstname_lastname.zip that includes the three classes CPU.java, Memory.java, and Stack.java. Memory.java file contains the main method. 2. Your program file named firstname_lastname_input.txt 3. Your output file named firstname_lastname_output.txt

Input.txt file:

================== ===Main Program===== ================== 1. 400 1940 ;load AC from memory 940 - AC has value 3 2. 401 5941 ;add to AC from memory 941 - AC has value 5 3. 402 2941 ;store AC in memory 941 - 941 has value 5 4. 403 6000 ;load register with 0 5. 404 3000 ;load AC from register - AC is now 0 6. 405 2942 ;store AC to memory 942 - 942 is now 0 7. 406 BA00 ;branch to subroutine starting at address A00 8. 407 BA0A ;branch to subroutine starting at A0A 9. 408 1942 ;load AC from memory 942 - AC is decimal 60 (line 8 subroutine 2) 10. 409 6014 ;load register with 0x14 = decimal 20 11. 40A 7000 ;add register to AC - AC is now decimal 80 12. 40B 2942 ;store AC in memory 942 - 942 is now decimal 80, hex 50 13. 40C F000 ;halt program ========= ;code separator ===== Subroutine 1 ===== ========== 1. A00 6001 ;load register with 1 2. A01 3000 ;load AC from register - AC is now 1 3. A02 6009 ;load register with 9 4. A03 7000 ;add register to AC - AC is now decimal 10, hex A 5. A04 4000 ;store AC in register - register is now decimal 10 6. A05 1942 ;load AC from memory 942 - AC is now 0 (942 is already 0) 7. A06 7000 ;add register to AC - AC is now decimal 10 8. A07 2942 ;store AC in memory 942 - 942 is now decimal 10 9. A08 C000 ;return from subroutine ========= ==== Subroutine 2 ===== ================= 1. A0A 6005 ;load register with 5 2. A0B 3000 ;load AC from register - AC is now 5 3. A0C 600A ;load register with A - decimal 10 4. A0D 8000 ;multiply AC with register - AC is now decimal 50 5. A0E 4000 ;store AC to register - register is now decimal 50 6. A0F 1942 ;load AC from memory 942 - AC is now decimal 10 7. A10 7000 ;add register to AC - AC is now decimal 60 8. A11 2942 ;store AC to memory 942 - 942 is now decimal 60 9. A12 C000 ;return from subroutine ========= === Memory Data ==== =========

1. 940 0003 ;memory location 940 has value 3 2. 941 0002 ;memory location 941 has value 2

Output.txt file

======Before Return from Subroutine 1 Status====== =============Stack Status============= Stack contents at 3FC = 0 Stack contents at 3FD = 0 Stack contents at 3FE = BA00 Stack contents at 3FF = 407 =============Registers & Memory Status============= PC = A08 IR = C000 AC = A REG = A Memory 940 = 3 Memory 941 = 5 Memory 942 = A Number of instructions executed = 16 ======Before Return from Subroutine 2 Status====== =============Stack Status============= Stack contents at 3FC = 0 Stack contents at 3FD = 0 Stack contents at 3FE = BA0A Stack contents at 3FF = 408 =============Registers & Memory Status============= PC = A12 IR = C000 AC = 3C REG = 32 Memory 940 = 3 Memory 941 = 5 Memory 942 = 3C Number of instructions executed = 26 ======End of Program Status====== =============Stack Status============= No data in Stack! =============Registers & Memory Status============= PC = 40D IR = F000 AC = 50 REG = 14 Memory 940 = 3 Memory 941 = 5 Memory 942 = 50 Number of instructions executed = 31

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Big Data, Mining, And Analytics Components Of Strategic Decision Making

Authors: Stephan Kudyba

1st Edition

1466568704, 9781466568709

More Books

Students also viewed these Databases questions

Question

Explain demotion as an alternative to termination.

Answered: 1 week ago

Question

Discuss termination of employees at various levels.

Answered: 1 week ago

Question

Discuss the various approaches to disciplinary action.

Answered: 1 week ago