Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; Ler o input do usuário STD_IN
- ; Montagem e linkedição: nasm -felf64 -o main.o main.asm && ld -o main main.o
- bits 64 ; Setando a arquitetura do programa
- global _start ; Setando o rótulo global
- section .data
- msg: db 'Digite seu nome: ', 0xF ; Armazenando os dados do input
- len: equ $ - msg ; Contando os caracteres
- section .bss
- buf: resb 7 ; Reservando 7 bytes em memória
- section .text
- _start:
- call _printMsg ; Printando a mensagem pro usuário
- call _readInput ; Coletando o valor do input do usuário
- call _printBuf ; Printando o conteúdo do input
- jmp _exit ; Saltando para o bloco de saída do programa
- _readInput:
- mov rax, 0 ; Chamando a syscall __NR_write
- mov rdi, rax ; Definindo STDIN
- mov rsi, buf ; Armazenando o endereço da memória reservada
- mov rdx, 7 ; Definindo o tamanho do buf
- syscall
- ret
- _printMsg:
- mov rax, 1 ; Chamando a syscall __NR_write
- mov rdi, rax ; Definindo STDOUT
- mov rsi, msg ; Armazenando o endereço do buffer
- mov rdx, len ; Definindo o tamanho do buffer
- syscall ; Chamada de sistema
- ret
- _printBuf:
- mov rax, 1 ; Chamando a syscall __NR_write
- mov rdi, rax ; Definindo STDOUT
- mov rsi, buf ; Armazenando o endereço do buffer
- mov rdx, 7 ; Definindo o tamanho do buffer
- syscall ; Chamada de sistema
- ret
- _exit:
- mov rax, 60 ; Definindo a syscall __NR_exit
- mov rdi, 0xff ; Definir o argumento da syscall
- syscall ; Chamada de sistema
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement