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

Subversion Repositories RISCMCU

[/] [RISCMCU/] [trunk/] [asm/] [counter.asm] - Blame information for rev 30

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

Line No. Rev Author Line
1 25 yapzihe
; This program is for simulation purpose
2
; It demo how the MCU output 3, 2 and 1 to each port (Port B, Port C and Port D)
3
; There are 3 approaches used in accomplishing the above task
4
 
5
.include "riscmcu.inc"
6
 
7
.def    B = r16
8
.def    C = r17
9
.def    D = r18
10
.def    TEMP = r19
11
 
12
 
13
 
14
        rjmp    reset           ; reset vector
15
        ret                     ; external interrupt vertor(not use)
16
        ret                     ; timer overflow interrupt vertor (not use)
17
 
18
 
19
reset:
20
        clr     TEMP            ; r19 = 00
21
        com     TEMP            ; r19 = FF
22
        out     DDRB,TEMP       ; set all Port B pins as output
23
        out     DDRC,TEMP       ; set all Port C pins as output
24
        out     DDRD,TEMP       ; set all Port D pins as output
25
 
26
 
27
 
28
; Approach 1, output to Port B
29
 
30
        ldi     B,3             ; r16 = 03
31
again1: out     PORTB,B         ; Port B now output 03
32
        dec     B               ; r16 = r16 - 1
33
        cpi     B,0             ; if r16 = 0,
34
        brne    again1          ;   branch to again1
35
 
36
 
37
 
38
; Approach 2, output to Port C
39
 
40
        clr     TEMP            ; r19 = 00
41
        inc     C               ; r17 = 01
42
        inc     C               ; r17 = 02
43
        inc     C               ; r17 = 03
44
again2: out     PORTC,C         ; Port C now output 03
45
        subi    C,1             ; r17 = r17 - 1
46
        cpse    C,TEMP          ; if r17 != r19 (means if r17 != 0),
47
        rjmp    again2          ;    branch to again2
48
 
49
 
50
 
51
; Approach 3, output to Port D
52
 
53
        clr     D               ; r18 = 00
54
        subi    D,-3            ; r18 = r18 - (-3) = 03
55
again3: out     PORTD,D         ; Port D now output 03
56
        dec     D               ; r18 = r18 -1
57
        in      TEMP,SREG       ; transfer the value of SR to R19
58
        sbrs    TEMP,1          ; if bit 1 in R19 (the Z-flag) is set, skip the next instruction
59
        rjmp    again3          ;    else branch to again3
60
 
61
 
62
 
63
end:    rjmp    end             ; Branch Forever
64
        sei                     ; (Set I-Bit in SR) This 2 instructions won't execute
65
        set                     ; (Set T-Bit in SR)   even they are fetched to the IR
66
 
67
 
68
 
69
 

powered by: WebSVN 2.1.0

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