-
Notifications
You must be signed in to change notification settings - Fork 3
/
variable.c
149 lines (120 loc) · 2.03 KB
/
variable.c
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/*
* variable.c
*
* Variable manipulation routines
*
*/
#include "ztypes.h"
/*
* load
*
* Load and store a variable value.
*
*/
#ifdef __STDC__
void load (zword_t variable)
#else
void load (variable)
zword_t variable;
#endif
{
store_operand (load_variable (variable));
}/* load */
/*
* push_var
*
* Push a value onto the stack
*
*/
#ifdef __STDC__
void push_var (zword_t value)
#else
void push_var (value)
zword_t value;
#endif
{
stack[--sp] = value;
}/* push_var */
/*
* pop_var
*
* Pop a variable from the stack.
*
*/
#ifdef __STDC__
void pop_var (zword_t variable)
#else
void pop_var (variable)
zword_t variable;
#endif
{
store_variable (variable, stack[sp++]);
}/* pop_var */
/*
* increment
*
* Increment a variable.
*
*/
#ifdef __STDC__
void increment (zword_t variable)
#else
void increment (variable)
zword_t variable;
#endif
{
store_variable (variable, load_variable (variable) + 1);
}/* increment */
/*
* decrement
*
* Decrement a variable.
*
*/
#ifdef __STDC__
void decrement (zword_t variable)
#else
void decrement (variable)
zword_t variable;
#endif
{
store_variable (variable, load_variable (variable) - 1);
}/* decrement */
/*
* increment_check
*
* Increment a variable and then check its value against a target.
*
*/
#ifdef __STDC__
void increment_check (zword_t variable, zword_t target)
#else
void increment_check (variable, target)
zword_t variable;
zword_t target;
#endif
{
short value;
value = (short) load_variable (variable);
store_variable (variable, ++value);
conditional_jump (value > (short) target);
}/* increment_check */
/*
* decrement_check
*
* Decrement a variable and then check its value against a target.
*
*/
#ifdef __STDC__
void decrement_check (zword_t variable, zword_t target)
#else
void decrement_check (variable, target)
zword_t variable;
zword_t target;
#endif
{
short value;
value = (short) load_variable (variable);
store_variable (variable, --value);
conditional_jump (value < (short) target);
}/* decrement_check */