Pristine Ack-5.5
[Ack-5.5.git] / util / int / do_branch.c
1 /*
2  * Sources of the "BRANCH" group instructions
3  */
4
5 /* $Id: do_branch.c,v 2.3 1994/06/24 10:46:07 ceriel Exp $ */
6
7 #include        <em_abs.h>
8 #include        "global.h"
9 #include        "log.h"
10 #include        "mem.h"
11 #include        "trap.h"
12 #include        "text.h"
13 #include        "fra.h"
14 #include        "warn.h"
15
16 /*      Note that in the EM assembly language brach instructions have
17         lables as their arguments, where in the EM machine language they
18         have (relative) offsets as parameters.  This is not described in the
19         EM manual but follows from the Pascal interpreter.
20 */
21
22 #define do_jump(j)      { newPC(PC + (j)); }
23
24 DoBRA(jump)
25         register long jump;
26 {
27         /* BRA b: Branch unconditionally to label b */
28
29         LOG(("@B6 DoBRA(%ld)", jump));
30         do_jump(arg_c(jump));
31 }
32
33 DoBLT(jump)
34         register long jump;
35 {
36         /* BLT b: Branch less (pop 2 words, branch if top > second) */
37         register long t = wpop();
38
39         LOG(("@B6 DoBLT(%ld)", jump));
40         spoilFRA();
41         if (wpop() < t)
42                 do_jump(arg_c(jump));
43 }
44
45 DoBLE(jump)
46         register long jump;
47 {
48         /* BLE b: Branch less or equal */
49         register long t = wpop();
50
51         LOG(("@B6 DoBLE(%ld)", jump));
52         spoilFRA();
53         if (wpop() <= t)
54                 do_jump(arg_c(jump));
55 }
56
57 DoBEQ(jump)
58         register long jump;
59 {
60         /* BEQ b: Branch equal */
61         register long t = wpop();
62
63         LOG(("@B6 DoBEQ(%ld)", jump));
64         spoilFRA();
65         if (t == wpop())
66                 do_jump(arg_c(jump));
67 }
68
69 DoBNE(jump)
70         register long jump;
71 {
72         /* BNE b: Branch not equal */
73         register long t = wpop();
74
75         LOG(("@B6 DoBNE(%ld)", jump));
76         spoilFRA();
77         if (t != wpop())
78                 do_jump(arg_c(jump));
79 }
80
81 DoBGE(jump)
82         register long jump;
83 {
84         /* BGE b: Branch greater or equal */
85         register long t = wpop();
86
87         LOG(("@B6 DoBGE(%ld)", jump));
88         spoilFRA();
89         if (wpop() >= t)
90                 do_jump(arg_c(jump));
91 }
92
93 DoBGT(jump)
94         register long jump;
95 {
96         /* BGT b: Branch greater */
97         register long t = wpop();
98
99         LOG(("@B6 DoBGT(%ld)", jump));
100         spoilFRA();
101         if (wpop() > t)
102                 do_jump(arg_c(jump));
103 }
104
105 DoZLT(jump)
106         register long jump;
107 {
108         /* ZLT b: Branch less than zero (pop 1 word, branch negative) */
109
110         LOG(("@B6 DoZLT(%ld)", jump));
111         spoilFRA();
112         if (wpop() < 0)
113                 do_jump(arg_c(jump));
114 }
115
116 DoZLE(jump)
117         register long jump;
118 {
119         /* ZLE b: Branch less or equal to zero */
120
121         LOG(("@B6 DoZLE(%ld)", jump));
122         spoilFRA();
123         if (wpop() <= 0)
124                 do_jump(arg_c(jump));
125 }
126
127 DoZEQ(jump)
128         register long jump;
129 {
130         /* ZEQ b: Branch equal zero */
131
132         LOG(("@B6 DoZEQ(%ld)", jump));
133         spoilFRA();
134         if (wpop() == 0)
135                 do_jump(arg_c(jump));
136 }
137
138 DoZNE(jump)
139         register long jump;
140 {
141         /* ZNE b: Branch not zero */
142
143         LOG(("@B6 DoZNE(%ld)", jump));
144         spoilFRA();
145         if (wpop() != 0)
146                 do_jump(arg_c(jump));
147 }
148
149 DoZGE(jump)
150         register long jump;
151 {
152         /* ZGE b: Branch greater or equal zero */
153
154         LOG(("@B6 DoZGE(%ld)", jump));
155         spoilFRA();
156         if (wpop() >= 0)
157                 do_jump(arg_c(jump));
158 }
159
160 DoZGT(jump)
161         register long jump;
162 {
163         /* ZGT b: Branch greater than zero */
164
165         LOG(("@B6 DoZGT(%ld)", jump));
166         spoilFRA();
167         if (wpop() > 0)
168                 do_jump(arg_c(jump));
169 }