Q3. Show the return value of main through register inspection Q4. Issue the following commands: (gdb) list
Question:
Q3. Show the return value of main through register inspection
Q4. Issue the following commands:
(gdb) list swap_n_add
(gdb) disas swap_n_add
Group the assembly code instructions with their corresponding statements in
swap_n_add
to the best of your ability.
Q5. What is the value of both a1 and a2 before swap_n_add? After? What would be the
value of diff if the call to swap_n_add did not occur?
Part 2:
Now, use breakpoints, and disassembly to solve the following questions. If you understand what the C code is supposed to do, figuring out what the assembly is doing can be done without looking up any opcodes.
Listing for whileLoop.c:
1 int main(){
2 int x = 6;
3 int y = 7;
4 int sum = 0;
5 int i = 0;
6 while(i < y){
7 sum = sum + x;
8 i++;
9 }
10 return sum;
11 }
Q4. Show the lines of assembly that make up the while loop part of the main function.
Specifically highlight the loop test condition.
Q5. Compare the assembly of the whileLoop.c to the same function written with a for loop. What is the difference between them in assembly?
Listing for forLoop.c:
1 int main(){
2 int x = 0;
3 int y = 0;
4 int sum = 0;
5 int i;
6 for(i = 0; i < y; i++){
7 sum = sum + x;
8 }
9 return sum;
10 }
Q6. What is the reason for the “jmp” command?
Elementary Linear Algebra with Applications
ISBN: 978-0471669593
9th edition
Authors: Howard Anton, Chris Rorres