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

Given this c program and its assembly, modify the assembly code so that it retur

ID: 3731592 • Letter: G

Question

Given this c program and its assembly, modify the assembly code so that it returns 3*x + 7*y + 14*z. Do not use the leal instruction. Use the 2-operand imull instruction with immediate addressing.

#include #include "calc.h" int calc(int x, int y, int z)í return 3*x 2*y 15*z; //Assembly file "calc.c" .text globl calc .type calc, @function calc: pushl %ebp movl %esp, %ebp movl 8(%ebp), %edx movl 16(%ebp), %ecx leal (%edx,XedX, 2), %eax movl 12 (%ebp), %eax leal (%edx,%eax,2), %eax movl %ecx, %edx sall $4, %edx subl %ecx, %edx addl %edx, %eax popl %ebp ret .size calc, .-calc .ident "GCC: (Ubuntu 4.3.3-5ubuntu4) 4.3.3" .section .note.GNU-stack," ",@progbits

Explanation / Answer

#include <stdio.h>

#include "calc.h"

int calc( intx, int y , intz)

{

return 3*x +2*y + 15*z;

}

//Assembly

.file "calc.c'

.text

.global calc

.type calc,@function

calc:

pushl %ebp #save the base pointer

movl %esp, %ebp # set new base pointer to sp

pushl %edi # save first argument on stack (x)

pushl %esi #save second argument on stack(y)

pushl %edx #save 3rd argument on stack (z)

subl $24, %esp #allocate one local variable

pushl %ebx #save callee- saved register

pushl %r12d

pushl %r13d

pushl %r14d

pushl %r15d

### body of function begins from here ###

movl -8(%ebp), %ebx #load each argument into a scratch register

movl -16(%ebp), %ecx

movl -24(%ebp), %edx

imull $3, %ebx # 3*x

movl %ebx,-32(%rbp) # stored in local variable 1

imull $2, %ecx # 2*y

movl %ecx,-40(%rbp) #stored in local variable 2

imull $15, %edx # 15*z

addl -32(%rbp), %edx #add the arguments together

addl -40(%rbp),%edx # 3*x+2*y+15*z

movl %edx, -48(%rbp) #store thr result in local variables created earlier

movl -20(%ebp), %eax # printing result

POP the callee saved register

popl %r15

popl %r14d

popl %r13d

popl%r12d

popl %ebx

movl %rbp, %rsp

popl %rbp

ret

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