-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprintFib.asm
More file actions
101 lines (80 loc) · 1.78 KB
/
printFib.asm
File metadata and controls
101 lines (80 loc) · 1.78 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
; set cursor stuff:
ldi xr #0E ; Display on, cursor on, blink off : 00001110
jmp writeSet
; entry mode set
ldi xr #06 ; Increment and shift curosr, don't shift display, 00000110
jmp writeSet
; write fib
ldi xr 'F' ; print F
jmp writeChar
ldi xr 'i' ; print i
jmp writeChar
ldi xr 'b' ; print b
jmp writeChar
; load initial values and print them
ldi xr #0 ; load 0
stw xr #90 ; store in addr1
ldw yr ascii
addu xr ; add ascii offset
jmp writeChar ; print 0
ldw xr sep ; load and print comma
jmp writeChar
ldi xr #1 ; load 1
stw xr #91
ldw yr ascii
addu xr ; add ascii offset
jmp writeChar ; print 1
ldw xr sep ; load and print comma
jmp writeChar
fib:
ldw xr #$90 ; load values, add and store result
ldw yr #$91
stw yr #$90
addu xr
stw xr #$91
ldi yr #9 ; Check if val is bigger than 9, if so exit
bgt loop
ldw yr ascii ; Add ascii offset
addu xr
jmp writeChar
ldw xr sep ; load and print comma
jmp writeChar
jmp fib
writeSet:
stw xr #FE ; store to port B
ldi xr #0 ; clear RS/RW/E bits
stw xr #FF ; store to port A
ldw xr enable ; enable write to lcd
stw xr #FF ; store to port A
ldi xr #0 ; clear RS/RW/E bits
stw xr #FF ; store to port A
ret
writeChar:
stw xr #FE ; store to port B
ldw xr rs ; set register select
stw xr #FF ; store to port A
ldw xr enrs ; enable write to lcd
stw xr #FF ; store to port A
ldw xr rs ; clear RS/RW/E bits
stw xr #FF ; store to port A
ret
loop:
jmp writeSet ;
jmp loop ; loop forever
.org #$78 ; place following code at address 0x1E
porta:
.word #FF ; place literal 0x5 at this address
portb:
.word #FE ; place literal 15 at this address
enable:
.word #80 ; store 10000000
rw:
.word #40 ; store 01000000
rs:
.word #20 ; store 00100000
enrs:
.word #A0
ascii:
.word #30 ;
sep:
.word ','