I finally got to the end of desiging the ALU - the result is documented here https://github.com/Johnlon/spam-1/blob/master/docs/alu_with_carry_in.md
0-7 ALU Ops | 8-15 ALU Ops | 16-23 ALU Ops | 24-31 ALU Ops |
---|---|---|---|
0 | B-1 | A*B (high bits) | A RRC B |
A | A+B*1 | A*B (low bits) | A AND B |
B | A-B*1 | A/B | A OR B |
-A | B-A*1 | A%B | A XOR B |
-B | A-B (special) | A << B | A NAND B |
BA / 10 | A+B+1*2 | A >> B arithmetic | NOT B |
BA % 10 | A-B-1*2 | A >> B logical | A+B (BCD) |
B+1 | B-A-1*2 | A RLC B | A-B (BCD) |
This ALU is based on Warren Toomey's ALU for CscVon8 but with a few significant differences that are detailed in the ALU design page for SPAM-1.
There is a verilog implementation of the ALU https://github.com/Johnlon/spam-1/blob/master/verilog/alu/alu_code.v and a bunch of unit tests for each operation https://github.com/Johnlon/spam-1/blob/master/verilog/alu/test.v.
Once I had that passing I needed to generated an image file for burning a ROM and also because I wanted to use the same data file to drive an alternative impl using a verilog ROM loaded from that datafile so that I could run the CPU and unit test against it.
The approach I took was to create the data file by writing a small verilog program that applied all possible input values to the verilog ALU implentation and then writing the inputs and outputs to disk as a ROM image.
The program was pretty simple https://github.com/Johnlon/spam-1/blob/master/verilog/alu/gen_alu.v and generated all the files I need to create some physical ROMS when I get to the H/W build - which will be as soon as I can clear a space at home to start work.
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.