Write a Java class with the Dalvik instruction set

Source: Internet
Author: User

Dalvik instruction Set

. class public lcalculate; #定义类名

. super Ljava/lang/object; #定义父类
. method public static main ([ljava/lang/string;) v# declares the static main () method, L indicates that this is a class
. Registers 5 #方法中使用5个寄存器
. Prologue #代码起始指令
NOP #空指令
Nop
Nop
Nop
New-instance V0, LCalculate; #构造一个CalculateInstance
Invoke-direct{v0},lCalculate;-><init> () V #调用构造函数
Sget-object v1,ljava/lang/system;->out:ljava/io/printstream; #静态字段操作指令
CONST/4 v2,0x5 #将5存入寄存器V2
CONST/4 v3,0x3 #将3存入寄存器V3
Invoke-virtual{v0,v2,v3},lCalculate;->foo (II) I #调用LCalculate InstancesThe Foo virtual function (V0 is an implicitLCalculate object reference, followed by two arguments)
Move-result V0 #获取foo函数执行后返回的结果
Invoke-virtual{v1,v0},ljava/io/printstream;->println (I) V #方法调用指令
Return-void #函数从一个void方法返回
The. End Method #方法结束符号


# Direct Methods #表示这是一个直接方法
. Method Public constructor <init> () V #构造函数
. Registers 1 #一个寄存器


. Prologue #Code Start Command
Invoke-direct {p0}, ljava/lang/object;-><init> () V #调用实例的直接方法


Return-void#函数从一个void方法返回

The. End method #方法结束符号


# Virtual Methods #表示这是一个虚方法
. method public Foo (II) I #方法名为foo, two parameters and both are of type int, and the return value is int
. Registers 5 #方法中使用5个寄存器
. Prologue # code Start command
Add-int v0,p1,p2 #p1, p2 two int types, the result is saved in V0
Sub-int v1,p1,p2#p1,p2 two int type subtraction, the result is saved in V1

Mul-int/2addr v0,v1 #v0, v1 Two registers for multiplication, results stored in V0 register
return V0 #返回寄存器V0的值
The. End method #方法结束符号

Java source code:

public class Calculate
{
public int foo (int a,int b) {
Return (A+B) * (A-B);
}
public static void Main (string[] argc)
{
Hello hello=new hello ();
System.out.println (Hello.foo (5,3));
}
}

Write a Java class with the Dalvik instruction set

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.