i was reading some examples for Assembly x86_64 and hit this slide: https://i.stack.imgur.com/KWAI8.jpg or incase the link goes down:
void multstore
(long x, long y, long *dest) {
long t = mult2(x, y);
*dest = t;
}
long mult2(long a, long b)
{
long s = a * b;
return s;
}
0000000000400540 <multstore>:
400540: push %rbx # Save %rbx
400541: mov %rdx,%rbx # Save dest
400544: callq 400550 <mult2> # mult2(x,y)
400549: mov %rax,(%rbx) # Save at dest
40054c: pop %rbx # Restore %rbx
40054d: retq # Return
0000000000400550 <mult2>:
400550: mov %rdi,%rax # a
400553: imul %rsi,%rax # a * b
400557: retq # Return
What i dont understand is at 400541 why the author saves the DEST, what about this - i can just use the %rdx to handle the work:
mulstore:
push %rbx
callq mult2
mov %rax, (%rdx)
retq
isnt this simpler? or im missing something important here? TY.