unable to pop operand of empty stack

776 views
Skip to first unread message

Joanna Eriksson

unread,
Feb 26, 2014, 11:17:26 AM2/26/14
to proglang-c...@googlegroups.com
When running this: 

int main() {
  printBool(true);
  printBool(false);
  return 0 ;

}

void printBool(bool b) {
  if (b) {
  } else {
 }
}

We get:
.class public core013
.super java/lang/Object

.method public <init>()V
aload_0
invokenonvirtual java/lang/Object/<init>()V
return
.end method
.method public static main([Ljava/lang/String;)V
.limit locals 100
.limit stack 1000
invokestatic core013/main()I
return
.end method
.method public static main()I
.limit locals 100
.limit stack 1000
bipush 1
istore 1
invokestatic core013/printBool(B)V
bipush 0
istore 1
invokestatic core013/printBool(B)V
bipush 0
ireturn
.end method
.method public static printBool(B)V
.limit locals 100
.limit stack 1000
iload 1
ifeq IFFALSE0
goto IFTRUE0
IFFALSE0:
IFTRUE0:
return
.end method

This gives error Exception in thread "main" java.lang.VerifyError: (class: core013, method: main signature: ()I) Unable to pop operand off an empty stack.

Why?



Linus Färnstrand

unread,
Feb 26, 2014, 11:21:53 AM2/26/14
to Joanna Eriksson, proglang-c...@googlegroups.com
Booleans don't have the signature char "B". It should be "Z"


--
You received this message because you are subscribed to the Google Groups "proglang-course-2014" group.
To unsubscribe from this group and stop receiving emails from it, send an email to proglang-course-...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Joanna Eriksson

unread,
Feb 26, 2014, 11:33:37 AM2/26/14
to proglang-c...@googlegroups.com, Joanna Eriksson
Unfortunately the error remains the same after replacing the B with Z. 
To unsubscribe from this group and stop receiving emails from it, send an email to proglang-course-2014+unsub...@googlegroups.com.

Aarne Ranta

unread,
Feb 26, 2014, 11:52:17 AM2/26/14
to proglang-c...@googlegroups.com, Joanna Eriksson
Hello Joanna,

In this part

bipush 1
istore 1
invokestatic core013/printBool(B)V

you are invoking printBool on an empty stack, because the pushed value 1 has been stored.

  Aarne.

Irene Lobo Valbuena

unread,
Feb 26, 2014, 11:55:40 AM2/26/14
to proglang-c...@googlegroups.com
From what I see in your Jasmin code, there is nothing in the stack when thprintBool call is reached since you push a value and then store it (the store will not only update your local memory, it also pops the stack when doing so). So it won't be possible to pop any operands off the stack.

Joanna Eriksson

unread,
Feb 26, 2014, 12:05:21 PM2/26/14
to proglang-c...@googlegroups.com
Thanks, that solves the problem! However now we're instead getting

Exception in thread "main" java.lang.VerifyError: (class: core013, method: printBool signature: (Z)V) Accessing value from uninitialized register 1

Doesn't the istore put the value in register 1 so that printbool can use iload to get is?

Aarne Ranta

unread,
Feb 26, 2014, 12:17:54 PM2/26/14
to proglang-c...@googlegroups.com
If it is the same code as before, you seem to be loading variable 1, but printBool has just one parameter b, which is stored in 0.

  Aarne.
Reply all
Reply to author
Forward
0 new messages