LeapyNick
LeapyNick

Reputation: 105

Intel x86-64 assembly jump statement question

Im tasked with reverse engineering assembly code back into C-code

    jge    .L4
    movq   $76, -16(%rbp)
    movq   $87, -24(%rbp)
    jmp    .L5

.L4:
    movq   -16(%rbp), %rax
    imulq  -24(%rbp), %rax
    movq   %rax, -40(%rbp)

.L5:
    do more stuff

My question is after I am done with the L4 (an if statement using ordering operations) instructions do I go back up and execute the code to move 76 and 87 into memory locations or do I move onto L5? Also would the instructions to move 76 and 87 probably be in an else statement?

Upvotes: 1

Views: 209

Answers (1)

Barmar
Barmar

Reputation: 780663

There's nothing that goes back up. jge is not a function call, it's just a jump that doesn't save the old location anywhere.

So this is basically just an if and else statement. In pseudo-code it could be written as

if (ge) {
    // .L4
    movq   -16(%rbp), %rax
    imulq  -24(%rbp), %rax
    movq   %rax, -40(%rbp)
} else {
    movq   $76, -16(%rbp)
    movq   $87, -24(%rbp)
}
// .L5
do more stuff

Notice that the order of the if/else blocks is the opposite of the order of the assembly code, because jge jumps over the immediately following block when the condition is true.

Upvotes: 3

Related Questions