From the course: Learning Assembly Language

Unlock the full course today

Join today to access over 22,400 courses taught by industry experts or purchase this course individually.

Calling assembler routines from C

Calling assembler routines from C - Python Tutorial

From the course: Learning Assembly Language

Start my 1-month free trial

Calling assembler routines from C

- [Instructor] Let's take a look at how we call assembler routines from C. We'll write a C program called caddy.c to print the sum of two numbers. Nano caddy.c. We'll start by including the standard IO. #include stdio.h and we'll declare an integer function called nasum which takes two parameters and returns their sum and this will be an external function that we'll be writing in assembler. int nasum. int a, int b. I'll set up the main program code, int main and then a printf statement, printf %d\n. We'll do a call to nasum with the values 28 and 14 and then we'll return and that's it. Now let's write the assembler routine. Do nano nasum.asm. We'll declare global nasum as its externally available address. Section .data, don't have any data section. .text, we do have some code and we'll declare this the entry point nasum. The parameters for subroutine are passed from c using registers, with the…

Contents