LM3000 Program
From BenningtonWiki
This program simulates the movement of a ball back and forth on an imaginary screen, bouncing it off the left and right boundaries. The simulation limits the ball's movement to one dimension.
We actually came up with this program before we started building the microprocessor as a "target" program. Because this program has variables and math and branching, it demonstrates all the things that a CPU needs to be Turing complete. So we tried to build a microprocessor that could run it. And we did.
Addr Code Instruction Comment 00 1305 MOV R0, #5 ; x - start the ball in the middle 01 1701 MOV R1, #1 ; dx - initially moving to the right 02 2000 MOV A, R0 ; x = x + dx 03 2500 MOV B, R1 04 4000 ADD R0 05 2000 MOV A, R0 ; hit the left boundary? 06 3700 MOV B, #0 07 4D00 CMP 08 FC01 BEQ 01 ; yes, begin moving to the right 09 3709 MOV B, #9 ; hit the right boundary? 0A 4D00 CMP 0B F802 BNE 02 ; nope 0C 17FF MOV R1, #-1 ; yes, begin moving to the left 0D F002 BRA 02
The equivalent code in C might look like this:
int x, dx; x = 5; dx = 1; while (1) { x += dx; if (x == 0) dx = 1; else if (x == 9) dx = -1; }
