编写Hello.smali文件
.class public LHelloWorld;
.super Ljava/lang/Object;
.method public static main([Ljava/lang/String;)V
.registers 4
.parameter
.prologue
nop
nop
const/16 v0, 0x8
const/4 v1, 0x5
const/4 v2, 0x3
# 创造一个v0数值的int类型数组, 并将引用赋给v0
new-array v0, v0, [I
array-length v1, v0
# 创建一个StringBuilder实例,引用赋给v1
new-instance v1, Ljava/lang/StringBuilder;
invoke-direct {v1}, Ljava/lang/StringBuilder;-><init>()V
#如果v0的值不为0,则跳转到cond_0
if-nez v0, :cond_0
goto :goto_0
:cond_0
#数据转换指令
int-to-float v2, v2
#数据运算指令
add-float v2, v2, v2
#比较指令
cmpl-float v0, v2, v2
# 将静态System对象的out对象引用赋给v0
sget-object v0, Ljava/lang/System;->out:Ljava/io/PrintStream;
const-string v1, "Hello jianggiegie"
# 调用v0的println,入参是v1
invoke-virtual {v0, v1}, Ljava/io/PrintStream;->println(Ljava/lang/String;)V
:goto_0
return-void
.end method
执行编译命令
java -jar smali.jar -o hello.dex Hello.smali
将dex 推入手机/sdcard 下
adb push hello.dex /sdcard/
手机中执行命令
dalvikvm -cp hello.dex HelloWorld
打印 jianggeigei