Question

In: Computer Science

How is the first argument passed to a function in x86-64 assembly? Give an example of...

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.

Solutions

Expert Solution

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.


Related Solutions

In assembly 1.What is the effect of the following instructions executing on a modern x86 64-bit...
In assembly 1.What is the effect of the following instructions executing on a modern x86 64-bit system (describe what happens and the final contents of the registers involved)? Can you obtain the same end result using only two instructions, and no other registers? PUSH RAX PUSH RBX PUSH RCX XOR RAX,RAX XOR RBX,RBX XOR RCX,RCX POP RAX POP RAX POP RBX 2. What is the purpose of a segment register in protected mode memory addressing? 3. For a 32-bit Pentium4...
Using x86 assembly language, create a flowchart and write an example of code that will sort...
Using x86 assembly language, create a flowchart and write an example of code that will sort 2 arrays of unsigned doubleword integers in ascending order and output the largest element in each array. Any sorting procedure can be used, but this procedure must be called twice for each array. The first time it is called, the first array should be sorted and the second time it is called, the second array must be sorted. As well as outputting which is...
in assembly language x86 Masm, Write a program that calculate the first seven values of the...
in assembly language x86 Masm, Write a program that calculate the first seven values of the Fibonacci number sequence, described by the following formula: Fib(0) = 0, Fib(1) = 1, Fib(2) = Fib(0)+ Fib(1), Fib(n) = Fib(n-1) + Fib(n-2). You NEED to calculate each value in the series "using registers and the ADD operation" You can also use variables, Have your program print out "The first seven numbers is" Use WriteInt for the printing, Place each value in the EAX...
Develop an x86 assembly language program that properly executes an "x to the y power" function:...
Develop an x86 assembly language program that properly executes an "x to the y power" function: int power(int x, int y) Compute the integer value that is x to the y power Do not concern yourself with the possibility of overflow You may only use only a loop structure to compute the value Remember that the return value must be placed in the EAX register Make sure that any registers (not EAX) used by this function are placed back to...
Assembly Language for x86 processors You are to write a program which should first ask for...
Assembly Language for x86 processors You are to write a program which should first ask for 4 random numbers from 0-20 (user will inpute these numbers in no preset order). Input these 5 numbers in variables called num1, num2, num3, num4, and num5. When done, your program should sort these numbers (you will use lots of conditions to check order). num1 should contain smallest number while num5 should contain the biggest. display the contents of num1 through num5 on the...
Explain the difference between a valid argument and a sound argument, and give an example of...
Explain the difference between a valid argument and a sound argument, and give an example of each.
Develop an x86 assembly language program that properly executes an "is even" function: bool isEven(int value)...
Develop an x86 assembly language program that properly executes an "is even" function: bool isEven(int value) If the value passed in is even, return 1 If the value passed in is odd, return 0 Remember that the return value must be placed in the EAX register Make sure that any registers (not EAX) used by this function are placed back to their initial states prior to exiting Allow an end user to test this function in the following manner: Prompt...
Write a function void reverse(char * s) that reverses the string passed as an argument. Your...
Write a function void reverse(char * s) that reverses the string passed as an argument. Your code should use pointer arithmetic (it may increment and decrement pointers, but it may not use array indexing). Here is a piece of code that shows the behavior of reverse: char buf[100]; strcpy(buf, “hello”); reverse(buf); printf(“%s\n”, buf); // output should be olleh
how to use the filename to be passed to the given function in c ? for...
how to use the filename to be passed to the given function in c ? for example the implementation accepts one command line argument, which is a filename. The filename is a file containing a starting state to be passed to the given function initial() ,which will produce the initial state of the game.
The first week of the course you were asked to give an example of how you...
The first week of the course you were asked to give an example of how you would use statistics in your job or everyday life. As expected, most of you gave examples of descriptive statistics. They were things like finding averages, using graphs or considering the chance of something happening. As you have now discovered there is an entire second branch of statistics called Inferential Statistics. In this post I am asking the same question but this time I want...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT