https://github.com/akkartik/mu/blob/master/subx/017jump_disp8.cc
  1 //: jump to 8-bit offset
  2 
  3 //:: jump
  4 
  5 :(before "End Initialize Op Names")
  6 put_new(Name, "eb", "jump disp8 bytes away (jmp)");
  7 
  8 :(scenario jump_rel8)
  9 == 0x1
 10 # op  ModR/M  SIB   displacement  immediate
 11   eb                05                        # skip 1 instruction
 12   05                              00 00 00 01
 13   05                              00 00 00 02
 14 +run: 0x00000001 opcode: eb
 15 +run: jump 5
 16 +run: 0x00000008 opcode: 05
 17 -run: 0x00000003 opcode: 05
 18 
 19 :(before "End Single-Byte Opcodes")
 20 case 0xeb: {  // jump rel8
 21   int8_t offset = static_cast<int>(next());
 22   trace(Callstack_depth+1, "run") << "jump " << NUM(offset) << end();
 23   EIP += offset;
 24   break;
 25 }
 26 
 27 //:: jump if equal/zero
 28 
 29 :(before "End Initialize Op Names")
 30 put_new(Name, "74", "jump disp8 bytes away if equal, if ZF is set (jcc/jz/je)");
 31 
 32 :(scenario je_rel8_success)
 33 % ZF = true;
 34 == 0x1
 35 # op  ModR/M  SIB   displacement  immediate
 36   74                05                        # skip 1 instruction
 37   05                              00 00 00 01
 38   05                              00 00 00 02
 39 +run: 0x00000001 opcode: 74
 40 +run: jump 5
 41 +run: 0x00000008 opcode: 05
 42 -run: 0x00000003 opcode: 05
 43 
 44 :(before "End Single-Byte Opcodes")
 45 case 0x74: {  // jump rel8 if ZF
 46   const int8_t offset = static_cast<int>(next());
 47   if (ZF) {
 48     trace(Callstack_depth+1, "run") << "jump " << NUM(offset) << end();
 49     EIP += offset;
 50   }
 51   break;
 52 }
 53 
 54 :(scenario je_rel8_fail)
 55 % ZF = false;
 56 == 0x1
 57 # op  ModR/M  SIB   displacement  immediate
 58   74                05                        # skip 1 instruction
 59   05                              00 00 00 01
 60   05                              00 00 00 02
 61 +run: 0x00000001 opcode: 74
 62 +run: 0x00000003 opcode: 05
 63 +run: 0x00000008 opcode: 05
 64 -run: jump 5
 65 
 66 //:: jump if not equal/not zero
 67 
 68 :(before "End Initialize Op Names")
 69 put_new(Name, "75", "jump disp8 bytes away if not equal, if ZF is not set (jcc/jnz/jne)");
 70 
 71 :(scenario jne_rel8_success)
 72 % ZF = false;
 73 == 0x1
 74 # op  ModR/M  SIB   displacement  immediate
 75   75                05                        # skip 1 instruction
 76   05                              00 00 00 01
 77   05                              00 00 00 02
 78 +run: 0x00000001 opcode: 75
 79 +run: jump 5
 80 +run: 0x00000008 opcode: 05
 81 -run: 0x00000003 opcode: 05
 82 
 83 :(before "End Single-Byte Opcodes")
 84 case 0x75: {  // jump rel8 unless ZF
 85   const int8_t offset = static_cast<int>(next());
 86   if (!ZF) {
 87     trace(Callstack_depth+1, "run") << "jump " << NUM(offset) << end();
 88     EIP += offset;
 89   }
 90   break;
 91 }
 92 
 93 :(scenario jne_rel8_fail)
 94 % ZF = true;
 95 == 0x1
 96 # op  ModR/M  SIB   displacement  immediate
 97   75                05                        # skip 1 instruction
 98   05                              00 00 00 01
 99   05                              00 00 00 02
100 +run: 0x00000001 opcode: 75
101 +run: 0x00000003 opcode: 05
102 +run: 0x00000008 opcode: 05
103 -run: jump 5
104 
105 //:: jump if greater
106 
107 :(before "End Initialize Op Names")
108 put_new(Name, "7f", "jump disp8 bytes away if greater, if ZF is unset and SF == OF (jcc/jg/jnle)");
109 
110 :(scenario jg_rel8_success)
111 % ZF = false;
112 % SF = false;
113 % OF = false;
114 == 0x1
115 # op  ModR/M  SIB   displacement  immediate
116   7f                05                        # skip 1 instruction
117   05                              00 00 00 01
118   05                              00 00 00 02
119 +run: 0x00000001 opcode: 7f
120 +run: jump 5
121 +run: 0x00000008 opcode: 05
122 -run: 0x00000003 opcode: 05
123 
124 :(before "End Single-Byte Opcodes")
125 case 0x7f: {  // jump rel8 if !SF and !ZF
126   const int8_t offset = static_cast<int>(next());
127   if (!ZF && SF == OF) {
128     trace(Callstack_depth+1, "run") << "jump " << NUM(offset) << end();
129     EIP += offset;
130   }
131   break;
132 }
133 
134 :(scenario jg_rel8_fail)
135 % ZF = false;
136 % SF = true;
137 % OF = false;
138 == 0x1
139 # op  ModR/M  SIB   displacement  immediate
140   7f                05                        # skip 1 instruction
141   05                              00 00 00 01
142   05                              00 00 00 02
143 +run: 0x00000001 opcode: 7f
144 +run: 0x00000003 opcode: 05
145 +run: 0x00000008 opcode: 05
146 -run: jump 5
147 
148 //:: jump if greater or equal
149 
150 :(before "End Initialize Op Names")
151 put_new(Name, "7d", "jump disp8 bytes away if greater or equal, if SF == OF (jcc/jge/jnl)");
152 
153 :(scenario jge_rel8_success)
154 % SF = false;
155 % OF = false;
156 == 0x1
157 # op  ModR/M  SIB   displacement  immediate
158   7d                05                        # skip 1 instruction
159   05                              00 00 00 01
160   05                              00 00 00 02
161 +run: 0x00000001 opcode: 7d
162 +run: jump 5
163 +run: 0x00000008 opcode: 05
164 -run: 0x00000003 opcode: 05
165 
166 :(before "End Single-Byte Opcodes")
167 case 0x7d: {  // jump rel8 if !SF
168   const int8_t offset = static_cast<int>(next());
169   if (SF == OF) {
170     trace(Callstack_depth+1, "run") << "jump " << NUM(offset) << end();
171     EIP += offset;
172   }
173   break;
174 }
175 
176 :(scenario jge_rel8_fail)
177 % SF = true;
178 % OF = false;
179 == 0x1
180 # op  ModR/M  SIB   displacement  immediate
181   7d                05                        # skip 1 instruction
182   05                              00 00 00 01
183   05                              00 00 00 02
184 +run: 0x00000001 opcode: 7d
185 +run: 0x00000003 opcode: 05
186 +run: 0x00000008 opcode: 05
187 -run: jump 5
188 
189 //:: jump if lesser
190 
191 :(before "End Initialize Op Names")
192 put_new(Name, "7c", "jump disp8 bytes away if lesser, if SF != OF (jcc/jl/jnge)");
193 
194 :(scenario jl_rel8_success)
195 % ZF = false;
196 % SF = true;
197 % OF = false;
198 == 0x1
199 # op  ModR/M  SIB   displacement  immediate
200   7c                05                        # skip 1 instruction
201   05                              00 00 00 01
202   05                              00 00 00 02
203 +run: 0x00000001 opcode: 7c
204 +run: jump 5
205 +run: 0x00000008 opcode: 05
206 -run: 0x00000003 opcode: 05
207 
208 :(before "End Single-Byte Opcodes")
209 case 0x7c: {  // jump rel8 if SF and !ZF
210   const int8_t offset = static_cast<int>(next());
211   if (SF != OF) {
212     trace(Callstack_depth+1, "run") << "jump " << NUM(offset) << end();
213     EIP += offset;
214   }
215   break;
216 }
217 
218 :(scenario jl_rel8_fail)
219 % ZF = false;
220 % SF = false;
221 % OF = false;
222 == 0x1
223 # op  ModR/M  SIB   displacement  immediate
224   7c                05                        # skip 1 instruction
225   05                              00 00 00 01
226   05                              00 00 00 02
227 +run: 0x00000001 opcode: 7c
228 +run: 0x00000003 opcode: 05
229 +run: 0x00000008 opcode: 05
230 -run: jump 5
231 
232 //:: jump if lesser or equal
233 
234 :(before "End Initialize Op Names")
235 put_new(Name, "7e", "jump disp8 bytes away if lesser or equal, if ZF is set or SF != OF (jcc/jle/jng)");
236 
237 :(scenario jle_rel8_equal)
238 % ZF = true;
239 % SF = false;
240 % OF = false;
241 == 0x1
242 # op  ModR/M  SIB   displacement  immediate
243   7e                05                        # skip 1 instruction
244   05                              00 00 00 01
245   05                              00 00 00 02
246 +run: 0x00000001 opcode: 7e
247 +run: jump 5
248 +run: 0x00000008 opcode: 05
249 -run: 0x00000003 opcode: 05
250 
251 :(scenario jle_rel8_lesser)
252 % ZF = false;
253 % SF = true;
254 % OF = false;
255 == 0x1
256 # op  ModR/M  SIB   displacement  immediate
257   7e                05                        # skip 1 instruction
258   05                              00 00 00 01
259   05                              00 00 00 02
260 +run: 0x00000001 opcode: 7e
261 +run: jump 5
262 +run: 0x00000008 opcode: 05
263 -run: 0x00000003 opcode: 05
264 
265 :(before "End Single-Byte Opcodes")
266 case 0x7e: {  // jump rel8 if SF or ZF
267   const int8_t offset = static_cast<int>(next());
268   if (ZF || SF != OF) {
269     trace(Callstack_depth+1, "run") << "jump " << NUM(offset) << end();
270     EIP += offset;
271   }
272   break;
273 }
274 
275 :(scenario jle_rel8_greater)
276 % ZF = false;
277 % SF = false;
278 % OF = false;
279 == 0x1
280 # op  ModR/M  SIB   displacement  immediate
281   7e                05                        # skip 1 instruction
282   05                              00 00 00 01
283   05                              00 00 00 02
284 +run: 0x00000001 opcode: 7e
285 +run: 0x00000003 opcode: 05
286 +run: 0x00000008 opcode: 05
287 -run: jump 5