Assembly NASM
Assembly NASM
Online: https://www.mycompiler.io/pt/new/asm-x86_64
Assemblers
rsp The stack pointer. Points to the top of the stack (details coming soon!) preserved rsp esp sp spl
Preserved register. Sometimes used to store the old value of the stack
rbp preserved rbp ebp bp bpl
pointer, or the "base".
Scratch register used to pass function argument #2 in 64-bit Linux. In 64-bit
rsi scratch rsi esi si sil
Windows, a preserved register.
Scratch register and function argument #1 in 64-bit Linux. In 64-bit
rdi scratch rdi edi di dil
Windows, a preserved register.
Scratch register. These were added in 64-bit mode, so they have numbers,
r8 scratch r8 r8d r8w r8b
not names.
r9 Scratch register. scratch r9 r9d r9w r9b
r10 Scratch register. scratch r10 r10d r10w r10b
r11 Scratch register. scratch r11 r11d r11w r11b
r12 Preserved register. You can use it, but you need to save and restore it. preserved r12 r12d r12w r12b
section .text
global _start
_start:
mov rax, 1 ; sys_write
mov rdi, 1 ; saída padrão
mov rsi, msg
mov rdx, 13
syscall
mov rax, 60
mov rdi, 0
syscall
NASM : Sub-rotinas
• Funções
• call e ret
• O código não se altera com a execução
NASM : Sub-rotinas
section .data _start: ; imprimir mensagem 2 ler_msg: encerrar:
msg1 db "Digite seu ; imprimir mensagem 1 mov rsi, msg2 mov rax, 0 mov rax, 60
nome: ", 10
mov rsi, msg1 mov rdx, tam2 mov rdi, 0 mov rdi, 0
tam1 equ $-msg1
mov rdx, tam1 call imprimir_msg syscall syscall
msg2 db "Ola, "
call imprimir_msg ret ret
tam2 equ $-msg2
; imprimir nome
tam_nome equ 10
; ler nome do usuário mov rsi, nome imprimir_msg:
mov rsi, nome mov rdx, tam_nome mov rax, 1
section .bss
mov rdx, tam_nome call imprimir_msg mov rdi, 1
nome resb tam_nome
call ler_msg syscall
call encerrar ret
section .text
global _start
section .data
msg db "Hello world!", LF, NULL
segment .data tam equ $-msg