This commit is contained in:
Steven Tracey 2025-10-24 23:59:38 -04:00
commit c263ad98fc
4 changed files with 70 additions and 0 deletions

21
App.h Normal file
View 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
View 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
View 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
View 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;
//}