-
Notifications
You must be signed in to change notification settings - Fork 33
/
main.lasm
63 lines (47 loc) · 1.19 KB
/
main.lasm
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
# Tests how the procedures work
#
.segment code
.global asm_main
.define ADDR_DEBUG_QUEUE, 0xF0000
asm_main:
# $k0 always points to ADDR_DEBUG_QUEUE
# since it's a reserved "kernel" register, we're putting it
# to a good use here.
#
li $k0, ADDR_DEBUG_QUEUE
ori $s3, $zero, 0xABBA
# Prepare arguments for prime_sieve
#
ori $a0, $zero, 20 # upto_num
li $a1, prime_arr # address of output array
ori $a2, $zero, 6 # maxprimes
call prime_sieve
li $t5, 0xFAFAFAFA
sw $t5, 0($k0)
move $t4, $v0 # t4 = nprimes
move $t3, $zero # t3 counts the primes for display
show_loop:
slli $t2, $t3, 2 # t2 = t3 * 4
add $t2, $t2, $a1 # t2 points to next prime_arr
lw $t1, 0($t2)
sw $t1, 0($k0)
addi $t3, $t3, 1 # t3++
bltu $t3, $t4, show_loop
li $k1, 0xEEEEBAAB
sw $k1, 0($k0)
# Check how intsqrt works
# ... for a small number
#
ori $a0, $zero, 20
call intsqrt
sw $v0, 0($k0)
# ... and for a large number
li $a0, 103456
call intsqrt
sw $v0, 0($k0)
nop
halt
.segment data
prime_arr:
.word 0
.alloc 100