better build

This commit is contained in:
Christoph J. Scherr 2023-12-10 16:05:22 +01:00
parent 58cff0bba6
commit 9edefd8877
2 changed files with 24 additions and 9 deletions

View File

@ -8,5 +8,5 @@ else
ls -lah bin/$1.class
echo -e "executing ================================================\n"
cd bin
java $1
java $1 "${@:2}" # the first arg is what java should do, the other are args
fi

View File

@ -9,9 +9,10 @@
.method public static factorial(I)I ; calc `given`!
.limit locals 3
.limit stack 5
bipush 1 ;
istore 0 ; store the parameter `given`
.limit stack 2
; note that parameters are automatically stored as
; local variables, we dont need to do `istore 0` to
; store the given integer in a local variable.
bipush 1 ; we start calculating with `p`=1
istore 1 ; store `p`
bipush 2 ; we start calculating with `j`=1
@ -43,11 +44,25 @@
.end method
.method public static main([Ljava/lang/String;)V
.limit locals 1
.limit stack 2
getstatic java/lang/System/out Ljava/io/PrintStream;
bipush 5 ; set parameter 1
.limit locals 3
.limit stack 4
; parse cli args to int
aload 0
aaload 0
invokestatic java/lang/Integer/parseInt(Ljava/lang/String;)I
istore 1
; format
iload 1
ldc "! = "
iload 1
invokestatic Factorial/factorial(I)I ; call factorial
invokevirtual java/io/PrintStream/println(I)V
invokevirtual java/lang/String/format(ILjava/lang/String;I)I
astore 2
; output
getstatic java/lang/System/out Ljava/io/PrintStream;
aload 2 ; load formatted str
invokevirtual java/io/PrintStream/println(Ljava/lang/String;)V
return
.end method