Menu

[solved]-Assembly Language 20 Points Consider Following Function Unsigned Int Multbysomeconstant U Q39025471

Assembly Language I (20 points)a. Consider the followingfunction:

unsigned int multBySomeConstant (unsigned int u) {

return(u * someConstant); }

Which compiles to:

push %ebpmov %esp,%ebpmov 0x8(%ebp),%edxmov %edx,%eaxshl $0x3,%eaxadd %edx,%eaxpop %ebpret// Copy value of u into edx register

What is the value of integer someConstant?
(Hint: Choose easy value for u and walk thru the code.)

b. Please translate the following from C into assembly languagefor theLinux/Intel architecture (what we discussed in class)

int inefficientMult (int intmultiplicand,multiplier

)

if (multiplier == 1) return(multiplicand);{ if (multiplier == 0)

return(0);

return(multiplicand + inefficientMult(multiplicand,multiplier-1)); }

Please assume:
Instead of push-ing a general purpose register like eax,

a. At the beginning of the function, give yourself enough spaceon the stack to handle all local variables and any parameters topass to called functions:

sub $0x18,%esp

b. Later, when you want to pass a parameter to a calledfunction, copy the value from the register (e.g. eax) to where esppoints:

mov %eax,(%esp)

To compare (by subtraction) a value on the stack (like 0xC(%ebp))with

a constant (like 1) say:

cmpl $0x1,0xC(%ebp)

For the instruction above, to jump to address addr when thevalue in0xC(%ebp) is not equal to the value 1 say

jne addr

Alternatively, there is je for jump-equal.

Functions return their values in register eax.

Expert Answer


Answer to Assembly Language I (20 points)a. Consider the following function: unsigned int multBySomeConstant (unsigned int u) { re… . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *