commit c263ad98fc3760d25a85257f343c22a5e3c90756 Author: Steven Tracey Date: Fri Oct 24 23:59:38 2025 -0400 Fun diff --git a/App.h b/App.h new file mode 100644 index 0000000..375a6f1 --- /dev/null +++ b/App.h @@ -0,0 +1,21 @@ +/* DO NOT EDIT THIS FILE - it is machine generated */ +#include +/* 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 diff --git a/App.java b/App.java new file mode 100644 index 0000000..d9dbef7 --- /dev/null +++ b/App.java @@ -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); +} \ No newline at end of file diff --git a/calc.S b/calc.S new file mode 100644 index 0000000..8fe28a5 --- /dev/null +++ b/calc.S @@ -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 \ No newline at end of file diff --git a/prog.c b/prog.c new file mode 100644 index 0000000..2c89642 --- /dev/null +++ b/prog.c @@ -0,0 +1,15 @@ +#include +#include +#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; +//}