Purpose: To: Go over the basics of assembly language Go over how to use a debugg
ID: 3760693 • Letter: P
Question
Purpose:
To:
Go over the basics of assembly language
Go over how to use a debugger
Go over the layout of an activation record
Assignment
Please do the following:
Download the program called toAnalyzeCDM.zip from COL
Use an sftp program like filezilla to upload it to a ctilinux machine (like ctilinux2.cstcis.cti.depaul.edu) Do not bother unzipping it on your local machine.
On ctilinux1 or ctilinux2 unzip it with:
Do chmod u+x toAnalyze to make tell Unix that it is an executable program
Analyze it with gdb: gdb toAnalyze. It has a structure like:
Answer the following:
(20 Points) Assembly language understanding (1):
The assembly language for bar() is:
Give a 1-2 sentence description of the purpose of each instruction.
I am more interested in the why than the what.
(10 Points) Assembly language understanding (2):
Write a C function that does what bar() does.
You won't be able to figure out the names of my parameters var(s) and local var(s); just make up your own name(s).
(20 Points) Activation Records (1):
Stop the program at its third call to bar(). When I did so I got the following:
Write the activation record for bar() when %eip gets to 0x08048385.
Under Value put the numeric value held at that address.
Under Purpose put one of the following:
not part of bar()'s activation record
argument to bar()
the address in foo() to which eip should return
the stored ebp address for foo()
local variable to bar()
(10 Points) Assembly language understanding (3):
What are the value(s) that foo() obtains as arguments from main()?
Where are they on the stack?
Give an offset from ebp from within foo()'s activation record.
(10 Points) Assembly language understanding (4):
How many local variables does foo() have?
Where are they on the stack?
Give an offset from ebp from within foo()'s activation record.
(20 Points) Debugger usage (1):
foo() has a loop. Inside of foo() what are the values that both its arguments and local variables take on when eip is at address0x0804,83B9? At the top of the table give the offset from ebp (the hexadecimal number added to ebp to get the address of the variable) of the parameter or local variable. (I may have tried to fool you the the number of variables.)
In the body of the table write the values that that variable has when you hit address local variables.
(5 Points) Debugger usage (2):
What value does foo() return to main()?
(5 Points) Assembly language understanding (5):
foo() calls bar(). bar() starts at address 0x0804,8374. If you look at the machine code for foo()'s call to bar(), however, you'll see that the actual number in the function call is 0xFFFF,FFC2.
What to what number did the CPU add with 0xFFFF,FFC2 to get the address of bar(), 0x0804,8374?
Do this addition. Compute 0x0804,8374.
Instruction: Purpose: push %ebp ___________________________________________________________ mov %esp,%ebp ___________________________________________________________ sub $0x10,%esp ___________________________________________________________ mov 0xc(%ebp),%edx ___________________________________________________________ mov 0x8(%ebp),%eax ___________________________________________________________ sub %edx,%eax ___________________________________________________________ mov %eax,-0x4(%ebp) ___________________________________________________________ mov -0x4(%ebp),%eax ___________________________________________________________ leave ___________________________________________________________ ret ___________________________________________________________Explanation / Answer
0xBFFF,E8D8 sb a1,-10008(v1)
0xBFFF,E8D4 jal 51a3d30f
0xf4e8d44 e8d05d7b
0xBFFF,E8CC sd ra,-1(ra)
0xBFFF,E8C8 sd ra,-1(ra)
0xBFFF,E8C4 sd ra,-1(ra)
r
push %ebp push the data into ebp register
mov%esp,%ebp Move the contents of the contents of number register %esp into number register %ebp
sub $0x10,%esp sub the value of esp and address then value is copied into address 0x10
mov 0xc(%ebp),%edx the substring of edx is stored in 0xc and esp are combined
sub %edx,%eax sub the value of eax and address then value is copied into edx
mov %eax,-0x4(%ebp) the substring stored in 0x4 and ebp are combined are pushed into eax.
leave the temporary register is removed after saving into memory.
ret standard subprogram return instruction
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.