-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstructions.html
505 lines (412 loc) · 8.91 KB
/
instructions.html
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
<html>
<head>
<title>Jasmin Instructions</title>
<link href="style.css" rel="stylesheet" type="text/css">
</head>
<body>
<table ID="Table1">
<tr><td width=550>
<center>
<p><img src=jasmin_icon.jpg></p>
<p>
<div class="h1">JASMIN INSTRUCTIONS</div>
Jonathan Meyer, July 1996
</p>
</center>
<h1>Introduction</h1>
This document shows the syntax and the types of parameters required by
each Java VM instruction in Jasmin. It also shows brief illustrative
examples.<p>
See <a href="guide.html">The Jasmin User Guide</a> for a description
of other aspects of the Jasmin syntax.<p>
<h1>Local variable instructions</h1>
The following instructions use local variables:<p>
<pre>
ret <var-num>
aload <var-num>
astore <var-num>
dload <var-num>
dstore <var-num>
fload <var-num>
fstore <var-num>
iload <var-num>
istore <var-num>
lload <var-num>
lstore <var-num>
</pre>
for example:<p>
<pre>
aload 1 ; push local variable 1 onto the stack
ret 2 ; return to the address held in local variable 2
</pre>
<h1>The bipush, sipush and iinc instructions</h1>
The bipush and sipush instructions take an integer as a
parameter:<p>
<pre>
bipush <int>
sipush <int>
</pre>
for example:<p>
<pre>
bipush 100 ; push 100 onto the stack
</pre>
The iinc instruction takes two integer parameters:<p>
<pre>
iinc <var-num> <amount>
</pre>
for example:<p>
<pre>
iinc 3 -10 ; subtract 10 from local variable 3
</pre>
<h1>Branch instructions</h1>
The following instructions take a label as a parameter:
<pre>
goto <label>
goto_w <label>
if_acmpeq <label>
if_acmpne <label>
if_icmpeq <label>
if_icmpge <label>
if_icmpgt <label>
if_icmple <label>
if_icmplt <label>
if_icmpne <label>
ifeq <label>
ifge <label>
ifgt <label>
ifle <label>
iflt <label>
ifne <label>
ifnonnull <label>
ifnull <label>
jsr <label>
jsr_w <label>
</pre>
For example:<p>
<pre>
Label1:
goto Label1 ; jump to the code at Label1
; (an infinite loop!)
</pre>
<h1>Class and object operations</h1>
The following instructions take a class name
as a parameter:
<pre>
anewarray <class>
checkcast <class>
instanceof <class>
new <class>
</pre>
For example:<p>
<pre>
new java/lang/String ; create a new String object
</pre>
<h1>Method invokation</h1>
The following instructions are used to invoke methods:<p>
<pre>
invokenonvirtual <method-spec>
invokestatic <method-spec>
invokevirtual <method-spec>
</pre>
for example:<p>
<pre>
; invokes java.io.PrintStream.println(String);
invokevirtual java/io/PrintStream/println(Ljava/lang/String;)V
</pre>
A method specification is formed of three parts: the characters before the
last '/' form the class name. The characters between the last '/' and '(' are
the method name. The rest of the string is the descriptor.<p>
<pre>
foo/baz/Myclass/myMethod(Ljava/lang/String;)V
--------------- ---------------------
| -------- |
| | |
class method descriptor
</pre>
A special case is invokeinterface, which takes a <method-spec> and
an integer indicating how many arguments the method takes:<p>
<pre>
invokeinterface <method-spec> <num-args>
</pre>
for example:<p>
<pre>
invokeinterface foo/Baz/myMethod(I)V 1
</pre>
<h1>Field manipulation instructions</h1>
The four instructions getfield, getstatic, putfield and
putstatic have the form:<p>
<pre>
getfield <field-spec> <descriptor>
getstatic <field-spec> <descriptor>
putfield <field-spec> <descriptor>
putstatic <field-spec> <descriptor>
</pre>
for example:
<pre>
; get java.lang.System.out, which is a PrintStream
getstatic java/lang/System/out Ljava/io/PrintStream;
</pre>
<field-spec> is composed of two parts, a classname and a fieldname. The
classname is all of the characters in the <field-spec> up to the last
'/' character, and the fieldname is the rest of the characters after the last
'/'. For example: <p>
<pre>
foo/baz/AnotherClass/anotherFunField
-- class name ------ --field name --
</pre>
<descriptor> is the Java type descriptor of the field.
For example:<p>
<pre>
Ljava/io/PrintStream;
</pre>
<h1>The newarray instruction</h1>
The newarray instruction is followed by the type of the array,<p>
<pre>
newarray <array-type>
</pre>
for example:<p>
<pre>
newarray int
newarray short
newarray float
etc.
</pre>
<h1>The multianewarray instruction</h1>
The multianewarray instruction takes two parameters,
the type descriptor for the array and the number of
dimensions to allocate:<p>
<pre>
multianewarray <array-descriptor> <num-dimensions>
</pre>
for example:<p>
<pre>
multianewarray [[[I 2
</pre>
<h1>The ldc and ldc_w instructions</h1>
The ldc and ldc_w instructions are followed by a constant:<p>
<pre>
ldc <constant>
ldc_w <constant>
</pre>
<constant> is either an integer, a floating point number, or a
quoted string. For example:<p>
<pre>
ldc 1.2 ; push a float
ldc 10 ; push an int
ldc "Hello World" ; push a String
ldc_w 3.141592654 ; push PI as a double
</pre>
<h1>The lookupswitch instruction</h1>
The lookupswitch instruction has the syntax:<p>
<pre>
<lookupswitch> ::=
lookupswitch
<int1> : <label1>
<int2> : <label2>
...
default : <default-label>
</pre>
For example:<p>
<pre>
; If the int on the stack is 3, jump to Label1.
; If it is 5, jump to Label2.
; Otherwise jump to DefaultLabel.
lookupswitch
3 : Label1
5 : Label2
default : DefaultLabel
Label1:
... got 3
Label2:
... got 5
DefaultLabel:
... got something else
</pre>
<h1>The tableswitch instruction</h1>
The tableswitch instruction has the syntax:<p>
<pre>
<tableswitch> ::=
tableswitch <low>
<label1>
<label2>
...
default : <default-label>
</pre>
For example:<p>
<pre>
; If the int on the stack is 0, jump to Label1.
; If it is 1, jump to Label2.
; Otherwise jump to DefaultLabel.
tableswitch 0
Label1
Label2
default : DefaultLabel
Label1:
... got 0
Label2:
... got 1
DefaultLabel:
... got something else
</pre>
<h1>No parameter</h1>
The following instructions (the majority) take no parameters:<p>
<dl><dd>
aaload
aastore
aconst_null
aload_0
aload_1
aload_2
aload_3
areturn
arraylength
astore_0
astore_1
astore_2
astore_3
athrow
baload
bastore
breakpoint
caload
castore
d2f
d2i
d2l
dadd
daload
dastore
dcmpg
dcmpl
dconst_0
dconst_1
ddiv
dload_0
dload_1
dload_2
dload_3
dmul
dneg
drem
dreturn
dstore_0
dstore_1
dstore_2
dstore_3
dsub
dup
dup2
dup2_x1
dup2_x2
dup_x1
dup_x2
f2d
f2i
f2l
fadd
faload
fastore
fcmpg
fcmpl
fconst_0
fconst_1
fconst_2
fdiv
fload_0
fload_1
fload_2
fload_3
fmul
fneg
frem
freturn
fstore_0
fstore_1
fstore_2
fstore_3
fsub
i2d
i2f
i2l
iadd
iaload
iand
iastore
iconst_0
iconst_1
iconst_2
iconst_3
iconst_4
iconst_5
iconst_m1
idiv
iload_0
iload_1
iload_2
iload_3
imul
ineg
int2byte
int2char
int2short
ior
irem
ireturn
ishl
ishr
istore_0
istore_1
istore_2
istore_3
isub
iushr
ixor
l2d
l2f
l2i
ladd
laload
land
lastore
lcmp
lconst_0
lconst_1
ldiv
lload_0
lload_1
lload_2
lload_3
lmul
lneg
lor
lrem
lreturn
lshl
lshr
lstore_0
lstore_1
lstore_2
lstore_3
lsub
lushr
lxor
monitorenter
monitorexit
nop
pop
pop2
return
saload
sastore
swap
</dl>
for example:
<pre>
pop ; remove the top item from the stack
iconst_1 ; push 1 onto the stack
swap ; swap the top two items on the stack
</pre>
<hr><address>Copyright (c) Jonathan Meyer, July 1996</address>
<hr>
<a href="http://mrl.nyu.edu/meyer/jvm/jasmin.html">Jasmin Home</a> |
<a href="http://mrl.nyu.edu/meyer/">Jon Meyer's Home</a>