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;
}
Servidor de Backup com Ubuntu Server 24.04 LTS, RAID e Duplicati (Dell PowerEdge T420)
Visualizar câmeras IP ONVIF no Linux sem necessidade de instalar aplicativos
Atualizar Debian Online de uma Versão para outra
Dica para encontrar diversos jogos Indies criativos
Instalando Discord no Debian 13
Instalar driver Nvidia no Debian 13
Redimensionando, espelhando, convertendo e rotacionando imagens com script
Software livre - será que eu estou tão errado assim? (11)
Boot do PosRog so funciona em notebook (1)