Created
April 6, 2012 20:38
-
-
Save Wollw/2322762 to your computer and use it in GitHub Desktop.
DCPU-16 Examples
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; Calculate each factorial from 1! -> N! where N the initial value | |
; of register B. When finished it pops each result into register J. | |
SET B, 5 | |
SET C, 0 | |
:LOOP | |
ADD C, 1 | |
SET A, C | |
JSR FACTORIAL | |
SET PUSH, A | |
IFN C, B | |
SET PC, LOOP | |
SET PC, POPSTACK | |
:POPSTACK | |
SET J, POP | |
SUB C, 1 | |
IFN C, 0 | |
SET PC, POPSTACK | |
SET PC, EXIT | |
:FACTORIAL | |
SET PUSH, B | |
SET B, 1 | |
:FACTORIALLOOP | |
MUL B, A | |
SUB A, 1 | |
IFG A, 1 | |
SET PC, FACTORIALLOOP | |
SET A, B | |
SET B, POP | |
SET PC, POP | |
:EXIT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; Calculates the factorial of the number in register A | |
; Result is stored in register B | |
SET A, 5 | |
SET B, 1 | |
:FACTORIAL | |
MUL B, A | |
SUB A, 1 | |
IFN A, 0 | |
SET PC, FACTORIAL |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; | |
; A Lucas Sequence calculator in DCPU-16 Assembly | |
; | |
; Starting state: | |
; | |
; A == N-2 | |
; B == N-1 | |
; C == Lucas Sequence Length | |
; | |
; Each number in the sequence is pushed to the stack after being | |
; calculated and then all the numbers are popped into register J | |
; when finished. | |
SET A, 0 ; First Number | |
SET B, 1 ; Second Number | |
SET C, 6 ; Sequence Length | |
SET Y, C | |
SUB C, 2 | |
SET PUSH, A | |
SET PUSH, B | |
:LUCAS | |
SET X, B | |
ADD B, A | |
SET A, X | |
SET PUSH, B | |
SUB C, 1 | |
IFN C, 0 | |
SET PC, LUCAS | |
:POPVALUES | |
SET J, POP | |
ADD C, 1 | |
IFN Y, C | |
SET PC, POPVALUES |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment