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 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
| ; fonctions externes pour les entrees/sortie
extern printf
extern scanf
segment .data ; memoire globale donnees initialisees
prompt1 db "Entrez une chaine de caractere hexadecimal (minuscule): ",0
sortieSuccess db "Le nombre est hexadecimal",10,0
sortieFailure db "Le nombre traduits en decimal vaut : %ld",10,0
a db "a"
b db"b"
c db"c"
d db"d"
e db"e"
f db"f"
stringFormat db "%s",10,0
longIntFormat db "%ld",0
chaine db "%ld",9,0
teste db "entier :%ld ",0
newLine db 10,0
string times 0 dq 16
tab times 0 dq 16
segment .bss ; memoire globale donnees non itialisees
segment .text ; code du programme
global asm_main
asm_main: ; fonction appelee par le programme C
; sauvegarde des registres sur la pile
push rbp
; appel printf
mov rdi,stringFormat
mov rsi,prompt1
mov rax,0
call printf
; appel scanf
mov rdi,stringFormat
mov rsi,string
mov rax,0
call scanf
; parcours du tableau verification de chaque entrees
mov rcx,0
mov r8,16
while:
mov r10,0
cmp rcx,r8
je endwhile
mov r9,[string+rcx*8]
cmp r9,0
je next
inc r10
cmp r9,1
je next
inc r10
cmp r9,2
je next
inc r10
cmp r9,3
je next
inc r10
cmp r9,4
je next
inc r10
cmp r9,5
je next
inc r10
cmp r9,6
je next
inc r10
cmp r9,7
je next
inc r10
cmp r9,8
je next
inc r10
cmp r9,9
je next
inc r10
cmp r9,[a]
je next
inc r10
cmp r9,[b]
je next
inc r10
cmp r9,[c]
je next
inc r10
cmp r9,[d]
je next
inc r10
cmp r9,[e]
je next
inc r10
cmp r9,[f]
je next
; appel printf SI echec
mov rdi,stringFormat
mov rsi,sortieFailure
mov rax,0
call printf
jmp e1
;on enregistre dans un tableau les valeurs des chiffres hexadecimal
next: mov [tab+rcx*8],r10
inc rcx
jmp while
endwhile:
mov rcx,0
mov r11,0
while2:
; on decale et ajoute les different chiffres hexadecimal
cmp rcx,r8
je endwhile2
mov r9,[tab+rcx*8]
mov r10,0
while3: cmp rcx,r10
je next2
shl r9,4
inc r10
jmp while3
next2: add r11,r9
inc rcx
jmp while2
;on affiche le resultats
endwhile2:
; appel printf reussite
mov rdi,sortieSuccess
mov rsi,r11
call printf
jmp e1
e1 :
; restauration des registres
pop rbp
; envoi de 0 au programme C
mov rax, 0
ret |
Partager