With everything together I wanted to do something interesting on my Working Digital Computer Version 1 so I wrote the following program to calculate the first few numbers in the Fibonacci sequence (which we know starts with 0, 1 and that each subsequent element is the sum of the previous two numbers in the sequence (so 0, 1, 1, 2, 3, 5, 8, 13...)).
; Calculate the first few Fibonacci numbers.
; Assumes that the first two numbers 0 and 1 are in the
; INPUT Encoder A and Encoder B addresses.
;
1000 1000 RIN A ; Read the first seed
0110 0000 TRA ; Transfer A to X
1000 0100 RIN B ; Read the second seed
0001 1100 STO C1 ; Save the last number
0100 1101 ADD 4 ; A + X Result in A
1110 0011 RUT 1s ; Result < 10 show in OUTPUT
0001 0010 STO C2 ; Remember result
1000 1100 RIN C1 ; Get last number
0110 0000 TRA ; Transfer A to X
1000 0010 RIN C2 ; Get current result back
1010 0001 SHL 1 ; Is the current result >= 8?
1001 0001 COJ 1 ; Result >= 8
1000 0010 RIN C2 ; Get current result back
0001 1100 STO C1 ; New last number
0101 1101 JMP 4 ; Go back to add
1101 0001 ENJ 1 ; Jump to location
1000 0010 RIN C2 ; Get current result back
0100 0000 ADD ; A + X Result in A
1110 1111 RUT BCD ; Convert binary to BCD put result in OUTPUT
0000 0111 NOP ANS ; Final result
The hardest part was keeping the program length down to 20 instructions, the current limit for my "low density" drum memory. I'll have to get going on the "high density" drum if I want to do more. I've "run" the program a few times and it seems to operate as expected. I guess my current thinking is to make a video of WDC-1 in action.
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.