-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo_prime.asm
61 lines (58 loc) · 1001 Bytes
/
demo_prime.asm
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
.org 0x8000 ; ROM
push a ; dividend sp+5
push a ; result sp+4
push a ; divisor sp+3
push a ; remainder sp+2
push a ; remainder_tmp sp+1
push a ; counter sp
start:
ld a,3 ;
st a,[sp + 5]
st a,[sp + 4]
ld a,2 ;
st a,[sp + 3]
ld a,0 ;
st a,[sp + 2]
st a,[sp + 1]
ld a,8 ;
st a,[sp]
step:
lsh [sp + 4]
ld a,[sp + 2]
st a,[sp + 1]
lshc [sp + 2]
sub [sp],1
jmpc [end]
ld a,[sp + 2]
sub [sp + 2],[sp + 3]
jmpcc [step]
st a,[sp + 2]
jmp [step]
end:
sub [sp + 1],1
jmpc [next_div]
sub [sp + 3],3
jmpc [next_div_prime]
add [sp + 3],2
ld a,[sp + 5]
st a,[sp + 4]
ld a,0
st a,[sp + 2]
ld a,8
st a,[sp]
jmp [step]
next_div_prime:
ld o,[sp + 5]
next_div:
ld a,[sp + 5]
add a,1
jmpc [start]
st a,[sp + 5]
st a,[sp + 4]
sub a,1
st a,[sp + 3]
ld a,0
st a,[sp + 2]
ld a,8
st a,[sp]
jmp [step]