File: variable.c

package info (click to toggle)
jzip 202b19981014-3.1
  • links: PTS
  • area: main
  • in suites: sarge, woody
  • size: 404 kB
  • ctags: 799
  • sloc: ansic: 6,312; makefile: 70; sh: 27
file content (100 lines) | stat: -rw-r--r-- 1,514 bytes parent folder | download | duplicates (2)
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
/*
 * variable.c
 *
 * Variable manipulation routines
 *
 */

#include "ztypes.h"

/*
 * load
 *
 * Load and store a variable value.
 *
 */

void load (zword_t variable)
{
    store_operand (load_variable (variable));
}/* load */

/*
 * push_var
 *
 * Push a value onto the stack
 *
 */

void push_var (zword_t value)
{
    stack[--sp] = value;
}/* push_var */

/*
 * pop_var
 *
 * Pop a variable from the stack.
 *
 */

void pop_var (zword_t variable)
{
    store_variable (variable, stack[sp++]);
}/* pop_var */

/*
 * increment
 *
 * Increment a variable.
 *
 */

void increment (zword_t variable)
{
    store_variable (variable, load_variable (variable) + 1);
}/* increment */

/*
 * decrement
 *
 * Decrement a variable.
 *
 */

void decrement (zword_t variable)
{
    store_variable (variable, load_variable (variable) - 1);
}/* decrement */

/*
 * increment_check
 *
 * Increment a variable and then check its value against a target.
 *
 */

void increment_check (zword_t variable, zword_t target)
{
    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.
 *
 */

void decrement_check (zword_t variable, zword_t target)
{
    short value;

    value = (short) load_variable (variable);
    store_variable (variable, --value);
    conditional_jump (value < (short) target);
}/* decrement_check */