Skip to content

Commit 5c81f07

Browse files
author
hanwen.chang
committed
init asm test
0 parents  commit 5c81f07

File tree

3 files changed

+97
-0
lines changed

3 files changed

+97
-0
lines changed

11.cpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#include <vector>
2+
#include <iostream>
3+
#include <fstream>
4+
#include <stdio.h>
5+
#include <stdlib.h>
6+
#include <cmath>
7+
#include <time.h>
8+
#include <cstdint>
9+
#include <cstring>
10+
#include <dlfcn.h>
11+
#include <x86intrin.h>
12+
13+
14+
int main(){
15+
char *error_str;
16+
void *handle;
17+
handle = dlopen ("./11.so", RTLD_LAZY);
18+
if (!handle) {
19+
fputs (dlerror(), stderr);
20+
exit(1);
21+
}
22+
23+
void (*mm)(long,long,long*);
24+
mm =(void (*)(long,long,long*)) dlsym(handle, "_Z8sumstorellPl");
25+
if ((error_str = dlerror()) != NULL) {
26+
fputs(error_str, stderr);
27+
exit(1);
28+
}
29+
30+
long*a;
31+
a=(long *)malloc(1*sizeof(long));
32+
printf("===========asm==========\n");
33+
mm(3,5,a);
34+
printf("===========result %ld==========\n",*a);
35+
36+
return 0;
37+
}
38+
39+
/*
40+
void sumstore(long x, long y,
41+
long *dest) {
42+
long t = x + y;
43+
*dest = t;
44+
}
45+
*/

22.s

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
.file "22.cpp"
2+
.text
3+
.globl _Z8sumstorellPl
4+
.type _Z8sumstorellPl, @function
5+
_Z8sumstorellPl:
6+
.LFB0:
7+
.cfi_startproc
8+
endbr64
9+
pushq %rbp
10+
.cfi_def_cfa_offset 16
11+
.cfi_offset 6, -16
12+
movq %rsp, %rbp
13+
.cfi_def_cfa_register 6
14+
movq %rdi, -24(%rbp)
15+
movq %rsi, -32(%rbp)
16+
movq %rdx, -40(%rbp)
17+
movq -24(%rbp), %rdx
18+
movq -32(%rbp), %rax
19+
addq %rdx, %rax
20+
movq %rax, -8(%rbp)
21+
movq -40(%rbp), %rax
22+
movq -8(%rbp), %rdx
23+
movq %rdx, (%rax)
24+
nop
25+
popq %rbp
26+
.cfi_def_cfa 7, 8
27+
ret
28+
.cfi_endproc
29+
.LFE0:
30+
.size _Z8sumstorellPl, .-_Z8sumstorellPl
31+
.ident "GCC: (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0"
32+
.section .note.GNU-stack,"",@progbits
33+
.section .note.gnu.property,"a"
34+
.align 8
35+
.long 1f - 0f
36+
.long 4f - 1f
37+
.long 5
38+
0:
39+
.string "GNU"
40+
1:
41+
.align 8
42+
.long 0xc0000002
43+
.long 3f - 2f
44+
2:
45+
.long 0x3
46+
3:
47+
.align 8
48+
4:

asm.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/bash
2+
3+
gcc -shared -o 11.so 22.s
4+
icx 11.cpp -lstdc++ -o test -std=c++17

0 commit comments

Comments
 (0)