## on calcule dans %rsi, car c'est le second argument pour printf
.text
.globl main
main:
mov $4, %rdi # 4 + 6
add $6, %rdi
call print_int
mov $21, %rdi # 21 * 2
imul $2, %rdi
call print_int
mov $21, %rdi # ou encore avec un décalage
sal $1, %rdi
call print_int
mov $0, %rdx # 4 + 7 / 2
mov $7, %rax
mov $2, %rbx
idivq %rbx # divise %rdx::%rax par %rbx, dans %rax
mov $4, %rdi
add %rax, %rdi
call print_int
mov $7, %rdi # ou encore avec un décalage
sar $1, %rdi
add $4, %rdi
call print_int
mov $0, %rdx # 3 - 6 * (10 / 5)
mov $10, %rax
mov $5, %rbx
idivq %rbx # divise %rdx::%rax par %rbx dans %rax
imul $6, %rax
mov $3, %rdi
sub %rax, %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 -no-pie arith1-v1.s && ./a.out"
## End: