Search code examples
stringjvm-bytecodejasmin

Jasmin ByteCode Storing a String


I am trying to store a String in Jasmin Bytecode. After allot of research I could not find if this was possible and if it was, how it should be done. I could only find out how I could print it out(this is how I print a string). I also thought of storing a string as an array of chars, but thought there should be an easier way.

.class public HelloWorld
.super java/lang/Object

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

  getstatic      java/lang/System/out Ljava/io/PrintStream;
  ldc            "Hello World."
  invokevirtual  java/io/PrintStream/println(Ljava/lang/String;)V

  return

.end method

Solution

  • Found the answer: A string is not a primitive datatype so you save it/load it with:

    aastore (number)
    aaload (number)