Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 248 Vote(s) - 3.49 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Linking C with NASM

#1
I have a NASM file and a C file. How do I call a function in the C file from the NASM file? How do I call a NASM function from the C file?

Many Thanks
DD
Reply

#2
Calling assembly function from C:

C file:

#include <stdio.h>

int add(int a, int b);

int main(int argc, char **argv)
{
printf("%d\n", add(2, 6));
return 0;
}

assembly file:

global add

section .data

section .text

add:
mov eax, [esp+4] ; argument 1
add eax, [esp+8] ; argument 2
ret

compiling:

$ nasm -f elf add.asm
$ gcc -Wall main.c add.o
$ ./a.out
8
$

Calling C function from assembly:

C file:

int add(int a, int b)
{
return a + b;
}

assembly file:

extern add
extern printf
extern exit

global _start

section .data
format db "%d", 10, 0
section .text

_start:
push 6
push 2
call add ; add(2, 6)

push eax
push format
call printf ; printf(format, eax)

push 0
call exit ; exit(0)

compiling:

$ gcc -Wall -c add.c
$ nasm -f elf main.asm
$ ld main.o add.o -lc -I /lib/ld-linux.so.2
$ ./a.out
8
$

Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through