Question

#include<stdio.h> voidmain() { int i = 0; while (i < 10) { printf("i is currently %d\n",...

#include<stdio.h>

voidmain() {

int i = 0;

while (i < 10) {

printf("i is currently %d\n", i);

++i;

}

}

Compile the code file using the command line. Copy the assembly code for just the _main sub-routineand paste it as your answer to this question and highlight the lines which corrospond to the ++i; statement from the source code.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

answer:-i am saving this file as ex1.c then execute the command gcc -S ex1.c..then we will get a file named as ex1.s which contains the assembly code for the above code..so the assembly code for the main function of the above program is:-

main:

.LFB0:

.cfi_startproc

pushl %ebp

.cfi_def_cfa_offset 8

.cfi_offset 5, -8

movl %esp, %ebp

.cfi_def_cfa_register 5

andl $-16, %esp

subl $32, %esp

movl $0, 28(%esp)

jmp .L2

.L3:

movl 28(%esp), %eax

movl %eax, 4(%esp)

movl $.LC0, (%esp)

call printf

addl $1, 28(%esp) // this line corresponds to the ++i statement

.L2:

cmpl $9, 28(%esp)

jle .L3

leave

.cfi_restore 5

.cfi_def_cfa 4, 4

ret

.cfi_endproc

note:-i have commented the line. which corresponds to ++i ststement

Add a comment
Know the answer?
Add Answer to:
#include<stdio.h> voidmain() { int i = 0; while (i < 10) { printf("i is currently %d\n",...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT