add-sub.s 1.04 KB
Newer Older
Benoit Perrot's avatar
Benoit Perrot committed
1
2
3
### runtime library
	.text
exit:
4
	li	$a0, 0
Benoit Perrot's avatar
Benoit Perrot committed
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
	li	$v0, 10
	syscall
print:
	li	$v0, 4
	syscall
	jr	$ra
print_int:
	li	$v0, 1
	syscall
	jr	$ra

	.data
eol:
	.asciiz "\n"

	.text
main:
### test instructions:	add, addi, addu, addui
	li	$t0, 42
	li	$t1, 2055
	li	$t2, 0x7fffffff
	li	$t3, 0x7ffff7d0
	
	## signed addition
	add	$a0, $t0, $t1
	jal	print_int
	la	$a0, eol
	jal	print
	addi	$a0, $t0, 2055
	jal	print_int
	la	$a0, eol
	jal	print

	## unsigned addition, no overflow-checking
	addu	$a0, $t2, $t3
	jal	print_int
	la	$a0, eol
	jal	print
	addiu	$a0, $t2, 0x7ffff7d0
	jal	print_int
	la	$a0, eol
	jal	print

### test instructions:	sub, sub immediate, subu, subu immediate
	li	$t0, 2139
	li	$t1, 42
	li	$t2, 0x80000000
	li	$t3, 0x7ffff7cf

	## signed substraction
	sub	$a0, $t1, $t0
	jal	print_int
	la	$a0, eol
	jal	print
	sub	$a0, $t0, 42
	jal	print_int
	la	$a0, eol
	jal	print

	## unsigned substraction, no overflow-checking
	subu	$a0, $t2, $t3
	jal	print_int
	la	$a0, eol
	jal	print
	subu	$a0, $t2, 0x7ffff7cf
	jal	print_int
	la	$a0, eol
	jal	print

end:
	j	exit