user1697083
user1697083

Reputation:

Checking my understanding of simple assembly

I'm teaching myself assembly and am working through some exercises. Is my interpretation of this code in C correct? I think I have everything right except for potentially the bit at the bottom.

 push %ebp
 mov  %esp,%ebp
 sub  $0x10,%esp
 movl $0x0,-0x4(%ebp)
 mov  0xc(%ebp),%eax
 add  $0x4,%eax
 mov  (%eax),%eax
 cmp  0x8(%ebp),%eax
 jle  .L1
 mov  0xc(%ebp),%eax
 mov  (%eax),%eax
 sub  $0x7,%eax
 mov  %eax,-0x4(%ebp)
 .L1:
 mov  0x8(%ebp),%eax
 shl  $0x5,%eax
 add  %eax,-0x4(%ebp)
 mov  -0x4(%ebp),%eax
 leave  
 ret

My interpretation:

Two parameters go into this function: parameter_1 and *parameter_2

int a = 0;

if (parameter_2 + 4 =< parameter_1) {

    a = parameter_2 - 7;

} else {

a = (parameter_1 * 32) + a // shifting to the right by 5 would be like 2 * 5?, or is it just divided by 5?

}

Upvotes: 0

Views: 101

Answers (1)

rkhb
rkhb

Reputation: 14399

MinGW-GCC w/o Optimization produces exactly your Assembler code with:

int func (int a, int b[])
{
    int c = 0;
    if (b[1] > a)
    {
        c = b[0] - 7;
    }
    c += (a * 32);
    return c;
}

Upvotes: 2

Related Questions