global mymul
mymul:
mov rax, rdi
mul rsi
ret
#include <stdio.h>
typedef struct {
unsigned long long high;
unsigned long long low;
} resmul;
void mymul(unsigned long long, unsigned long long, resmul *res);
int main() {
resmul res;
mymul(3, 6, &res);
printf("mymul(3, 6); res.high=0x%llx, res.low=0x%llx\n", res.high, res.low);
//mymul(3, 6); res.high=0x0, res.low=0x12
return 0;
}
the goal is to multiply first arg with the second and send to result to the last arg first arg = RDI / second arg = RSI goal to send result high/low to typestruct
I dont understand why it gives 0 to both results RAX and RDX should be returned but i doesnt
Your
mymul
function is declared from C as taking a pointer argument, where it should be storing the results in memory. But in fact it is leaving them in the rdx:rax registers and never storing anything in memory at all, ignoring the pointer completely.The third argument would be passed in the rdx register, which complicates things a little because
mul
overwrites it. So you have to do something like