In: Computer Science
How is the first argument passed to a function in x86-64 assembly? Give an example of this happening in assembly and the corresponding C code.
What x86-64 register is changed to allocate local variables? Explain briefly with an example.
to answer the following question I would say
the string does not need to be passed you can pass a pointer but the string needs to be in memory somewhere.
by putting the address of that memory into the argument register
Assembly code is :
/////// declare a data segment object containg the string .data str: .string "example" ////////code to call fun(char *) with the string: .text movq $str, %rdi call fun
C code is :
char str[] = "example" void fun(char *str)
.........................................................
example code ;
#include <stdint.h> int main(void) { uint64_t a = 0x12345679abcdefULL; uint64_t b = 0xfdcba987654321ULL; uint64_t c = a + b; return 0; }
if you run the above code u come to know that It seems to allocate two 32-bit values on the stack and add then with addl and adcl separately. thia happens with both m32 and m64 bit switch. all though I was on a 64bit system der seemed no need to add any dedicated instruction set for 64bit integers.