Question: CPU Simulator Purpose: To work with the simulation of a simple CPU and its machine language described in Chapter 2 and Appendix C (the Brooshear
CPU Simulator
Purpose: To work with the simulation of a simple CPU and its machine language described in Chapter 2 and Appendix C (the "Brooshear Machine").
Preparation: Before beginning this lab you should read Section 2.2, pages 85-91, and Appendix C, pages 569-570. You should be able to convert to and from hexadecimal.
Background:
Chapter 2 of the text describes a basic CPU and uses it to show the machine cycle as the CPU fetches, decodes and executes machine instructions.
If you wanted to add two numbers together, for example, such as 14 and -6, these would have to be converted to two's complement notation in 8 bits. 14 converts to 0000 1110 in two's complement, binary notation, 8 bits. -6 converts to 1111 1010 in the same notation.
Now we need to convert the binary to hexadecimal which we do by replacing each four bits with a hexadecimal digit as in Figure 1.6 on page 25 of the text. 0000 1110 converts to 0e 1111 1010 converts to fa.
To add these we need to enter them into memory cells. The cells hold 16 bits each in Memory List format, but our data is only 8 bits, so we have to pad our data to fit. We would put 0e00 and fa00 into two cells as data. The extra 00 in each is not used when the data in that address is read.
The Brooshear Machine applet can be found here: http://bmachine.sourceforge.net/ (to be able to run it you will need to have Java installed on your machine). Running the applet is not required for this assignment.
Here is an example of a program to add the two numbers -6 and 14 as entered in the applet. The first five memory locations hold instructions while the next two hold -6 and 14. The address location 0a holds -6 as fa with padding of 00, while address location 0c holds 14 as 0e with padding of 00.
Since the cells in the applet are 16 bits but the cells in the original definition in the textbook are 8 bits, the address here skip every other one. 00 is followed by 02, not 01 - 04 is followed by 06, not 05. The odd address still work, however - they address the second 8 bits in a cell. So, the address 0b would retrieve the low order bits 00 in the address 0a.
Assignment:
The image on the previous page shows the Brooshear Machine solution for adding 14 and -6. Modify the code so that it adds 2, 12, and -4 instead. The image below can be used as a reference for memory locations and CPU register names.
Please submit your solution into the dropbox for week 3 as a simple text file, a Word document, a PDF document, or an image.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
