#算數運算 Java代碼:java
public void num(int b){ int a = b; boolean b1 = true; Log.d("MainActivity","a + b ="+(a+b)); Log.d("MainActivity","a - b ="+(a-b)); Log.d("MainActivity","a * b ="+(a*b)); Log.d("MainActivity","a / b ="+(a/b)); Log.d("MainActivity","a % b ="+(a%b)); }
與之對應的smali代碼:android
.method public num(I)V .locals 5 #定義局部變量寄存器 .param p1,"b" #聲明參數 .prologue #代碼開始 .line 30 move v0, p1 #數據變量賦值 .line 31 .local v0, "a":I #定義局部變量 const/4 v1, 0x1 #數據常量賦值 .line 32 .local v1, "b1":Z #定義局部變量 const-string v2, "MainActivity" #定義字符串常量 new-instance v3,Ljava/lang/StringBuilder; #建立StringBuilder對象 invoke-direct {v3},Ljava/lang/StringBuilder;-><init>()V #調用構造 const-string v4,"a+b=" #調用虛方法 v3.append(v4) invoke-virtual {v3,v4}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder; move-result-object v3 #將返回值放入v3 add-int v4,v0,p1 #v4=v0+v1 invoke-virtual {v3,v4}, Ljava/lang/StringBuilder;->append(I)Ljava/lang/StringBuilder; # v3.append(v4) move-result-object v3 invoke-virtual v3, Ljava/lang/StringBuilder;->toString()Ljava/lang/String; move-result-object v3 invoke-static {v2,v3},Landroid/util/Log;->d(Ljava/lang/String;Ljava/lang/String) #調用靜態方法 .line 33 const-string v2,"MainActivity" new-instance v3,Ljava/lang/StringBuilder;-><init>V const-string v4,"a-b=" invoke-virtual {v3,v4}, Ljava/lang/StringBuilder;->append(I)Ljava/lang/StringBuilder; move-result-object v3 sub-int v4,v0,p1 #v4 = v0 - p1 invoke-virtual {v3,v4}, Ljava/lang/StringBuilder;->append(I)Ljava/lang/StringBuilder; move-result-object v3 invoke-virtual v3, Ljava/lang/StringBuilder;->toString()Ljava/lang/String; move-result-object v3 invoke-static {v2,v3},Landroid/util/Log;->d(Ljava/lang/String;Ljava/lang/String) .line 34 const-string v2,"MainActivity" new-instance v3,Ljava/lang/StringBuilder;-><init>V const-string v4,"a/b=" invoke-virtual {v3,v4}, Ljava/lang/StringBuilder;->append(I)Ljava/lang/StringBuilder; move-result-object v3 div-int v4,v0,p1 #v4 = v0 / p1 invoke-virtual {v3,v4}, Ljava/lang/StringBuilder;->append(I)Ljava/lang/StringBuilder; move-result-object v3 invoke-virtual v3, Ljava/lang/StringBuilder;->toString()Ljava/lang/String; move-result-object v3 invoke-static {v2,v3},Landroid/util/Log;->d(Ljava/lang/String;Ljava/lang/String) .line35 const-string v2,"MainActivity" new-instance v3,Ljava/lang/StringBuilder;-><init>V const-string v4,"a*b=" invoke-virtual {v3,v4}, Ljava/lang/StringBuilder;->append(I)Ljava/lang/StringBuilder; move-result-object v3 mul-int v4,v0,p1 #v4 = v0 * p1 invoke-virtual {v3,v4}, Ljava/lang/StringBuilder;->append(I)Ljava/lang/StringBuilder; move-result-object v3 invoke-virtual v3, Ljava/lang/StringBuilder;->toString()Ljava/lang/String; move-result-object v3 invoke-static {v2,v3},Landroid/util/Log;->d(Ljava/lang/String;Ljava/lang/String) .line 36 const-string v2,"MainActivity" new-instance v3,Ljava/lang/StringBuilder;-><init>V const-string v4,"a/b=" invoke-virtual {v3,v4}, Ljava/lang/StringBuilder;->append(I)Ljava/lang/StringBuilder; move-result-object v3 rem-int v4,v0,p1 #v4 = v0 % p1 invoke-virtual {v3,v4}, Ljava/lang/StringBuilder;->append(I)Ljava/lang/StringBuilder; move-result-object v3 invoke-virtual v3, Ljava/lang/StringBuilder;->toString()Ljava/lang/String; move-result-object v3 invoke-static {v2,v3},Landroid/util/Log;->d(Ljava/lang/String;Ljava/lang/String) .line 37 return-void .end method
能夠看到關於算數運算的代碼以下:app
add-int v4, v0 ,p1 加法,v4 = v0 + p1 sub-int v4, v0 ,p1 減法,v4 = v0 - p1 mul-int v4, v0 ,p1 乘法,v4 = v0 * p1 div-int v4, v0 ,p1 除法,v4 = v0 / p1 rem-int v4, v0 ,p1 取餘,v4 = v0 % p1