-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaccumulate.asm
76 lines (53 loc) · 1.02 KB
/
accumulate.asm
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
; A subprogram that accumulates the line-separated decimal numbers sent through the serial line.
; The result is both written to the LCD and the serial line.
#include "layouts/subeater.asm"
; Allocate a string buffer
#bank ram
string_buffer: #res 256
; Main program
#bank program
reset:
; Init LCD
jsr lcd_init
; Configure UART
jsr uart_init
; Init accumulator in r0
wrw #0 r0
; Write 0 to LCD display
lda #"0"
jsr lcd_print_char
; Loop over lines
.line_loop:
; Read line to a0
wrw #string_buffer a0
jsr uart_readline
; Convert to base10
jsr from_base10
; Add to accumulator
clc
lda a0
adc r0
sta r0
lda a1
adc r1
sta r1
; Convert result to base 10
wrw r0 a0
wrw #string_buffer a2
jsr to_base10
; Print result
jsr lcd_clear
wrw a2 a0
jsr lcd_print_str
; Write to serial
jsr uart_writeline
; Loop over
jmp .line_loop
; Interrupt
nmi:
irq:
rti
; Libraries
#include "libraries/lcd.asm"
#include "libraries/uart.asm"
#include "libraries/decimal.asm"