Question

In: Computer Science

3) Consider the following IA32 assembly language code fragment. Assume that a, b and c are...

3) Consider the following IA32 assembly language code fragment. Assume that a, b and c are integer variables declared in the data segment.

                        movl    a, %eax
                        movl    b, %ebx
                        cmpl    %ebx, %eax
                        jge     L1
                        movl    %eax, %ecx
                        jmp     L2 
                L1:     movl    %ebx, %ecx
                L2:     movl    %ecx, c 

Write the C code which is equivalent to the above assembly language code. You don't need to include the variable declarations, a function or anything like that, just show the 1 to 4 lines of code in C that express what the above assembly code is doing:

Solutions

Expert Solution

ANSWER::::::

In the given code first line is:

movl a,%eax : This speaks to that we are moving the worth present inside the a to the eax register . which is a 32 cycle register.

movl b,%eax : This speaks to that we are moving the worth present inside the b to the ebx register . which is a 32 cycle register.

cmpl %ebx,%eax: This speaks to the correlation activity between the qualities present inside ebx and eax registers. it is much the same as an if explanation where we checks ebx is more prominent than eax. On the off chance that it is genuine we will execute jge guidance which is close to it.

jge(jump if more noteworthy than or equivalent) L1: this is the continuation of above instruction.means ,it will execute, if and just if the worth present in the source register is more prominent than the worth present inside the objective register.Here L1 is a Label.

in this way, if the condition is valid. execution will bounce to the L1 hinder and execute the directions present inside L1 block.

movl %eax,%ecx: This speaks to we are moving the incentive in ecx to eax.

jmp L2: This speaks to the execution will hop to L2 impede and execute the guidance present inside L2 block.

L1: movl %ebx, %ecx

L2: movl %ecx, c

The over two guidelines are available in the L1 and L2 block individually.

C code for the given problem is:

          int a,b,c;/*this are the memory or variables*/

          int *eax,*ebx,*ecx;/*In C ,we can use pointer variables in place of registers*/

         *eax=a;

         *ebx=b;

         if(*ebx>*eax)

        {/*if value in ebx is greater than value in eax */

                   *ecx=*ebx;/* L1 block is executing*/

         }

         *ecx=*eax; /*moving the value present inside eax into ecx*/

         c=*ecx;/* L2 block is executing*/


Related Solutions

Assembly Language Programming Construct an assembly language program fragment equivalent to the following C/C++ statement: if...
Assembly Language Programming Construct an assembly language program fragment equivalent to the following C/C++ statement: if (M <= N + 3 && (C == ‘N’ || C == ‘n’)) C = ‘0’; else C = ‘1’; Assume that M and N are 32-bit signed integer variables, and C is an 8-bit ASCII character variable. All variables are stored in memory, and all general-purpose registers are available for use.
Consider the following fragment of C code: for (i=0; i<100; i++) { A[i]=B[i]+C; } Assume that...
Consider the following fragment of C code: for (i=0; i<100; i++) { A[i]=B[i]+C; } Assume that A and B are arrays of 64-bit integers, and C and i are 64-bit integers. Assume that all data values and their addresses are kept in memory (at addresses 1000, 3000, 5000, and 7000 for A, B, C, and i, respectively) except when they are operated on. Assume that values in registers are lost between iterations of the loop. Assume all addresses and words...
Construct an assembly language program fragment equivalent to the following C/C++ statement: if (M <= N...
Construct an assembly language program fragment equivalent to the following C/C++ statement: if (M <= N + 3 && (C == ‘N’ || C == ‘n’)) C = ‘0’; else C = ‘1’; Assume that M and N are 32-bit signed integer variables, and C is an 8-bit ASCII character variable. All variables are stored in memory, and all general-purpose registers are available for use.
Write a code fragment in C language that tests the value of an integer num1. If...
Write a code fragment in C language that tests the value of an integer num1. If the value is 10, square num1. If it is 9, read a new value into num1. If it is 2 or 3, multiply num1 by 99 and print out the result. Implement your code using SWITCH statements
The following code fragment is expressed in arm assembly code. Fill in the blanks, so that...
The following code fragment is expressed in arm assembly code. Fill in the blanks, so that it is equivalent to the following C code. int counter; int x = 5; int y = 6; for (counter =10; counter >0;counter--) IF(X==Y) Y = Y + 1 ; ELSE Y = Y + 2} Fill in the blanks in the following code: MOV__________ ;loop counter into r0-ten times round the loop MOV__________ ;Value of y loaded into r1 MOV__________ ;Value of x...
The following code fragment is expressed in arm assembly code.Fill in the blanks, so that...
The following code fragment is expressed in arm assembly code. Fill in the blanks, so that it is equivalent to the following C code.int counter;int x = 5;int y = 6;for (counter =10; counter >0;counter--)IF(X==Y)Y = Y + 1 ;ELSEY = Y + 2}Fill in the blanks in the following code:MOV__________ ;loop counter into r0-ten times round the loopMOV__________ ;Value of y loaded into r1MOV__________ ;Value of x loaded into r2Next CMP ____________ ;assume r1 contains y and r2 contains...
Javascript. Consider the following code fragment, that is supposed to compute the pixel value let c...
Javascript. Consider the following code fragment, that is supposed to compute the pixel value let c = image.getPixel(x, y); const m1 = (c[0] + c[1] + c[2]) / 3; c = image.getPixel(x + 1, y); const m2 = (c[0] + c[1] + c[2]) / 3; image.setPixel(x, y, [m1 - m2, m1 - m2, m1 - m2]); Give three pairs of pixel values (x, y) = [?, ?, ?] and (x+1, y) = [?, ?, ?] in the input image, for...
The language is Assembly Language. Thank you! Assignment 3: Run the following code. Record what each...
The language is Assembly Language. Thank you! Assignment 3: Run the following code. Record what each of the flag changes are for each command. INCLUDE Irvine32.inc .data .code main PROC mov al,255 add al,1 call DumpRegs sub al,1 call DumpRegs sub al,1 call DumpRegs exit main ENDP END main
2. Translate the following C/Java code to MIPS assembly code. Assume that the values of a,...
2. Translate the following C/Java code to MIPS assembly code. Assume that the values of a, i, and j are in registers $s0, $t0, and $t1, respectively. Assume that register $s2 holds the base address of the array A (add comments to your MIPS code). j = 0; for(i=0 ; i<a ; i++) A[i]=i+j++;
4.Translate the following C code to MIPS assembly code. Assume that the value of i is...
4.Translate the following C code to MIPS assembly code. Assume that the value of i is in register $t0, and $s0 holds the base address of the integer MemArray if (i > 10) MemArray[i] = 0; else MemArray[i] = -MemArray[i]; 6.Translate the following C code to MIPS assembly code. Use a minimum number of instructions. Assume that the values of a, b, i, and j are in registers $s0, $s1, $t0, and $t1, respectively. Also, assume that register $s2 holds...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT