-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhello.asm
More file actions
71 lines (53 loc) · 1.5 KB
/
hello.asm
File metadata and controls
71 lines (53 loc) · 1.5 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
# Hello world and interrupt handler demo
# prints "Hello world!" on startup
# echoes data received over UART
# displays a message and toggles a GPIO line every second
###################################
# Main program
main:
# configure timer
# retrieve prescaler value from memory ...
LDA DS, SEGMENT presc_value
LD R2, OFFSET presc_value
# and write it to the timer
LDA DS, SEGMENT TIM_PRESC
ST R2, OFFSET TIM_PRESC
# retrieve counter compare value from memory ...
LDA DS, SEGMENT cmp_value
LD R2, OFFSET cmp_value
# and write it to the timer
LDA DS, SEGMENT TIM_CNT_CMP
ST R2, OFFSET TIM_CNT_CMP
# enable timer
LDA R2, 1
ST R2, OFFSET TIM_EN
# load hello message address into R2 ...
LDA R3, SEGMENT msg_hello
LDA R2, 8
LS R3, R3, R2
LDA R2, OFFSET msg_hello
ADD R2, R2, R3
# and call print_string
CALL print_string
# load interrupt handler address into R2 and write it to the interrupt controller
LDA R3, SEGMENT interrupt_handler
LDA R2, 8
LS R3, R3, R2
LDA R2, OFFSET interrupt_handler
ADD R2, R2, R3
LDA DS, SEGMENT INT_ADDR
ST R2, OFFSET INT_ADDR
# enable UART and timer counter interrupts (bits 0 and 2 of the interupt enable register)
LDA R2, 5
ST R2, OFFSET INT_EN
# infinite loop:
LDA CS, SEGMENT inf_loop
inf_loop: JL R0, OFFSET inf_loop
# end main
###################################
###################################
msg_hello: DW 'H' 'e' 'l' 'l' 'o' 32 'W' 'o' 'r' 'l' 'd' '!' 10 13 0
# Timer prescaler value
presc_value: DW 0xFFFF
# Timer counter compare value (25MHz / 0xFF / 381 = 1Hz)
cmp_value: DW 381