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
|
.global mscanf
.type mscanf, @function
mscanf:
pushq %rbp
movq %rsp, %rbp
movq %rdi, %r15 # %r15 = &format [ %d || %f || %c ]
movq %rsi, %r14 # %r14 = &var1
call parser # parse &format
call mread # sys_red [ !! ERREUR !!]
movq %rbp, %rsp
popq %rbp
ret
.global parser
.type parser, @function
parser:
pushq %rbp
movq %rsp, %rbp
movq %r15, %rcx # %rcx = &format
parser_loop:
movb (%rcx), %al
cmp $32, %al # case : espace
je parser_next # incq %rcx
cmp $37, %al # case : %
je parser_next # incq %rcx
cmp $100, %al # case : d
je int_init # pour les entiers
jmp error # SINON ERREUR
int_init: # %rdx = taille = 4
movq $4, %rdx
jmp parser_end
char_init: # %rdx = taille = 1
movq $1, %rdx
jmp parser_end
double_init: # %rdx = taille = 8
movq $8, %rdx
jmp parser_end
error:
pushq $1 # on quitte avec une erreur
call exit
parser_next:
incq %rcx # %rcx = &format + 1 (plutot 8 ?)
jmp parser_loop
parser_end:
movq %rbp, %rsp
popq %rbp
ret
.global mread
.type mread, @function
mread: # %rdx déja initialisé
pushq %rbp
movq %rsp, %rbp
movq $3, %rax # sys_print
movq $0, %rbx # stdin
movq %r14, %rcx # %rcx = &var1
int $0x80 # interruption
movq %rbp, %rsp
pop %rbp
ret
.global mprint
.type mprint, @function
mprint:
pushq %rbp
movq %rsp, %rbp
movq $4, %rax # sys_read
movq $1, %rbx # stdout
movq $9, %rdx # taille
movq %r15, %rcx # &msg
int $0x80 # interruption
movq %rbp, %rsp
popq %rbp
ret
.global exit
.type exit, @function
exit:
pushq %rbp
movq %rsp, %rbp
movq 16(%rbp), %rbx
movq $1, %rax
int $0x80 # interruption
ret # ne doit pas s'exec |
Partager