Enviado em 18/10/2018 - 11:49h
Estava testando um "brinquedinho" enquanto aguardava o almoço e resolvi compartilhar.
//-------------------------------------------------------------------
//
// ASM Expr X86( 32 bits ):
//
// ARQUIVO:
// expr.c
//
// COMPILE:
// gcc expr.c -o expr -Wall -m32
//
//-------------------------------------------------------------------
//
#include <stdio.h>
#define REG_MAX 6
enum {
EAX = 0,
ECX,
EDX,
EBX,
ESI,
EDI
};
static char *REGISTER[REG_MAX] = { "%eax", "%ecx", "%edx", "%ebx", "%esi", "%edi" };
static int stack;
void push (void) {
if (stack < REG_MAX)
stack++;
}
void pop (void) {
if (stack)
stack--;
}
void push_number (int i) {
push();
printf ("mov $%d, %s\n", i, REGISTER[stack]);
}
void add (void) {
printf ("add %s, %s\n", REGISTER[stack], REGISTER[stack-1]);
pop();
}
void imul (void) {
printf ("imul %s, %s\n", REGISTER[stack], REGISTER[stack-1]);
pop();
}
void print_stack(void) {
printf ("Stack(%s) = %d\n",REGISTER[stack], stack);
}
int main (void) {
//----------------------------
//
// Expression:
// 10 * 20 + 3 * 5;
//
// Result: ecx = 215
//
//----------------------------
//
push_number(10);
push_number(20);
imul();
push_number(3);
push_number(5);
imul();
add();
print_stack();
return 0;
}
Aprenda a Gerenciar Permissões de Arquivos no Linux
Como transformar um áudio em vídeo com efeito de forma de onda (wave form)
Como aprovar Pull Requests em seu repositório Github via linha de comando
Procurando vídeos de YouTube pelo terminal e assistindo via mpv (2025)
Gravação de tela com temporizador
Aplicativo simples para gravar tela
Como fazer boot em img do debian 12.img da web? (11)
Manjaro 25.0 no permite usar crontab (1)
trocar linhas [RESOLVIDO] (11)