Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .section .text
- .globl _start
- #------------------------------------------------------------------------------
- # Imprime un entier positif dans la sortie standard
- # input: %eax
- # Modified: none
- printint:
- call save_registers
- # Digit counter
- movl $0, %ebx
- movl $10, %ecx
- # Store each digit on stack
- while_1:
- movl $0, %edx
- divl %ecx
- pushl %edx
- # %eax récupère le quotient
- incl %ebx
- # Break as soon as %eax = 0
- cmpl $0, %eax
- je break_while_1
- jmp while_1
- break_while_1:
- # Print each digit
- for_1:
- # Break as soon as %ebx is null
- cmpl $0, %ebx
- je break_for_1
- popl %eax
- call printdigit
- decl %ebx
- jmp for_1
- break_for_1:
- call restaure_registers
- ret
- # Imprime un chiffre dans la sortie standard
- # input: %eax
- # Modified: none
- printdigit:
- call save_registers
- # Convert to ASCII code
- addl $48, %eax
- # Use stack as storage
- pushl %eax
- # Print digit
- movl $4, %eax
- movl $1, %ebx
- movl %esp, %ecx # storage address
- movl $1, %edx # length
- int $0x80
- # Restaure
- addl $4, %esp # remove %eax from stack
- call restaure_registers
- ret
- #------------------------------------------------------------------------------
- exit:
- movl %eax, %ebx # recuperation parametre = code retour
- movl $1, %eax # appel a la fonction 1 du noyau
- int $0x80 # terminer programme
- # Save %eax, %ebx, %ecx, %edx, %esi
- save_registers:
- # Move return address
- pushl %eax
- pushl %ebx
- pushl %ecx
- pushl %edx
- # Save return address
- movl 16(%esp), %eax
- # Swap return address with last saved value
- movl %esi, 16(%esp)
- pushl %eax # Restaure return address
- # Restaure %eax
- movl 16(%esp), %eax
- ret
- restaure_registers:
- # Restaure %esi
- movl 20(%esp), %esi
- # Move return address
- movl (%esp), %eax
- movl %eax, 20(%esp)
- addl $4, %esp
- # Restaure other registers
- popl %edx
- popl %ecx
- popl %ebx
- popl %eax
- ret
- # Calcule la longueur d'une chaine de caractère
- # %esi: input, adresse de la chaine, modified
- # %eax: output, length of the string
- # Modified: %esi
- length:
- # Save registers
- pushl %ebx
- # Calcule length
- movl $0, %eax
- do_1:
- movb (%esi), %bl
- cmpb $0, %bl
- je break_do_1
- incl %eax
- incl %esi
- jmp do_1
- break_do_1:
- # Restaure registers
- popl %ebx
- ret
- # Write "+" in stdout
- # Modified: none
- output:
- call save_registers
- leal debug, %esi
- movl %esi, %ecx
- call length
- movl %eax, %edx
- movl $4, %eax
- movl $1, %ebx
- int $0x80
- call restaure_registers
- ret
- _start:
- movl $45, %eax
- call printint
- movl $0, %eax
- call exit
- #------------------------------------------------------------------------------
- .section .rodata
- debug: .string "+"
Advertisement
Add Comment
Please, Sign In to add comment