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

Subversion Repositories lxp32

[/] [lxp32/] [trunk/] [verify/] [lxp32/] [src/] [firmware/] [test009.asm] - Blame information for rev 9

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 9 ring0_mipt
/*
2
 * This test verifies call and ret instructions
3
 */
4
 
5
        lc r100, 0x10000000 // test result output pointer
6
        lc r101, halt
7
        lc r102, failure
8
        lc sp, 0x00010000 // stack pointer
9
 
10
        lc r0, 0x00008000
11
        sw r0, 0
12
 
13
// Test simple procedure call
14
 
15
        lc r1, testproc
16
 
17
        call r1 // testproc
18
 
19
        lw r0, r0
20
        lc r1, 0x11223344
21
 
22
        cjmpne r102, r0, r1 // failure
23
 
24
// Test jump directly to CALL instruction
25
        lc r1, jump_to_call
26
        lc r2, testproc2
27
 
28
        jmp r1
29
        nop
30
        nop
31
        nop
32
 
33
jump_to_call:
34
        call r2
35
 
36
        lw r0, r0
37
        lc r1, 0x55667788
38
 
39
        cjmpne r102, r0, r1 // failure
40
 
41
// Test recursive calls: calculate 10th Fibonnaci number
42
// using recursive algorithm
43
        mov r0, 10 // argument
44
        mov r16, 0 // how many times test_recursive has been called
45
        lc r1, test_recursive
46
        call r1 // test_recursive
47
 
48
        lc r1, 0x00008000
49
        sw r1, r0
50
 
51
        add r1, r1, 4
52
        sw r1, r16
53
 
54
        lc r1, 55
55
        cjmpne r102, r0, r1
56
 
57
        lc r1, 177
58
        cjmpne r102, r16, r1
59
 
60
        sw r100, 1
61
        jmp r101 // halt
62
 
63
failure:
64
        sw r100, 2
65
 
66
halt:
67
        hlt
68
        jmp r101 // halt
69
 
70
testproc:
71
        lc r0, 0x00008000
72
        lc r1, 0x11223344
73
        sw r0, r1
74
        ret
75
 
76
testproc2:
77
        lc r0, 0x00008000
78
        lc r1, 0x55667788
79
        sw r0, r1
80
        ret
81
 
82
test_recursive:
83
        add r16, r16, 1 // increment call counter
84
 
85
// If r0 is 0 or 1, just return
86
        cjmpe rp, r0, 0
87
        cjmpe rp, r0, 1
88
 
89
// Save return address in stack
90
        sub sp, sp, 4
91
        sw sp, rp
92
// Save argument in stack
93
        sub sp, sp, 4
94
        sw sp, r0
95
// Call itself for with (r0-1) and (r0-2) arguments
96
        sub r0, r0, 1
97
        lc r1, test_recursive
98
        call r1
99
// Restore value from stack, save temporary result
100
        lw r1, sp
101
        sw sp, r0
102
 
103
        sub r0, r1, 2
104
        lc r1, test_recursive
105
        call r1
106
 
107
// Restore result from stack
108
        lw r1, sp
109
        add sp, sp, 4
110
 
111
        add r0, r0, r1
112
 
113
// Restore return address
114
        lw rp, sp
115
        add sp, sp, 4
116
        ret

powered by: WebSVN 2.1.0

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