blob: c20cad0c759da5439c6c6549667bc24492b967f6 (
plain)
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
|
.data 128
idfmt:
.c "received %d\n"
failure_message:
.c "numbers don't add up to zero\n"
report_message:
.c "failed: got %i instead of %i\n"
succeeded_message:
.c "succeeded\n"
.code
jmpi main
/*
static int
identity (int arg)
{
printf ("received %i\n", arg);
return arg;
}
*/
name identify
identify:
prolog
arg $i
getarg %v0 $i
prepare
pushargi idfmt
ellipsis
pushargr %v0
finishi @printf
retr %v0
epilog
name identity_func
identity_func:
prolog
arg $i
getarg %r1 $i
/* Store the argument on the stack. */
allocai $(__WORDSIZE >> 3) $off
stxi $off %fp %r1
/* Store the negative of the argument on the stack. */
allocai $(__WORDSIZE >> 3) $neg
negr %r2 %r1
stxi $neg %fp %r2
/* Invoke FUNC. */
prepare
pushargr %r1
finishi identify
/* Ignore the result. */
/* Restore the negative and the argument from the stack. */
ldxi %r2 %fp $neg
ldxi %v1 %fp $off
/* Make sure they still add to zero. */
addr %r0 %v1 %r2
bnei branch %r0 0
/* Return it. */
retr %v1
/* Display a failure message. */
branch:
prepare
pushargi failure_message
ellipsis
finishi @printf
/* Leave. */
retr %v1
epilog
name main
main:
prolog
prepare
pushargi 7777
finishi identity_func
retval %r0
beqi succeeded %r0 7777
prepare
pushargi report_message
ellipsis
pushargr %r0
pushargi 7777
finishi @printf
reti 1
succeeded:
prepare
pushargi succeeded_message
ellipsis
finishi @printf
reti 0
epilog
|