data_test.s
1.84 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#
# data_test.s
#
# This program tests the use of intialized data segments.
#
# One data segent per program is allowed. The assembler directive
# .data can specify an address where this seg should be loaded,
# but since there is no loader, this is only informational (reported
# in the listing file). A future linker/loader may use this info.
#
# Subsequent directives (.byte, .half, .word) will pack data into this
# data segment. Things are aligned to their size, so if you follow a
# single .byte with .word, 3 bytes of padding would be added, etc.
#
# Program labels are allowed to be used with .word, during the second
# pass of the assembler the addresses will be stuffed into the data
# segment (for use as a jump table, etc.). Labels are *not* allowed
# in .byte or .half directives.
#
# The compiler will (for now) generate a separate data file,
# containing the data block. This block must be loaded into
# DMEM at the place the assembly code expects. Then you can load
# data, pointers, etc. from DMEM and use them as you see fit.
#
# Wed Jun 22 14:22:11 PDT 1994
#
#define IMEMBASE 0x10002000
#define DMEMBASE 0x10000000
.base IMEMBASE
.data DMEMBASE # where we need to load the data segment
.byte 0xff
.half 0xaabb # will align with padding
.word 0xdeadbeef
#define JUMPTABLE_OFFSET 8 /* in bytes */
.word lab0
.word lab1
.word lab2
.word lab3
.word lab4
.word lab5
addi $7, $0, 0
lui $7, 0x1000
addi $7, $7, JUMPTABLE_OFFSET
nop
sll $1, $1, 2 # $1 holds jump table item
add $7, $7, $1
nop
lw $2, 0($7)
jr $2
nop
lab0: addi $0, $0, 0
addi $10, $0, 0
nop
break
lab1: addi $0, $0, 0
addi $10, $0, 1
nop
break
lab2: addi $0, $0, 0
addi $10, $0, 2
nop
break
lab3: addi $0, $0, 0
addi $10, $0, 3
nop
break
lab4: addi $0, $0, 0
addi $10, $0, 4
nop
break
lab5: addi $0, $0, 0
addi $10, $0, 5
nop
break