/
melonSlicer.s.m4
71 lines (57 loc) · 1.37 KB
/
melonSlicer.s.m4
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
include(macroLibrary.m4)
.section __CODE__
//------------------------------------------------------
// Melon Slicer routines
//------------------------------------------------------
//
// Return - Size of melon thrown by melonthrower
//
FUNCTION(catchMelon,
`
CALL(getRawMelon)
')
//
// Slices melons by choosing a point randomly.
// Param1 - Size of the melon to slice.
// Return - point on melon where the slice happened
//
FUNCTION(sliceMelon,
` movq param1, param2
CALL(randomInterval, $ 1)
')
//
// Puts the melon halfs in a place where the thrower
// can find them. In practical terms, this means
// storing the point on the melon where the slice happened.
//
// Param1 - location of the slice
//
FUNCTION(discardHalfs,
`
CALL(putSlicedMelon)
')
//------------------------------------------------------
// This is the primary Melon Slicer loop
//------------------------------------------------------
//
// Simulates a melon slicing agent!
// Param1 - ignored
// Return - always NULL
//
FUNCTION(melonSlicerLoop,
`
do(`
CALL(catchMelon)
cmpl $0, %eax
jle no_melon
#Caught a melon! Slice it!
CALL(sliceMelon, `%rax')
CALL(discardHalfs, `%rax')
no_melon:
movq _melonSlicerShouldStop@GOTPCREL(%rip), %rax
')while(`$ 0, (%rax)', je)
#Notify done processing
movq _melonSlicerDidStop@GOTPCREL(%rip), %rcx
movl $1, (%rcx)
xorl %eax, %eax #set rv to zero
')