new version
authorTobias Girstmair <t@thi3nkpad.lan>
Tue, 13 Nov 2018 02:11:02 +0000 (03:11 +0100)
committerTobias Girstmair <t@thi3nkpad.lan>
Tue, 13 Nov 2018 02:11:02 +0000 (03:11 +0100)
fakeasm.h
foo.c

index c00061275ef783e2b3c278a933efd2c7bb634762..a33c8e496ce8aca87b181644e4b230b52a94b5c6 100644 (file)
--- a/fakeasm.h
+++ b/fakeasm.h
@@ -2,15 +2,15 @@
 #define c2(x) (0xff & (x>>16))
 #define c1(x) (0xff & (x>> 8))
 #define c0(x) (0xff & (x    ))
-#define LSL(x)    x <<= 1;
-#define LSR(x)    x >>= 1;
+#define LSL(x)    carry = x>>7; x <<= 1;
+#define LSR(x)    carry = x&1; x >>= 1;
 #define SWAP(x)   x = ((x & 0x0F) << 4 | (x & 0xF0) >> 4);
 #define AND(x,y)  x &= y;
 #define ANDI(x,n) x &= n;
 #define OR(x,y)   x |= y;
 #define ORI(x,n)  x |= n;
 #define EOR(x,y)  x ^= y;
-#define ADD(x,y)  x += y;
+#define ADD(x,y)  carry = (x+y)>>8; x += y;
 #define ADC(x,y,c)x += y; x+=c;
 #define SUB(x,y)  x -= y;
 #define SUBI(x,n) x -= (u8)n;
diff --git a/foo.c b/foo.c
index 6c8469e77c690824c683e09cc00fc7db89d458fe..fdb92fcbdd12c2b5ca3a59378619729fd212da4a 100644 (file)
--- a/foo.c
+++ b/foo.c
@@ -86,24 +86,26 @@ int main(void) {
                MOV     (x, s)
                INC     (x)
                #define tmp o
-                unsigned short sum = 0; //XXX
-                sum += x;
-                sum >>= 1;
+               //NOTE: we only need 1 bit of the upper byte. instead of using a u16 and LSR'ing, 
+               //we can use a u8 for sum and use ROR (which shifts the carry in)
+               CLR     (tmp)
+               ADD     (tmp, x)
+               ROR     (tmp)
                 //nop
-                sum >>= 1;
-                sum += x;
-                sum >>= 1;
+               LSR     (tmp)
+               ADD     (tmp, x)
+               ROR     (tmp)
                 //nop
-                sum >>= 1;
-                sum += x;
-                sum >>= 1;
+               LSR     (tmp)
+               ADD     (tmp, x)
+               ROR     (tmp)
                 //nop
-                sum >>= 1;
-                sum += x;
-                sum >>= 1;
+               LSR     (tmp)
+               ADD     (tmp, x)
+               ROR     (tmp)
                 //nop
-                sum >>= 1;
-                x = sum;
+               LSR     (tmp)
+                x = tmp;
                #undef tmp
                t = ((i3&0x01)<<13 | i2<<5 | i1>>3) % 3;
                ADD     (t, n)
@@ -115,7 +117,7 @@ int main(void) {
                MOV     (x, s)
                INC     (x)
                #define tmp o
-                sum = 0; //XXX
+                unsigned short sum = 0; //XXX
                 sum += x;
                 sum >>= 1;
                 sum += x;
Imprint / Impressum