1

I get this error after "java testphase":

C:\jasmin-2.4>java testphase
Exception in thread "main" java.lang.VerifyError: 
  (class: testphase, method: main signature: ([Ljava/lang/String;)V) 
  Expecting to find object/array on stack
  Could not find the main class: testphase. 
Program will exit.

Code:

.class public testphase
.super java/lang/Object

; standard initializer
.method public <init>()V
  aload_0
  invokenonvirtual java/lang/Object/<init>()V
  return
.end method

.method public static main([Ljava/lang/String;)V
  .limit stack 10
  .limit locals 3

  ; assign something
  iconst_1
  iconst_1
  iadd
  istore_1

 ; assign something
  iconst_2
  iconst_2
  isub
  istore_2

 ; Writeln
  getstatic java/lang/System/out Ljava/io/PrintStream;
  iload_1
  invokevirtual java/io/PrintStream/println(Ljava/lang/String;)V

  return
.end method
Ciro Santilli OurBigBook.com
  • 347,512
  • 102
  • 1,199
  • 985
vik
  • 11
  • 1
  • 2

2 Answers2

1

You've got multiple issues.

First: you need to change the final

iload_1

to be

aload_1

  • you're loading the String array parameter, so shouldn't be using an integer load (iload) to do it.

Second, you're loading a String array, not a String. You need to choose which element you want. (look up aaload for how to dereference elements in the array.)

You need to fix both before it'll actually work.

Trent Gray-Donald
  • 2,286
  • 14
  • 17
0

This will work:

.class public testphase
.super java/lang/Object

; standard initializer
  .method public <init>()V
   aload_0
   invokenonvirtual java/lang/Object/<init>()V
   return
.end method

.method public static main([Ljava/lang/String;)V
  .limit stack 2
  .limit locals 3

  ; assign something
  iconst_1
  iconst_1
  iadd
  istore_1

  ; assign something
  iconst_2
  iconst_2
  isub
  istore_2

  ; Writeln
  getstatic java/lang/System/out Ljava/io/PrintStream;
  iload_1
  invokevirtual java/io/PrintStream/println(I)V

  ; Writeln variable 2
  getstatic java/lang/System/out Ljava/io/PrintStream;
  iload_2
  invokevirtual java/io/PrintStream/println(I)V

  return
.end method

Basically the change consists in the signature of System.out.println(int).

Martín Schonaker
  • 7,273
  • 4
  • 32
  • 55