Fun
This commit is contained in:
commit
c263ad98fc
21
App.h
Normal file
21
App.h
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
/* DO NOT EDIT THIS FILE - it is machine generated */
|
||||||
|
#include <jni.h>
|
||||||
|
/* Header for class App */
|
||||||
|
|
||||||
|
#ifndef _Included_App
|
||||||
|
#define _Included_App
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
/*
|
||||||
|
* Class: App
|
||||||
|
* Method: add
|
||||||
|
* Signature: (II)I
|
||||||
|
*/
|
||||||
|
JNIEXPORT jint JNICALL Java_App_add
|
||||||
|
(JNIEnv *, jclass, jint, jint);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
20
App.java
Normal file
20
App.java
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
import java.lang.System;
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
public class App {
|
||||||
|
static {
|
||||||
|
System.loadLibrary("calc");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
Scanner sc = new Scanner(System.in);
|
||||||
|
System.out.print("Number 1: ");
|
||||||
|
int num1 = sc.nextInt();
|
||||||
|
System.out.print("Number 2: ");
|
||||||
|
int num2 = sc.nextInt();
|
||||||
|
|
||||||
|
System.out.printf("Nums from C and ASM %d\n", add(num1, num2));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static native int add(int x, int y);
|
||||||
|
}
|
||||||
14
calc.S
Normal file
14
calc.S
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
.intel_syntax noprefix
|
||||||
|
|
||||||
|
.text
|
||||||
|
.globl add
|
||||||
|
.type add, @function
|
||||||
|
|
||||||
|
# rdi - arg1
|
||||||
|
# rsi - arg2
|
||||||
|
add:
|
||||||
|
lea eax, [rdi + rsi]
|
||||||
|
ret
|
||||||
|
ret
|
||||||
|
|
||||||
|
.section .note.GNU-stack,"",@progbits
|
||||||
15
prog.c
Normal file
15
prog.c
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <jni.h>
|
||||||
|
#include "App.h"
|
||||||
|
|
||||||
|
extern int add(int, int);
|
||||||
|
|
||||||
|
JNIEXPORT jint JNICALL Java_App_add(JNIEnv *jniEnv, jclass class, jint jX, jint jY) {
|
||||||
|
return (jint)add((int)jX,(int)jY);
|
||||||
|
}
|
||||||
|
|
||||||
|
//int main() {
|
||||||
|
// printf("Hello, world!\n");
|
||||||
|
// printf("Number %d from ASM!\n", add(42, 28));
|
||||||
|
// return 0;
|
||||||
|
//}
|
||||||
Loading…
Reference in New Issue
Block a user