Question

This question is in regards to Assembly. What x86-64 register is changed to allocate local variables?...

This question is in regards to Assembly.
What x86-64 register is changed to allocate local variables? Explain briefly with an example.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

What x86-64 bit register is changed or used to allocate the local variables:

Answer: rbp register

Description:

• The base pointer register %rbp is used to keep track of the base value of the current stack frame. The start of the frame can be defined by moving the current stack pointer register to frame pointer.

• Example:

• Consider the following C code which is having variable a and b.

int main()

{

int a = 10, b = 20;

return 0;

}

Stack frame for main function will look like as follows:

• Assembly code to implement above function using %rbp register.

main:

pushq %rbp ; push or save the rbp on stack.

movq %rsp, %rbp ; Move the current stack frame of main function

movl $10, -8(%rbp) ; Assign value 10 to variable a

movl $20, -4(%rbp) ; Assign value 20 to variable b

movl $0, %eax ; return 0 function value

leave ; cleans allocated variables and restore the rbp register.

ret

In x86-32 architecture, register ebp is used to allocate local variables.

Add a comment
Know the answer?
Add Answer to:
This question is in regards to Assembly. What x86-64 register is changed to allocate local variables?...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT