wm: 5551

Download patch

ref: 67f1be8c8bf3f883569a4a39fd3f15c5b543414d
parent: b1698f6307812f32fe6d062908d52ac3350e5e8b
author: Mahdi Hoessini <mahdi.hoseini1381@yahoo.com>
date: Fri May 12 03:18:13 EDT 2023

add DEC, INC, simplify sub and add

--- a/5551.h
+++ b/5551.h
@@ -15,7 +15,9 @@
 
 	/* arithmatic */
 	SUB,
-	ADD,
+	ADD
+	INC,
+	DEC,
 
 	/* shift */
 	SHR,
--- a/5551e.c
+++ b/5551e.c
@@ -11,14 +11,6 @@
 	int regs[8];
 }reg_t;
 
-bool add_bit(bool a, bool b)
-{
-	bool out;
-	out = ((a ^ b) ^ carry);
-	carry = (((a ^ b) & carry) | (a & b));
-	return out;
-}
-
 int btoi(bool b[], int len)
 {
   char arr[10];
@@ -78,20 +70,20 @@
 				break;
 			case SUB:
 				b = ~b;
-				carry = 1;
+				r.regs[CARRY] = 1;
+				r.flags[NSIGN] = (a < b);
+				r.regs[c] = r.flags[NSIGN] ? b - a : a - b;
 			case ADD:
-				while (a > 0 && b > 0) {
-					int diga = a % 10;
-					int digb = b % 10;
-					barr[ind] = add_bit(diga, digb);
-					a /= 10;
-					b /= 10;
-					ind++;
-				}
-				barr[ind] = carry;
-				r.regs[c] = btoi(barr,ind);
+				r.flags[NSIGN] = false;
+				r.regs[c] = a + b;
 				break;
+				r.flags[NSIGN] = false;
+				r.regs[b] = a + 1;
 				break;
+			case DEC:
+				r.regs[b] = a - 1;
+				r.flags[NSIGN] = (r.regs[b] < 0);
+				break;
 			case SHR:
 				r.regs[c] = a >> b;
 				break;
@@ -118,8 +110,6 @@
 		b = 0;
 		op = 0;
 		string[0] = '\0'; 
-        ind = 0;
-        carry = 0;
 	}
 	return 0;
 }