| Arquivo: makefile |
| troca: troca.cpp troca.o g++ troca.o troca.cpp -o troca troca.o: troca.asm nasm -f elf64 troca.asm -o troca.o #Compilar com o comando: #make |
| Arquivo: troca.cpp |
| #include <cstdio> #include <iostream> using namespace std; extern "C" int GetValorASM(int a); int main(){ printf("ASM me deu %d\n", GetValorASM(32)); return 0; } /* ========== Compilação ========== nasm -f elf64 troca.asm -o troca.o g++ troca.o troca.cpp -o troca ./troca ========== Resultado ========== ASM me deu 33 */ |
| Arquivo: troca.asm |
| global GetValorASM segment .text GetValorASM: mov eax, edi add eax, 1 ret |
| Arquivo: makefile |
| questao: questao.cpp questao.o g++ questao.o questao.cpp -o questao questao.o: questao.asm nasm -f elf64 questao.asm -o questao.o #Compilar com o comando: #make |
| Arquivo: questao.cpp |
| #include <iostream> /* ================== Compilacao ================== make ================== Execucao ================== ./questao ================== Resultado ================== Numero Par */ using namespace std; extern "C" int Question(int a); int main() { if (Question(26) == 1) { printf("Numero Par\n"); } else { printf("Numero Impar\n"); } return 0; } |
| Arquivo: questao.asm |
| global Question segment .text Question: mov ebx, edi jmp _testar ret _testar: cmp ebx, 0 je _par jl _impar sub ebx, 2 jmp _testar _par: mov eax, 1 ret _impar: mov eax, 0 ret ; JUMP ; jmp incondicional ; condicional ; cmp a, b ; je a == b ; jne a != b ; jg a > b ; jge a >= b ; jl a < b ; jle a <= b |