wm: 5552

Download patch

ref: 00a90ab613d802127bc3108eb160711153aafbfa
parent: 218be5c0d3083dfaa7c48ebc02c78cb22bc48cd3
author: mkf <mkf@cloud9p.org>
date: Thu Jul 4 05:37:37 EDT 2024

5552a: remove main, add outfd

--- a/5552a.c
+++ b/5552a.c
@@ -184,84 +184,11 @@
 	{
 		for(int i = 0 ; i < pc ; i++)
 		{
-			write(0, program[i].inst, sizeof(Word));
-			write(0, program[i].mode, sizeof(Word));
-			write(0, program[i].arg1, sizeof(Word));
-			write(0, program[i].arg2, sizeof(Word));
+			write(outfd, program[i].inst, sizeof(Word));
+			write(outfd, program[i].mode, sizeof(Word));
+			write(outfd, program[i].arg1, sizeof(Word));
+			write(outfd, program[i].arg2, sizeof(Word));
 		}
 	}
 }
 
-int main(int argc, char* argv[])
-{
-	unsigned int inst, a, b, c;
-	char string[32], op[4];
-	while(scanf("%s %[^\n;]%*c", op, string) > 0)
-	{
-		sscanf(string, "%u %u %u", &a, &b, &c);
-		if(!strcmp(op, "DIE"))
-			inst = DIE;
-		if(!strcmp(op, "OUT"))
-			inst = OUT;
-		if(!strcmp(op, "NOT"))
-			inst = NOT;
-		if(!strcmp(op, "AND"))
-			inst = AND;
-		if(!strcmp(op, "NOR"))
-			inst = NOR;
-		if(!strcmp(op, "XOR"))
-			inst = XOR;
-		if(!strcmp(op, "SUB"))
-			inst = SUB;
-		if(!strcmp(op, "ADD"))
-			inst = ADD;
-		if(!strcmp(op, "SHR"))
-			inst = SHR;
-		if(!strcmp(op, "SHL"))
-			inst = SHL;
-		if(!strcmp(op, "PUT"))
-			inst = PUT;
-		if(!strcmp(op, "MOV"))
-			inst = MOV;
-		if(!strcmp(op, "LDM"))
-			inst = LDM;
-		if(!strcmp(op, "NTH"))
-			inst = NTH;
-
-		switch(inst)
-		{
-			/* no args */
-			case DIE:
-					printf("%u\n", inst);
-					break;
-			/* one arg */
-			case NOT:
-			case OUT:
-					printf("%u %u\n", inst, a);
-					break;
-			/* two args */
-			case PUT:
-			case MOV:
-			case LDM:
-				printf("%u %u %u\n", inst, a, b);
-				break;
-			/* three args */
-			case AND:
-			case NOR:
-			case XOR:
-			case SUB:
-			case SHL:
-			case SHR:
-			case ADD:
-			case NTH:
-				printf("%u %u %u %u\n", inst, a, b, c);
-				break;
-			/* should this ever happen? */
-			default:
-				fprintf(stderr, "unkown instr.\n");
-				return -1;
-			
-		}
-	}
-	return 0;
-}