In: Computer Science
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:
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*/