1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
|
.data
.text
/**
* intisialisé %r15 avec &pile
**/
.global init
.type init, @function
init:
pushq %rbp
movq %rsp, %rbp
#movq 16(%rbp), %r15 # 16/32 marchent pas
movq %rdi, %r15
movq %rbp, %rsp
popq %rbp
ret
/**
* empiler une valeur dans &pile = %r15
**/
.global empiler
.type empiler, @function
empiler:
pushq %rbp # sauvegarde pointeur base
movq %rsp, %rbp # rsp = rbp
#movq 24(%rbp), %rax # recup val (ne marche pas toujours)
movq %rdi, %rax # recup val (OK)
movq %rsp, %r14 # sauv &sommet_fonction_empiler
movq %r15, %rsp # %rsp = &pile
push %rax # ENNFIIINNNN
movq %rsp, %r15 # sauv nouvelle &pile
movq %r14, %rsp # restaurer &sommet_fonction_empiler
movq %rbp, %rsp # restauration pointeur base
popq %rbp
ret
/**
* depiler valeur depuis &pile = %r15
**/
.global depiler
.type depiler, @function
depiler:
pushq %rbp # sauvegarde pointeur base
movq %rsp, %rbp # rsp = rbp
movq %rsp, %r14
movq %r15, %rsp
pop %rax
movq %rsp, %r15
movq %r14, %rsp
movq %rbp, %rsp # restauration pointeur base
popq %rbp
ret
.global addition
.type addition, @function
addition:
push %rbp /* sauvegarde pointeur base */
movq %rsp, %rbp
push %rbx /* sauvegarde des registres */
movq 24(%rbp), %rbx /* on prépare les opérandes */
movq 32(%rbp), %rax
addq %rbx, %rax /* on fait l'addition */
pop %rbx /* on restaure les registres */
movq %rbp, %rsp /* restauration pointeur base */
pop %rbp
ret
.global substract
.type substract, @function
substract:
push %rbp
movq %rsp, %rbp
push %rbx
movq 24(%rbp), %rbx
movq 32(%rbp), %rax
subq %rbx, %rax
pop %rbx
movq %rbp, %rsp
pop %rbp
ret
.global times
.type times, @function
times:
push %rbp
movq %rsp, %rbp
push %rbx
movq 24(%rbp), %rbx
movq 32(%rbp), %rax
imul %rbx
pop %rbx
movq %rbp, %rsp
pop %rbp
ret
.global divide
.type divide, @function
divide:
movq $0, %rdx /* Sinon problème de division */
push %rbp
movq %rsp, %rbp
push %rbx
movq 24(%rbp), %rbx
movq 32(%rbp), %rax
idiv %rbx
pop %rbx
movq %rbp, %rsp
pop %rbp
ret |
Partager