From the course: Advanced C Programming: Integrating C and Assembly Language

Unlock this course with a free trial

Join today to access over 22,400 courses taught by industry experts.

Writing functions that pass and return values

Writing functions that pass and return values - C Tutorial

From the course: Advanced C Programming: Integrating C and Assembly Language

Writing functions that pass and return values

- [Instructor] For those functions that both accept values and return a value, the convention works similarly for both assembly and C. Values passed are set in registers. rdi for the first argument, rsi for the second, rdx, rcx, r8, and r9 for additional arguments with any more saved on the stack. Floating point arguments are saved in register xmm0, xmm1, and so on. Again, additional arguments are saved on the stack. Values returned are set in the rax register for integers, addresses, and similar values, and for floating point numbers, values are returned in the xmm0 register. This C code calls four assembly language functions to perform math operations; add, subtract, multiply, and divide. These do as they say, dealing mostly with integer values, save for divide, which deals with real numbers. Each assembly function is called within a printf statement in the code. The statement outputs the expression and the…

Contents