## on calcule avec la pile
.text
.globl main
main:
pushq $4 # 4 + 6
pushq $6
popq %rdi
popq %rbx
add %rbx, %rdi
call print_int
pushq $21 # 21 * 2
pushq $2
popq %rdi
popq %rbx
imul %rbx, %rdi
call print_int
pushq $4 # 4 + 7 / 2
pushq $7
pushq $2
popq %rbx
mov $0, %rdx
popq %rax
idivq %rbx # divise %rdx::%rax par %rbx
pushq %rax # le quotient dans est %rax
popq %rbx
popq %rdi
add %rbx, %rdi
call print_int
pushq $3 # 3 - 6 * (10 / 5)
pushq $6
pushq $10
pushq $5
popq %rbx
mov $0, %rdx
popq %rax
idivq %rbx # divise %rdx::%rax par %rbx dans %rax
pushq %rax
popq %rbx
popq %rax
imul %rbx, %rax
pushq %rax
popq %rbx
popq %rdi
sub %rbx, %rdi
call print_int
mov $0, %rax # on termine proprement
ret
## une routine pour afficher un entier (%rdi) avec printf
print_int:
mov %rdi, %rsi
mov $message, %rdi # arguments pour printf
mov $0, %rax
call printf
ret
.data
message:
.string "%d\n"
## Local Variables:
## compile-command: "gcc arith1-v2.s && ./a.out"
## End: