| ; ========================= ; Programa Teste ; ========================= ; instale o programa ; https://www.msys2.org/ ; rode o programa ; ========================= ; Compilação ; ========================= ; cd /c ; mkdir pasta-teste ; cd pasta-teste ; notepad teste.asm ; nasm -fwin64 -o teste.o teste.asm ; ld -s -o teste.exe teste.o -lkernel32 ; ./teste.exe ; ========================= ; O arquivo está na pasta ; c:\pasta-teste\teste.asm ; ========================= ; Resultado ; ========================= ; Hello World ; ========================= bits 64 default rel section .rdata hello: db `Hello World\r\n` hello_len equ $ - hello section .text extern __imp_GetStdHandle extern __imp_WriteConsoleA extern __imp_ExitProcess global _start _start: sub rsp,32 mov ecx,-11 call [__imp_GetStdHandle] mov rcx,rax lea rdx,[hello] mov r8d,hello_len xor r9,r9 push 0 call [__imp_WriteConsoleA] xor ecx,ecx call [__imp_ExitProcess] ; Nunca chegará aqui! |
| ; ========================= ; Programa Teste ; ========================= ; Compilação ; ========================= ; nasm -f elf32 teste.asm ; ld -m elf_i386 -s -o teste teste.o ; ./teste ; ========================= ; Resultado ; ========================= ; Hello World ; ========================= section .data: msg db 'Hello World', 0xa len equ $ - msg section .text: global _start _start: mov edx, len mov ecx, msg mov ebx, 1 mov eax, 4 int 0x80 ; Saida mov eax, 1 mov ebx, 0 int 0x80 |
| ; ========================= ; Programa Teste ; ========================= ; Compilação ; ========================= ; nasm -f elf32 teste.asm ; ld -m elf_i386 -s -o teste teste.o ; ./teste ; ========================= ; Resultado ; ========================= ; ========================= section .data: section .text: global _start _start: ; Conteúdo ; Saida mov eax, 1 mov ebx, 0 int 0x80 |
| ; ========================= ; Programa Teste ; ========================= ; Compilação ; ========================= ; nasm -f elf32 teste.asm ; ld -m elf_i386 -s -o teste teste.o ; ./teste ; ========================= ; Resultado ; ========================= ; ========================= section .data: section .text: global _start _start: ; Comentário de uma linha ; Exemplo 1 ; Exemplo 2 ; Exemplo 3 ; Saida mov eax, 1 mov ebx, 0 int 0x80 |
| ; ========================= ; Programa Teste ; ========================= ; Compilação ; ========================= ; nasm -f elf32 teste.asm ; ld -m elf_i386 -s -o teste teste.o ; ./teste ; ========================= ; Resultado ; ========================= ; ========================= COMENTARIO equ 0 section .data: section .text: global _start _start: ; Não existe um suporte nativo, mas tem gambiarras possíveis: ; Opção 1 - Simplesmente um ponto-e-vírgula no início de cada linha (mas essa você já sabe) ; linha1 ; linha2 ; linha3 ; Opção 2 - Começa com ponto-e-vírtugla e protege o caractere de fim de linha com a contra-barra ; linha1\ linha2\ linha3 ; Opção 3 - Testar se uma macro inexistente existe %ifdef COMENTARIO ; pode ser qualquer coisa, contanto que não exista - ou seja, não esteja definida linha1 linha2 linha3 %endif ; Opção 4 - Avaliar uma expressão numérica que retorne falso sempre %if 0 linha1 linha2 linha3 %endif ; Abraço. ; Saida mov eax, 1 mov ebx, 0 int 0x80 |
| ; ========================= ; Programa Teste ; ========================= ; Compilação ; ========================= ; nasm -f elf32 teste.asm ; ld -m elf_i386 -s -o teste teste.o ; ./teste ; ========================= ; Resultado ; ========================= ; Este é meu primeiro programa. ; ========================= section .data: msg db 'Este é meu primeiro programa.', 0xa len equ $ - msg section .text: global _start _start: mov edx, len mov ecx, msg mov ebx, 1 mov eax, 4 int 0x80 ; Saida mov eax, 1 mov ebx, 0 int 0x80 |
; ========================= |
| ; ========================= ; Programa Teste ; ========================= ; Compilação ; ========================= ; nasm -f elf32 teste.asm ; ld -m elf_i386 -s -o teste teste.o ; ./teste ; ========================= ; Resultado ; ========================= ; X eh maior ou igual que Y ; ========================= section .data: ; x = 50 x dd 50 ; dd - Define Double Word - 4 bytes ; db - Define Byte - 1 Byte ; dw - Define Word - 2 Bytes ; dq - Define Quad Word - 4 Bytes ; dt - Define Ten Word - 10 Bytes ; y = 10 y dd 10 msg_maior db 'X eh maior ou igual que Y', 0xa len_maior equ $ - msg_maior msg_menor db 'X eh menor que Y', 0xa len_menor equ $ - msg_menor section .text: global _start _start: mov eax, DWORD [x] mov ebx, DWORD [y] cmp eax, ebx ; Comparacao: <, >, <=, >= jge maior_ou_igual ; if(eax >= ebx) ; je ==, jg >, jge >=, jl <, jle <=, jne != cmp eax, ebx ; Comparacao: <, >, <=, >= jl menor ; if(eax < ebx) ; je ==, jg >, jge >=, jl <, jle <=, jne != jmp final ; pula para o => final: maior_ou_igual: mov edx, len_maior mov ecx, msg_maior jmp imprimir; imprimir menor: mov edx, len_menor mov ecx, msg_menor jmp imprimir; imprimir imprimir: mov ebx, 1 mov eax, 4 int 0x80 ; Saida final: mov eax, 1 mov ebx, 0 int 0x80 |