Back to DFS's Workshop Page
Back to Agenda Page
This problem is part of the larger CPU Register Math project. It will simulate how addition can be performed with the 8-bit register 6502 CPU.
For this problem, you are to cannibalize any available code and write a pair of scripts which will accept two decimal inputs from the user and show how registers in the CPU can be used to add their binary equivalents.
Your code should produce representations of the CPU registers which look like the one below.
Add Register X to Register A
| A | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 1 |
|---|---|---|---|---|---|---|---|---|
| X | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 1 |
| Y | ? | ? | ? | ? | ? | ? | ? | ? |
Provide a short description of the action being taken.
To indicate which register has just been manipulated, display the row entries in red.
If a register has not as yet been used, have a query (?) represent each bit. (In reality, each bit in the CPU would contain a 1 or 0.)
Your solution should utilize two scripts.
To see how this could work, view this possible solution.
A default color can be specified in the function declaration by doing something such as the following:
function printregister($label, $bin, $color="BLACK")
This allows you to call the function with either two or three arguments. If you use two arguments, $color will have the value "black"; if you use three, the value passed to the function will be used.