-
Notifications
You must be signed in to change notification settings - Fork 0
/
mult.asm
110 lines (98 loc) · 1.83 KB
/
mult.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
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
108
109
110
.export
.data
zero: 0
a: 0
b: -1
c: -7
tmp: 0
tmpb: 0
tmpc: 0
sig: 0
one: 1
minusOne: -1
max: 0
inc: 0
.text
start:
mult:
a a // a = 0;
sig sig // sig = 0;
// if (-b <= 0) goto bpos;
tmp tmp
b tmp bpos
minusOne sig // sig++;
// tmpb = -b;
tmpb tmpb
b tmpb
zero zero checkc // goto check;
bpos:
// tmpb = b;
tmpb tmpb
b zero
zero tmpb
zero zero
checkc:
// if (-c <= 0) goto cpos;
tmp tmp
c tmp cpos
minusOne sig // sig++;
// tmpc = -c;
tmpc tmpc
c tmpc
zero zero multMax // goto multMax;
cpos:
// tmpc = c;
tmpc tmpc
c zero
zero tmpc
zero zero
multMax:
// if (tmpb - tmpc <= zero) goto loopB;
tmp tmp
tmpb zero
zero tmp
zero zero
tmpc tmp loopB
zero zero loopC // goto loopC;
loopB:
// max = tmpb;
max max
tmpb zero
zero max
zero zero
// inc = -tmpc;
inc inc
tmpc inc multLoop // goto multLoop;
loopC:
// max = tmpc;
max max
tmpc zero
zero max
zero zero
// inc = -tmpb;
inc inc
tmpb inc
multLoop:
zero max multSig // if (max <= 0) goto multSig;
inc a // a = a - (-tmpc or -tmpb);
one max // max--;
zero zero multLoop // goto multLoop;
multSig:
one sig checkgeq // sig--; if (sig <= 0) goto checkgeq;
zero zero multDone // goto multDone;
checkgeq:
// if (-sig <= 0) goto multNeg;
tmp tmp
sig tmp multNeg
zero zero multDone // goto multDone;
multNeg:
// tmp = a;
tmp tmp
a zero
zero tmp
zero zero
// a = -tmp;
a a
tmp a
multDone:
zero zero multDone