Je recherche ces deux fonctions-ci.
Si quelqu'un peut m'aider.
Merci d'avance
Je recherche ces deux fonctions-ci.
Si quelqu'un peut m'aider.
Merci d'avance
Bonjour et bienvenue,
Voici par exemple en Assembleur x86 16 bits, syntaxe MASM :
atoi :
itoa :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 ; ATOI.ASM --- Convert ASCII string to 16-bit decimal integer. ; ; By Ray Duncan ; ; Call with: DS:SI = address of string, ; where 'string' is in the form ; [whitespace][sign][digits] ; ; Returns: AX = result ; DS:SI = address+1 of terminator ; ; Destroys: Nothing ; ; Like the C runtime library function 'atoi', this routine gives no ; warning of overflow, and terminates on the first invalid character. _TEXT segment word public 'CODE' _TEXT ends _DATA segment word public 'DATA' _DATA ends STACK segment para stack 'STACK' STACK ends DGROUP group _DATA,STACK assume cs:_TEXT,ds:DGROUP,ss:DGROUP,es:DGROUP blank equ 20h ; ASCII blank character tab equ 09h ; ASCII tab character _TEXT segment public atoi atoi proc near push bx ; save registers push cx push dx xor bx,bx ; initialize forming answer xor cx,cx ; initialize sign flag atoi1: lodsb ; scan off whitespace cmp al,blank ; ignore leading blanks je atoi1 cmp al,tab ; ignore leading tabs je atoi1 cmp al,'+' ; if + sign, proceed je atoi2 cmp al,'-' ; is it - sign? jne atoi3 ; no, test if numeric dec cx ; was - sign, set flag ; for negative result atoi2: lodsb ; get next character atoi3: cmp al,'0' ; is character valid? jb atoi4 ; jump if not '0' to '9' cmp al,'9' ja atoi4 ; jump if not '0' to '9' and ax,0fh ; isolate lower four bits xchg bx,ax ; previous answer x 10 mov dx,10 mul dx add bx,ax ; add this digit jmp atoi2 ; convert next digit atoi4: mov ax,bx ; put result into AX jcxz atoi5 ; jump if sign flag clear neg ax ; make result negative atoi5: pop dx ; restore registers pop cx pop bx ret ; back to caller atoi endp _TEXT ends end
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 ; ITOA.ASM --- Convert 16-bit integer to ASCII string ; ; By Ray Duncan ; ; Call with: AX = 16-bit integer ; DS:SI = buffer to receive string, ; must be at least 6 bytes long ; CX = radix ; ; Returns: DS:SI = address of converted string ; AX = length of string ; ; Destroy: Nothing ; ; Since test for value = zero is made after a digit ; has been stored, the resulting string will always ; contain at least one significant digit. _TEXT segment word public 'CODE' _TEXT ends _DATA segment word public 'DATA' _DATA ends STACK segment para stack 'STACK' STACK ends DGROUP group _DATA,STACK assume cs:_TEXT,ds:DGROUP,ss:DGROUP,es:DGROUP _TEXT segment public itoa itoa proc near push dx add si,6 ; advance to end of buffer push si ; and save that address. or ax,ax ; test sign of 16-bit value, pushf ; and save sign on stack. jns itoa1 ; jump if value was positive. neg ax ; find absolute value. itoa1: mov dx,0 ; divide value by radix to extract div cx ; next digit for forming string add dl,'0' ; convert remainder to ASCII digit cmp dl,'9' ; in case converting to hex ASCII, jle itoa2 ; jump if in range 0-9, add dl,'A'-'9'-1 ; correct digit if in range A-F itoa2: dec si ; back up through buffer mov [si],dl ; store this character into string or ax,ax jnz itoa1 ; no, convert another digit popf ; was original value negative? jns itoa3 ; no, jump dec si ; yes, store sign into output mov byte ptr [si],'-' itoa3: pop ax ; calculate length of string sub ax,si pop dx ret ; back to caller itoa endp _TEXT ends end
Règles du forum
Cours et tutoriels Pascal, Delphi, Lazarus et Assembleur
Avant de poser une question, consultez les FAQ Pascal, Delphi, Lazarus et Assembleur
Mes tutoriels et sources Pascal
Le problème en ce bas monde est que les imbéciles sont sûrs d'eux et fiers comme des coqs de basse cour, alors que les gens intelligents sont emplis de doute. [Bertrand Russell]
La tolérance atteindra un tel niveau que les personnes intelligentes seront interdites de toute réflexion afin de ne pas offenser les imbéciles. [Fiodor Mikhaïlovitch Dostoïevski]
Vous avez un bloqueur de publicités installé.
Le Club Developpez.com n'affiche que des publicités IT, discrètes et non intrusives.
Afin que nous puissions continuer à vous fournir gratuitement du contenu de qualité, merci de nous soutenir en désactivant votre bloqueur de publicités sur Developpez.com.
Partager