Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Test del microlenguaje.
#include <stdio.h>
#include <stdlib.h>
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;
}
}
int main(int argc, char**argv) {
if(argc != 5) {
fprintf(stderr, "Usage: %s <almacén> <cantidad> <pendiente> <microprograma>\n\n"
"Example:\n"
"\t$ %s 3 2 4 \"sCra\"\n"
"\tA = 0, C = -2, P = 1\n", argv[0], argv[0]);
return 1;
}
int A = atoi(argv[1]);
int C = atoi(argv[2]);
int P = atoi(argv[3]);
Extraer(&A, &C, &P, argv[4]);
printf("A = %i, C = %i, P = %i\n", A, C, P);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.