Question

In: Computer Science

2) Draw a line between each of the IA32 assembler routines on the left and its...

2) Draw a line between each of the IA32 assembler routines on the left and its equivalent C function on the right. (If there is no matching C function, do not draw a line.):

        pushl   %ebp
        movl    %esp, %ebp
        movl    8(%ebp), %edx
        movl    12(%ebp), %eax
        cmpl    %edx, %eax
        jle     .L1
        movl    %edx, %eax
.L1:
        leave
        ret
        pushl   %ebp
        movl    %esp, %ebp
        movl    8(%ebp), %edx
        movl    (%edx), %edx
        movl    12(%ebp), %eax
        movl    (%eax), %eax
        cmpl    %edx, %eax
        jle     .L1
        movl    %edx, %eax
.L1:
        leave
        ret
        pushl   %ebp
        movl    %esp, %ebp
        movl    8(%ebp), %eax
        movl    12(%ebp), %edx
        cmpl    %edx, %eax
        jge     .L1
        subl    %edx, %eax
.L1:
        leave
        ret
        pushl   %ebp
        movl    %esp, %ebp
        movl    8(%ebp), %edx
        movl    12(%ebp), %eax
        cmpl    %edx, %eax
        jge     .L1
        movl    %edx, %eax
.L1:
        leave
        ret
int fun1(int a, int b)
{
   if (a < b)
      return a-b;
   else
      return a;
}



int fun2(int a, int b)
{
   if (a > b)
      return a;
   else
      return b;
}





int fun3(int *a, int *b)
{
   if (*a < *b)
      return *a;
   else
      return *b;
}



int fun4(int a, int b)
{
   if (a < b)
      return a;
   else
      return b;
}



(b) Consider the following IA32 assembly language code fragment:

       .data
       .align 4
A:     .long 10, 20, 30, 40, 50
       .text
main: <code>

Determine the decimal value stored in register %eax if <code> in the above code fragment is replaced by each of the following:

i) movl $A, %ebx
   movl 4(%ebx), %eax

ii) movl $2, %ecx
   movl A(,%ecx, 4), %eax

iii)  movl $24, %eax
   sarl $2, %eax

iv) movl $4, %ecx
   leal 4(%ecx,%ecx,4), %eax

Solutions

Expert Solution

SOLUTION:

2)

(b)

(i)

movl $A, %ebx ;Move the address of A into register %eax

movl 4(%ebx), %eax ;Add 4 byte (one memory unit in 'Long' type ) to address stored in %ebx and move the contents of this address into %eax.

Value stored in %eax is 20

(ii)

movl $2, %ecx ;Move number 2 into register %ecx

movl A( , %ecx, 4), %eax ;Multiply content on %ecx with 4. Add the result to the address of A (struct_base) This gives the resultant address and move the contents of this address into %eax.

Value stored in %eax is 30

(iii)

movl $24, %eax ;Move number 24 into register %eax

sarl $2, %eax ;Arithmetic right shift to content in %eax for 2 times.

ie, (24)10 = (0001 1000)2

First shift -> 00001100

Second shift -> (00000110)2 = (6)10

Value stored in %eax is 6

(iv)

movl $4, %ecx ;Move number 4 into register %ecx

leal 4( %ecx, %ecx, 4), %eax ;Multiply content on %ecx with 4, add this with content on %ecx, and add 4 to it. This gives the resultant address

Resultant Address = (4 * %ecx) + %ecx + 4 = (4 * 4) + 4 + 4

Value stored in %eax is 24

**Fell free to ask any queries in the comment section. I am happy to help you. if you like our work, please give Thumbs up**


Related Solutions

1. Explain the difference between an Assembler and a Compiler. 2. What is the version of...
1. Explain the difference between an Assembler and a Compiler. 2. What is the version of Visual Basic used today? Is this the only Basic compiler that exists?
1)draw a line with an undefined slope and negative x intercept . 2)draw a line with...
1)draw a line with an undefined slope and negative x intercept . 2)draw a line with a negative slope and positive y - intercept. 3)line l has positive slope and a positive x intercept .Line m has negative slope and a negative y-intercept .Can line l intersect line m in cuadrant III? justify your answer please help
What is the proper way to define an assembly code in in-line assembler x86 for this...
What is the proper way to define an assembly code in in-line assembler x86 for this case: multiplication without using mul/imul, using hexadecimal numbers for "shl" instruction.
Draw a diagram which illustrates the difference between a multi-line queue and a single-line queue.
Draw a diagram which illustrates the difference between a multi-line queue and a single-line queue.
For each item in the left column, determine whether it can be an above-the-line deduction, a...
For each item in the left column, determine whether it can be an above-the-line deduction, a deduction from AGI to arrive at taxable income, or neither. Select from the option list provided. Item Allowable Deduction 1. Unreimbursed expenses incurred by an eligible educator for books and supplies used in the classroom 2. Unreimbursed direct moving expenses incurred for qualified active-duty military relocation 3. Payments for child support 4. Alimony payments made pursuant to a divorce finalized before 2019 5. Charitable...
Suppose a particle is moving right and left in a straight line. Its position, in centimeters,...
Suppose a particle is moving right and left in a straight line. Its position, in centimeters, at time t seconds is given by the function s(t) = −t3 + 12t2 − 21t. (For the purposes of this problem, assume that t ≥ 0.) (a) At what t-values is the particle stopped (that is, has a velocity of zero)? (b) Over what time interval(s) is the particle moving left? (c) Find the acceleration of the object when t = 4.
Suppose a particle is moving right and left in a straight line. Its position, in centimeters,...
Suppose a particle is moving right and left in a straight line. Its position, in centimeters, at time t seconds is given by the function s(t) = −t^3+ 12t^2 − 21t. (For the purposes of this problem, assume that t ≥ 0.) (a) At what t-values is the particle stopped (that is, has a velocity of zero)? (b) Over what time interval(s) is the particle moving left? c) Find the acceleration of the object when t = 4.
Programs 1 and 2 (Line Scan Conversion) 1.Write a function to draw a line using the...
Programs 1 and 2 (Line Scan Conversion) 1.Write a function to draw a line using the Basic line drawing algorithm. The following is a function header example: Basic-alg( int x0, int y0, int x1, int y1 ) Use this function to draw N lines (N is provided by the user) at positions (i.e., end coordinates) determined by a random number generator. 2.Write a function to draw a line using the "Bresenham" algorithm. The following is a header example:brz ( int...
One of the most difficult matters to determine is where to draw the line between free...
One of the most difficult matters to determine is where to draw the line between free enterprise and government intervention. Businesses tend to thrive on less regulation, but unregulated businesses also tend to cause harm to customers, investors, the environment, etc. Think of a business that is regulated and try to determine why types of regulations affect the business. Then, make a determination if the regulations are too much, too little, or just right. Be sure to make your discussion...
Find an example of a detergent. Using a line drawing, draw the detergent and provide its...
Find an example of a detergent. Using a line drawing, draw the detergent and provide its name.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT