Question: high address commandine arguments and enviroment variables lack pushq %rbp movq rsp, %rbp movl $10,-8(%rbp) movl $15.- 4rbp) movl -4%rbp), %eax subl -8C%rbp), %eax movl%eax,

 high address commandine arguments and enviroment variables lack pushq %rbp movq

rsp, %rbp movl $10,-8(%rbp) movl $15.- 4rbp) movl -4%rbp), %eax subl -8C%rbp),

high address commandine arguments and enviroment variables lack pushq %rbp movq rsp, %rbp movl $10,-8(%rbp) movl $15.- 4rbp) movl -4%rbp), %eax subl -8C%rbp), %eax movl%eax, -8(%rbp) movl -8(%rbp), %eax addl %eax. -4%rbp) movl $0.%eax popq %rbp ret heap uninitialized data initized by initialized data text read from programie low address All lines that begin with a period are not being shown here, because they are annotations for the linker. Become familiar with the syntax and registers. Do a web search and/or ask your TA for the questions to the following: What does a % refer to? What does a $ designate What do rbp, eax, and tsp refer to? What does a "-8" refer to, as for example - 8%rbp) What do the opcodes pushq, mov, sub, add, pop, ret specify What do the single letter suffixes 1, q (and are there others?) specify, as for example movq versus movl. (gdb) disassemble Dump of assembler code for function main: @x00005555555545fa : push rbp 0x00005555555545fb : mov *rsp,$rbp 0x00005555555545fe : movl $@xa, -x8 (*rbp) Ox0000555555554605 : movl $0xf,-0x4(%rbp) => 0x000055555555460C : mov -@x4(*rbp), eax 0x000055555555460f : sub - 8x8 (#rbp), feax 0x0000555555554612 ; mov Reax,-0x8(%rbp) 0x0000555555554615 : mov - 0x8(%rbp), Seax Ox0000555555554618 : add keax, -6x4 (%rbp) Ox000055555555461b : mov $0x0, eax 0x0000555555554620 : pop %rbp 0x0000555555554621 : reta End of assembler dump. (gdb) What similarities and differences are there between this disassembled code, and the assembly code that you generated using the gcc -S flag? For starters, notice that gdb is telling you, via the >, where the program is currently executing. Note that %rbp (the base pointer) is set to the top of the stack. The local variables x and y are stored on the stack at positions beyond the base pointer. Since x and y are both int, each requires 4 bytes (that's the C default) so their values are stored at addresses -Ox8(%rbp) and - Ox4%bp), respectively, where the 8 and 4 refer to addresses BEYOND the start of the memory location referred to by rop Here's the assembly instructions again, with annotations: push%bp # save the old value of %rbp mov%rsp,%rbp #set%rbp to the value of %rsp movl $0xa-Ox8C%rbp) #x= 10 movl $Oxf.-Ox4%rbp) #y=15 mov -0x4%rbp),%eax #load y into %eax sub -0x8(%rbp),%eax #y-x is now in %eax mov%eax.-0x8C%rbp) #x=y- mov - Ox8(%rbp),%eax #load x into %eax add %eax.-Ox4(%rbp) #y=x+y mov $0x0,%eax pop%rbp #restore the old value of%rbp reta # return from main() high address commandine arguments and enviroment variables lack pushq %rbp movq rsp, %rbp movl $10,-8(%rbp) movl $15.- 4rbp) movl -4%rbp), %eax subl -8C%rbp), %eax movl%eax, -8(%rbp) movl -8(%rbp), %eax addl %eax. -4%rbp) movl $0.%eax popq %rbp ret heap uninitialized data initized by initialized data text read from programie low address All lines that begin with a period are not being shown here, because they are annotations for the linker. Become familiar with the syntax and registers. Do a web search and/or ask your TA for the questions to the following: What does a % refer to? What does a $ designate What do rbp, eax, and tsp refer to? What does a "-8" refer to, as for example - 8%rbp) What do the opcodes pushq, mov, sub, add, pop, ret specify What do the single letter suffixes 1, q (and are there others?) specify, as for example movq versus movl. (gdb) disassemble Dump of assembler code for function main: @x00005555555545fa : push rbp 0x00005555555545fb : mov *rsp,$rbp 0x00005555555545fe : movl $@xa, -x8 (*rbp) Ox0000555555554605 : movl $0xf,-0x4(%rbp) => 0x000055555555460C : mov -@x4(*rbp), eax 0x000055555555460f : sub - 8x8 (#rbp), feax 0x0000555555554612 ; mov Reax,-0x8(%rbp) 0x0000555555554615 : mov - 0x8(%rbp), Seax Ox0000555555554618 : add keax, -6x4 (%rbp) Ox000055555555461b : mov $0x0, eax 0x0000555555554620 : pop %rbp 0x0000555555554621 : reta End of assembler dump. (gdb) What similarities and differences are there between this disassembled code, and the assembly code that you generated using the gcc -S flag? For starters, notice that gdb is telling you, via the >, where the program is currently executing. Note that %rbp (the base pointer) is set to the top of the stack. The local variables x and y are stored on the stack at positions beyond the base pointer. Since x and y are both int, each requires 4 bytes (that's the C default) so their values are stored at addresses -Ox8(%rbp) and - Ox4%bp), respectively, where the 8 and 4 refer to addresses BEYOND the start of the memory location referred to by rop Here's the assembly instructions again, with annotations: push%bp # save the old value of %rbp mov%rsp,%rbp #set%rbp to the value of %rsp movl $0xa-Ox8C%rbp) #x= 10 movl $Oxf.-Ox4%rbp) #y=15 mov -0x4%rbp),%eax #load y into %eax sub -0x8(%rbp),%eax #y-x is now in %eax mov%eax.-0x8C%rbp) #x=y- mov - Ox8(%rbp),%eax #load x into %eax add %eax.-Ox4(%rbp) #y=x+y mov $0x0,%eax pop%rbp #restore the old value of%rbp reta # return from main()

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!