-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnmultiplier.upv
107 lines (94 loc) · 1.93 KB
/
nmultiplier.upv
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
slide[f]
// multiplier box
// io block
scape[b]{
// If the state of the box is state 0 -- needs a new number to multiply
if0{
// change box state to state 1 -- ready for second number
//#?
slide[d]
push1[u]
slide[u]
//#?
// slide the input value to the left
slide[l]
push[l]
} else {
if1{
// box state is 1 -- store value to left
// debug: print the current value
//#?
slide[d]
push1[u]
slide[u]
//#?
slide[r]
push[r]
// store the input number to the right
} else {
// box state is 2 -- do multiplication
// create a temporary storage for first number
slide[r,f]
// load first number
slide[d]
push#u,l,b,l[u]
slide[u]
// return to center
// using a pathway that does not cause
// any "scape" actions to activate
slide[b,l]
//#?
push[d] // drop value
//#?
// drop multiply signal
push0[u,f,r,d]
}
}
}
slide[f,r]
// counter block
scape[u]{
//1337?
// make this the drop signal block -- when a signal comes from above,
// slide left, increase by second number, then return here
// and decrement the current value until it reaches 0
if0{
//888?
// go to accumulator block
slide[l]
// only happens when multiply engine has finished,
// -- drop current user value --
slide[d,b,b,u]
push[d]
slide[d,f,f,u]
// -----------------------------
// return the value in accumulator to user
push[b,b]
} else {
//111?
// decrement counter block (this)
push1[d]
// go to accumulator block
slide[l]
// increase by second value
slide[d]
push#u,b,r[u]
slide[u]
// debug: print accumulator value
//#?
// slide left again to the repeater block
slide[l]
}
}
slide[l,l]
// repeater block
scape[r]{
// we arrive here mid-multiplication, when we want to return
// two blocks to the right and regenerate the first number
// contents found there
slide[r,r]
// drop multiply signal again
push0[r,u,l,d]
}
slide[r,b]
slide[b]