Answered step by step
Verified Expert Solution
Link Copied!
Question
1 Approved Answer

PART II i ab Tasks Procedure 2. For each task c file for your program and follow the below steps to complete

image text in transcribed
image text in transcribed
PART II i ab Tasks Procedure 2. For each task " " c " file for your program and follow the below steps to complete the task: a. Save each task with the file name "Las fad Ted Nad. Task 1: Using gdb for disaasembly Type the following C program in the editor and save the file as task 1.e 1 minclude sstdto.hm 2 tnt natin() 3 [ 4 int a=5; 5 tnt bat 6 return 0; 7 ) - In the Ubantu L.TS terminal prompt go to the relevant directory. - To enable the gdb disassembler, the program using should be compiled using the g flag: gee g0 taskl taskl.c - Start gdb by specifying the executable to debug/disassemble : gdb task 1 - Add a breakpoint in main: (gdb) b main - Run the program with: (gdb) run - Go to next with: (gdb) next ( repeat this till end of the function main) - To disassemble the souree code use the command: (gdb) disass/s (Note : The disassemble command defoults to oufputing instructions in AT\&T syntax, which is the same syntax used by the GNU assembler. Instructions in ATET syntax are of the format mnemonic soarce, destination.) - You can now see the assembler code. Take a serecushof of the assembler code. pointer onto the stack to save it for later. Then ine copy the valure of the stack pointer so the towe pointer. Afier thas, Firhp poins to the barge of main's stack frame. this is a memory address, Here, Firbp is called the bate rogister, and -0x 8 is the displacement. This is equivilent to fiehp + - Pt\& Because she stack grows downwards, subtracting & fram the base of the curnent stack frame moves as into the current frame itself, where local variables ane stoned. This meams that dis instruction stores number 5 in the variable slot Girlpo - Qx 8 . The saffer ' % ' in the mov instruction signifies that the operands are 32 bits for integers. To see the value of variable ' a ': (gdb) x sa or (gdb) Srbp 0x8 We then move a info % ceax, one of our general purpose registers, add 6 to it and store the result in \%orbp This instruction copies 0 into \%eax. The x86 calling convention dictates that a function's return value is stored in \%eax. We pop the old base pointer off the stack and store it back in \%rbp and then retq jumps back to our return address, which is also stored in the stack frame. - To quit : (gdb) quit - In the gce terminal prompt, type the command gec -S task1.c. The assembly source code file with .s extension is generated and saved in the same folder as the .c file. Take a screenshot of the same

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image
Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Jeff Hoffer, Ramesh Venkataraman, Heikki Topi

12th edition

133544613, 978-0133544619

More Books

Students explore these related Databases questions