What gcc command flags would you use to produce an assembly listing in 32-bit mode using the intel style assembly syntax?

  1. What gcc command flags would you use to produce an assembly listing in 32-bit mode using the intel style assembly syntax?
  2. Suppose you wrote a program in C that declared and initialized variable a with value 42 and variable b with value 52. The program then returned the sum of these two values. How would the assembly listing differ if compiled with optimization and without optimization?

3. In the following assembly code, what does the first SUB instruction do? What purpose does this serve?

 

Q3 Code:

main:
push  ebp
mov ebp, esp
sub esp, 16
mov DWORD PTR [ebp-12], 32
mov DWORD PTR [ebp-8], 46
mov DWORD PTR [ebp-4], 55
mov edx, DWORD PTR [ebp-12]
mov eax, DWORD PTR [ebp-8]
add eax, edx
add DWORD PTR [ebp-4], eax
mov eax, DWORD PTR [ebp-4]
leave
ret
.size main, .-main
.ident  “GCC: (Ubuntu 4.9.2-10ubuntu13) 4.9.2″
.section  .note.GNU-stack,””,@progbits

 

4.  In the following assembly code, how many local variables exist? How do you know this?

 

Q4 Code 

main:
push  ebp
mov ebp, esp
sub esp, 16
mov DWORD PTR [ebp-8], 10
mov DWORD PTR [ebp-4], 14
mov eax, DWORD PTR [ebp-8]
cmp eax, DWORD PTR [ebp-4]
jge .L2
mov eax, 1
jmp .L3
.L2:
mov eax, 2
.L3:
leave
ret
.size main, .-main
.ident  “GCC: (Ubuntu 4.9.2-10ubuntu13) 4.9.2″
.section  .note.GNU-stack,””,@progbits

Complete Answer:

Get Instant Help in Homework Asap
Get Instant Help in Homework Asap
Calculate your paper price
Pages (550 words)
Approximate price: -