Skip to content

Instantly share code, notes, and snippets.

@josejuan
Created June 19, 2012 21:07
Show Gist options
  • Save josejuan/2956541 to your computer and use it in GitHub Desktop.
Save josejuan/2956541 to your computer and use it in GitHub Desktop.
Microcódigo de reglas.
void Extraer(
int *A, // I/O unidades actuales en almacén
int *C, // I/O valor actual en la tarifa
int *P, // I/O unidades pendientes a extraer
char *m // microprograma a ejecutar
) {
int r; // registro de memoria
#define INTENTA(S) { \
int x = S - *P; \
if(x >= 0) {S = x; *P = 0;} \
else {S = 0; *P = -x;} \
}
while(*m)
switch(*m++) {
case 'c': INTENTA(*C); break;
case 'a': INTENTA(*A); break;
case 'C': *C -= *P; *P = 0; break;
case 'A': *A -= *P; *P = 0; break;
case 's': r = *P; break;
case 'r': *P = r; break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment