-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathpreprocessor_test.psm
64 lines (61 loc) · 2.33 KB
/
preprocessor_test.psm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
;This is a program to test the
;new features of the preprocessor,
;the `<code>display</code>` directive,
;`<code>if</code>`-`<code>else</code>` branching and
;`<code>while</code>` loops, by
;printing the Fibonacci numbers
;smaller than 1000 on the terminal
;during the assembly time.
;This program compiles to no machine
;code at all, and it does nothing except
;causing an error message right after
;assembly (that the assembler written in
;JavaScript sent no machine code to the
;main program written in Java) in
;<a href="https://github.com/FlatAssembler/PicoBlaze_Simulator_for_Android">PicoBlaze Simulator for Android</a>.
;I have started a
;<a href="https://board.flatassembler.net/topic.php?p=232650#232650">forum thread about this program</a>.
;<b style="color: #770000">WARNING</b>: Please do not press
; "<i>Highlight Assembly</i>"
; before you assemble this program,
; as there is a bug in the syntax
; highlighter inserting a
; semi-colon after the less-than
; and greater-than characters,
; causing syntax errors in programs
; such as this one. I have opened
; a <a href="https://github.com/FlatAssembler/PicoBlaze_Simulator_in_JS/issues/7">GitHub issue about that</a>.
base_decimal ;The PicoBlaze assembler by default considers numerical literals to be hexadecimal.
display "We are about to display Fibonacci numbers smaller than 1000 in the UART terminal... "
display a'x ;0xa=='\n', a new-line character.
constant first, 0
constant second, 1
while first < 1000
if first < 10
display "0" + first
display " " ;In case inserting a new-line character doesn't work...
;I have opened <a href="https://github.com/FlatAssembler/PicoBlaze_Simulator_in_JS/issues/8">a GitHub issue about that problem</a>.
display a'x
else
constant remainder, first
constant counter, 0
while remainder > 10 - 1
constant remainder, remainder - 10
constant counter, counter + 1
endwhile
if counter > 10 - 1 ;If <code>first</code> is bigger than 99.
constant hundreds, 0
while counter > 10 - 1
constant counter, counter - 10
constant hundreds, hundreds + 1
endwhile
display hundreds + "0"
endif
display counter + "0"
display remainder + "0"
display " "
display a'x
endif
constant second, first + second
constant first, second - first
endwhile