OpenCores
URL https://opencores.org/ocsvn/light8080/light8080/trunk

Subversion Repositories light8080

[/] [light8080/] [trunk/] [sw/] [demos/] [hello/] [hello.asm] - Blame information for rev 86

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 74 ja_rd
;*******************************************************************************
2
; tb1.asm -- light8080 core basic demo: 'Hello World!"
3
;*******************************************************************************
4
; Should be used with SoC vhdl\soc\l80soc.vhdl
5
; Assembler format compatible with TASM for DOS and Linux.
6
;*******************************************************************************
7
; This program will print a Hello message to a 9600/8/N/1 serial port, then
8
; will loop forever copying the input port P1 to the output port P2.
9
; This demo is meant to be used as a starting point for those wanting to play
10
; with the l80soc core -- which in turn is little more than an usage example
11
; for the light8080 cpu core.
12
; See the readme file for instructions for setting up a project with this
13
; program on Digilentic's DE-1 development board.
14
;*******************************************************************************
15
 
16
; DS pseudo-directive; reserve space in bytes, without initializing it
17
#define ds(n)    \.org $+n
18
 
19
MASK_RX_IRQ:  .equ 20h
20
MASK_TX_IRQ:  .equ 10h
21
MASK_RX_RDY:  .equ 02h
22
MASK_TX_RDY:  .equ 01h
23
 
24
UART_DATA:    .equ 80h
25
UART_STATUS:  .equ 81h
26
UART_BAUDL:   .equ 82h
27
UART_BAUDH:   .equ 83h
28
IRQ_ENABLE:   .equ 88h
29
 
30
P1IN:         .equ 84h
31
P2OUT:        .equ 86h
32
 
33
 
34
;*******************************************************************************
35
 
36
          .org  0H              ; Reset entry point
37
          jmp   start           ; Skip the rst address area
38
 
39
        ;***** Interrupt vectors in area 0008h-0038h *****************
40
 
41
          .org  0h+(1*8)        ; interrupt vector 1
42
          ret
43
          .org  0h+(2*8)        ; interrupt vector 2
44
          ret
45
          .org  0h+(3*8)        ; interrupt vector 3
46
          ret
47
          .org  0h+(4*8)        ; interrupt vector 4
48
          ret
49
          .org  0h+(5*8)        ; interrupt vector 5
50
          ret
51
          .org  0h+(6*8)        ; interrupt vector 6
52
          ret
53
 
54
          .org  0h+(7*8)        ; interrupt vector 7
55
int38h:   jmp   irq_uart        ; UART interrupt
56
 
57
          ;***** program entry point *******************************************
58
 
59
start:    .org  60H
60
          lxi   sp,stack
61
 
62
          ; Initialize UART RX and TX buffers
63
          lxi   h,void_buffer
64
          shld  ptr_tx
65
          lxi   h,rx_buffer
66
          shld  ptr_rx
67
          ; Set up UART baud rate to 9600 bauds @ 50MHz:
68
          ; (50E6 / 9600) = 5208d = 1458h
69
          mvi   a,14h
70
          out   UART_BAUDH
71
          mvi   a,58h
72
          out   UART_BAUDL
73
 
74
          ; Clear P2 port
75
          mvi   a,00h
76
          out   P2OUT
77
 
78
          ; Set up interrupts
79
          mvi   a,08h           ; Enable UART irq...
80
          out   IRQ_ENABLE
81
          ei                    ; ...and enable interrupts in the CPU
82
 
83
          ; print hello message to console
84
          lxi   h,msg_hello
85
          call  print_string
86
 
87
forever:
88
          in    P1IN
89
          mov   c,a
90
          rlc
91
          rlc
92
          add   c
93
          out   P2OUT
94
          jmp   forever
95
 
96
          di
97
          hlt
98
done:     jmp   done
99
 
100
msg_hello: .text "\n\r\nHello World!$\000"
101
 
102
;irq_uart: UART interrupt processing
103
irq_uart:
104
          push  h
105
          push  psw
106
 
107
          ; Deal with RX interrupt (if any) first and then the TX interrupt.
108
          in    UART_STATUS     ; Is there new data in the RX register?
109
          ani   MASK_RX_IRQ
110
          jz    irq_uart_rx_done ; If there isn't, process TX interrupt.
111
 
112
          ; Process UART RX interrupt
113
irq_uart_rx:
114
          mvi   a,MASK_RX_IRQ   ; Clear IRQ flag.
115
          out   UART_STATUS
116
          in    UART_DATA       ; Get RX byte...
117
          out   P2OUT           ; ...display it in the output port...
118
          lhld  ptr_rx          ; ...and store it in the rx buffer.
119
          mov   m,a
120
          inx   h
121
          shld  ptr_rx          ; Update the rx buffer pointer.
122
          ; Note there's no check for RX buffer overrun!
123
 
124
irq_uart_rx_done:
125
          ; Ok, RX is done. Now deal with TX irq, if any
126
          in    UART_STATUS     ; Is the TX buffer re new data in the RX register?
127
          ani   MASK_TX_IRQ
128
          jz    irq_uart_end    ; If there isn't, we're done.
129
 
130
          ; process UART TX interrupt
131
irq_uart_tx:
132
          mvi   a,MASK_TX_IRQ   ; Clear IRQ flag.
133
          out   UART_STATUS
134
          lhld  ptr_tx          ; Get next byte from the TX buffer
135
          mov   a,m
136
          cpi   '$'             ; Did we reach the end of the buffer?
137
          jz    irq_uart_tx_done ; If we did, we're done here...
138
          inx   h               ; ...otherwise increment the TX pointer...
139
          shld  ptr_tx
140
          out   UART_DATA       ; ...and transmit the data byte.
141
 
142
irq_uart_tx_done:
143
 
144
irq_uart_end:
145
          pop   psw             ; Done, quit.
146
          pop   h
147
          ei
148
          ret
149
          ; Note there's no check for RX buffer overrun! we shouldn't need it
150
          ; in this program, anyway.
151
 
152
 
153
;print_string: print $-terminated string at HL
154
; Returns as soon as the transmission has started; transmission proceeds in
155
; 'background' through the UART interrupt service routine.
156
print_string:
157
          ; We don't check if there's a transmission going on, we just start
158
          ; transmitting. Not suitable for real use!
159
          mov   a,m             ; Get first character from string...
160
          inx   h               ; ...and move updated string pointer to TX
161
          shld  ptr_tx          ; buffer pointer.
162
          cpi   '$'             ; Kickstart transmission by sending 1st byte...
163
          jz    print_string_end; ...unless its the end of string marker.
164
          out   UART_DATA       ;
165
print_string_end:
166
          ret
167
 
168
 
169
          ; data space, placed immediately after object code in memory
170
void_buffer:  .text "$"
171
ptr_tx:       ds(2)
172
ptr_rx:       ds(2)
173
rx_buffer:    ds(32)
174
              ds(64)
175
stack:        ds(2)
176
          .end
177
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.