Skip to content

Instantly share code, notes, and snippets.

@nikolaybotev
Last active December 17, 2015 07:39
Show Gist options
  • Save nikolaybotev/5574392 to your computer and use it in GitHub Desktop.
Save nikolaybotev/5574392 to your computer and use it in GitHub Desktop.
A simple Jasmin file demonstrating the use of the jsr instruction.
.bytecode 49.0
.source Hello.j
.class Hello
.super java/lang/Object
; This example method uses a PrintMe subroutine to invoke the System.out.println() method.
.method static usingSubroutine()V
.limit stack 2
.limit locals 2
ldc "Message 1"
jsr PrintMe ; print "Message 1"
ldc "Message 2"
jsr PrintMe ; print "Message 2"
ldc "Message 3"
jsr PrintMe ; print "Message 3"
return ; now return from usingSubroutine
; define the PrintMe subroutine ...
PrintMe:
astore_0 ; store return-address in local variable 1
astore_1 ; store argument to println()
; call System.out.println()
getstatic java/lang/System/out Ljava/io/PrintStream;
aload_1 ; load argument for println()
invokevirtual java/io/PrintStream/println(Ljava/lang/String;)V
ret 0 ; return to the return-address in local variable 0
.end method
public class HelloDriver {
public static void main(String[] args) {
try {
System.out.println(10);
Hello.usingSubroutine();
} catch (Exception ex) {
System.out.println(ex);
} finally {
try {
System.out.println(24);
} catch (Exception ex) {
System.out.println(ex);
} finally {
System.out.println(42);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment