Problem Convert C code to Assembly This is a little piece of

Problem: Convert C code to Assembly.

This is a little piece of code about an if statement in C. Re-write it on Assembly Language. unsigned, char i, j; if (j > = 0 times 25) {j = j - i;}

Solution

Please follow the code and description :

CODE :

#include <stdio.h>

int main(void) // driver method
{
   unsigned char i, j; // local varaibles
if(j >= 0x25) { // check for the value
j = j - i; // calculate the results
}
   return 0;
}


Assembly Code :

   

Here the declaration of the main method do takes place as below for
int main(void)
    .Ltext0:
        .globl   main
    main:
    .LFB0:
        .cfi_startproc

Now that the main driver method is preceded by a braces for the ease fo execution conveying that the process or the code has benn started. So the below represents the initialisation of the executable code by making the register value opened as a operation of pushq and that moving to the desired locationof the register The local varaibles are thus generalised over the registers.
{
0000 55        pushq   %rbp
        .cfi_def_cfa_offset 16
        .cfi_offset 6, -16
0001 4889E5        movq   %rsp, %rbp
        .cfi_def_cfa_register 6

Now that the compariosn of the values based on the hexadecimal value is done using the operation cmpb such that the values in the register and the respective byte values as such in this case the value in the rbp(local varaible/register) is compared with the byte value of 36.
in the code which resembles the line,
if(j >= 0x25)
0004 807DFE24        cmpb   $36, -2(%rbp)
0008 7607        jbe   .L2 // jump to value l2 if the comparison is below or equal to

Now that if the condition is satiafied the value is moved with sign extend from byte to longword (movzbl) to eax register and that the result is subtracted from the rbp and saved it to the al register.
j = j - i;
000a 0FB645FF        movzbl   -1(%rbp), %eax
000e 2845FE        subb   %al, -2(%rbp)

After the execution is done the code returns to the l2 register for the execution to be completed and moves the temporary register value to 0 and that could be returned to the main if any.
return 0;
    .L2:
0011 B8000000        movl   $0, %eax
00
     
Lastly the cod eis doen about the execution and that the main is closed for the effect of completion with a brace. Here the value is poped out and the result is returned.
}
0016 5D        popq   %rbp
        .cfi_def_cfa 7, 8
0017 C3        ret
        .cfi_endproc
    .LFE0:
    .Letext0:
              

              
Hope this is helpful.

Problem: Convert C code to Assembly. This is a little piece of code about an if statement in C. Re-write it on Assembly Language. unsigned, char i, j; if (j >
Problem: Convert C code to Assembly. This is a little piece of code about an if statement in C. Re-write it on Assembly Language. unsigned, char i, j; if (j >

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site