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
| ; **************************************
; ****************************************
; ** name : coin64.asm **
; ** platform : linux x86_64 **
; ** compile : nasm -f elf64 coin64.asm **
; ** gcc coin64.o -o coin64 **
; ****************************************
; **************************************
; ==============================================================
; on precise quelles sont les fonctions de la libc qu'on utilise
; ==============================================================
extern printf
extern scanf
; =======================
; on definit les sections
; =======================
section .data
msg1: db "1er nombre: ", 0
msg2: db "2eme nombre: ", 0
msg3: db "resultat: "
msg4: db "%lld", 0
msg5: db 10, 0
section .bss
nb1: resq 1
nb2: resq 1
sum: resq 1
; ==========
; vroooom...
; ==========
section .text
global main
main:
push rbp ; on s'installe confortablement avec un prologue standard
mov rbp, rsp
mov rdi, msg1
call printf ; on affiche le premier message
mov rdi, msg4
mov rsi, nb1
call scanf ; on attend la saisie du premier nombre
mov rdi, msg2
call printf ; on affiche le deuxieme message
mov rdi, msg4
mov rsi, nb2
call scanf ; on attend la saisie du deuxieme nombre
mov rax, [nb1]
mov rbx, [nb2]
add rax, rbx ; on effectue l'addition
mov [sum], rax
mov rdi, msg3
mov rsi, qword [sum]
call printf ; on affiche le resultat a travers le 3eme message
mov rdi, msg5
call printf ; on finit en affichant un retour chariot, pour vider le tampon
leave ; et on quitte avec l'epilogue standard
ret |
Partager