data_test.s 1.84 KB

 #
 # 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