简体   繁体   中英

Java inline assembly transferring variables

Hello I'm trying to do simple java code with inline assembly. In asm procedure I want to do some operations on java variables here are my codes

public class Add {
    public static void main(String[] args) {
          int a=5;
          int b=4;
          int c=0;

            System.loadLibrary("native");
            (new Add()).nativeCode();


    }

    public native void nativeCode();
}

And Asm procedure

global _Java_Add_nativeCode
section .text
_Java_Add_nativeCode:
mov eax, a
mov ebx, b
add eax,ebx 
mov c,eax 

I'm trying to do operations on variables like in C++ but Nasm gives me an error symbol 'a' undefinied etc. Is there any way to do operation on variables declared in java in ASM procedure?

a is a virtual variable. The only way to do this at the moment is to implement a method call in C via JNI. I suggest you use javah to generate C code and use asm from that. Note: this will be many time slower than doing the same thing in Java (and many time more complicated)

In Java 9 you might be able to use user defined intrinsics. This will allow you to add assembly into Java to use instructions Java doesn't currently use like XMM.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM