如何编写jasmin程序
jasmin程序网上几乎没有资料(或者没有)。
今天我就先举例一个
;(分号)开头的都为注释
.class public Count
.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
; set limits used by this method
.limit locals 4
.limit stack 3
; setup local variables:
; 1 - the PrintStream object held in java.lang.System.out
getstatic java/lang/System/out Ljava/io/PrintStream;
astore_1
; 2 - the integer 10 - the counter used in the loop
bipush 10
istore_2
; now loop 10 times printing out a number
Loop:
; compute 10 - <local variable 2> ...
bipush 10
iload_2
isub
invokestatic java/lang/String/valueOf(I)Ljava/lang/String;
astore_3
; ... and print it
aload_1 ; push the PrintStream object
aload_3 ; push the string we just created - then ...
invokevirtual java/io/PrintStream/println(Ljava/lang/String;)V
; decrement the counter and loop
iinc 2 -1
iload_2
ifne Loop
; done
return
.end method
程序运行结果如下:
这算是一个典例了,一个计数输出程序。
学这门汇编语言前,最好有一定的java基础,比如关于对象,输入输出的知识。
在开始学习这个的时候,我还没学过java,真的是一脸懵逼,后面花了两个晚上去学习,这对我理解程序有了很大的帮助。