Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

You must do this assignment using one of the Linux machines in our lab to make s

ID: 3732250 • Letter: Y

Question

You must do this assignment using one of the Linux machines in our lab to make sure that everyone is using the same version of the compiler In this assignment you are asked to annotate assembly language code to illustrate that you Look at the examples in the lecture notes for section 3.4, especially Example 3, and all of Examples 4, 5, and 6. Your comments should indicate what the purpose of the code is in the context of the problem being solved, not just what an individual assembly language instruction does. As an example, in Example 6 from the notes, the line: should not be annotated as: movl 12 (8ebp),Sedx /7 move i into Sedx movi 12 (tebp), edx // more 4 bytes from memory address %(ebp+12) into %edx Part 1: Create a file called calc.c that contains the following: int calc (int x, int y, int z) return 3*x 2'y +15z; Compile the program to produce assembly code. Use: cc -01-S calc.c to produce calc.s. Copy cale.s into calc.s.txt and annotate calc.s.txt with comments to illustrate that you understand how the calculation is implemented. Make sure you identify each parameter Print out the annotated code and turn it in. Part 2: Write a main p The main program should declare three int variables, x, y, and z, and initialize them to 2, 6, and 11, respectively rogram, testcalc.c, that will test calc .c.

Explanation / Answer

Part1:

calc.c

int calc(int x,int y,int z)
{
return 3*x + 2*y + 15* z;
}

calc.s code

.file "calc.c"

.text

.globl _calc

.def _calc; .scl 2; .type 32; .endef

_calc:

LFB0:

.cfi_startproc

movl 4(%esp), %eax

movl 12(%esp), %ecx

movl %eax, %edx

addl 8(%esp), %edx

leal (%eax,%edx,2), %edx

movl %ecx, %eax

sall $4, %eax

subl %ecx, %eax

addl %edx, %eax

ret

.cfi_endproc

LFE0:

.ident "GCC: (MinGW.org GCC-6.3.0-1) 6.3.0"

Part 2:

#include<stdio.h>
#include<conio.h>

int calc(int x,int y,int z)
{
return 3*x + 2*y + 15* z;
}

int main()
{

int x=2,y=6,z=11;
printf("%d",calc(x,y,z));

}

O/P:

183

testcalc.s

.file "testcalc.c"

.text

.globl _testcalc

.def _testcalc; .scl 2; .type 32; .endef

_testcalc:

LFB12:

.cfi_startproc

movl 4(%esp), %eax

movl 12(%esp), %ecx

movl %eax, %edx

addl 8(%esp), %edx

leal (%eax,%edx,2), %edx

movl %ecx, %eax

sall $4, %eax

subl %ecx, %eax

addl %edx, %eax

ret

.cfi_endproc

LFE12:

.def ___main; .scl 2; .type 32; .endef

.section .rdata,"dr"

LC0:

.ascii "%d"

.text

.globl _main

.def _main; .scl 2; .type 32; .endef

_main:

LFB13:

.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 $16, %esp

call ___main

movl $183, 4(%esp)

movl $LC0, (%esp)

call _printf

movl $0, %eax

leave

.cfi_restore 5

.cfi_def_cfa 4, 4

ret

.cfi_endproc

LFE13:

.ident "GCC: (MinGW.org GCC-6.3.0-1) 6.3.0"

.def _printf; .scl 2; .type 32; .endef

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote