- Compile C code and get the OBJ file
- Call the C/C++ function as .call _funcname(parameters)
- Code: Select all
SWAP2 lastVal, reg1
SWAP4 reg1, reg1
B savelastVN ; Branch
There are few things to notice here.
- The C/C++ function is write_to_disk. But we have added '_' prefix. This usual as the compiler adds '_' to functions in the symbol table
- Whenever we pass a parameter from ASM, we need to make sure the C/C++ function is ready accept the size of a register. For example: In a 32-bit system where registers are 32-bit, the C/C++ function prototype must be something like write_to_disk(int value)
NOTE 1 : If the function is called from inline assembly make sure you don't put the '_'
NOTE 2 : If it is x86 assembly, the calling function is 'call' without the dot (.) prefix.