Search code examples
assemblyx86calling-conventionatt

Subtraction order in assembly


So I have.

pushl %ebp
movl %esp, %ebp
movswl 12(%ebp), %edx
movl 8(%ebp), %eax
subl %edx, %eax
popl %ebp
ret

If say my function calls 2 variables: function(int a, short b).

When I call the subtraction, would it be (b - a) or (a - b). eax is where the value will be stored if I'm correct so I want to say it will be (a - b).


Solution

  • movl 8(%ebp), %eax brings your int a in the %EAX register.

    movswl 12(%ebp), %edx brings your short b in the %EDX register.

    Since subl %edx, %eax subtracts %EDX from %EAX you obtained (a - b)