From e2be3b5fec966fac0edd30f6d32e5afd25eda084 Mon Sep 17 00:00:00 2001 From: Tobias Girstmair Date: Sat, 17 Nov 2018 21:12:26 +0100 Subject: [PATCH] new version --- fakeasm.h | 2 ++ foo.c | 20 ++++++++++---------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/fakeasm.h b/fakeasm.h index de0898f..0e31859 100644 --- a/fakeasm.h +++ b/fakeasm.h @@ -15,6 +15,7 @@ #define SUB(x,y) x -= y; //TODO: carry #define SUBI(x,n) x -= (u8)n; //TODO: carry #define INC(x) x++; //WARN: does not set carry +#define DEC(x) x--; sr_zero=!x; #define MOV(x,y) x = y; #define LDI(x,n) x = n; #define SBRC(x,b) if (x & 1< do if set @@ -25,6 +26,7 @@ int sr_zero = 0; //status register zero bit #define TST(x) if(x==0)sr_zero=1;else sr_zero=0; //WARN: not a complete TST mockup #define BREQ(l) if(sr_zero) goto l; +#define BRNE(l) if(!sr_zero) goto l; int carry = 0; //status register carry bit //WARN: not respected by all mocked instructions int asmtmp = 0; #define ROL(x) asmtmp = x>>7; x <<= 1; x |= carry; carry = asmtmp; diff --git a/foo.c b/foo.c index 6333bf1..45e0261 100644 --- a/foo.c +++ b/foo.c @@ -80,16 +80,16 @@ void g(void) { CLR (a1) LDI (loop, 8) mul: - SBRS (t, 0) - RJMP (skip2) - ADD (a1, i0) - ADC (a2, i1, carry) - skip2: - LSR (a2) - ROR (a1) - ROR (t) - loop--; - if (loop) goto mul; + SBRS (t, 0) + RJMP (skip2) + ADD (a1, i0) + ADC (a2, i1, carry) + skip2: + LSR (a2) + ROR (a1) + ROR (t) + DEC (loop) + BRNE (mul) MOV (t, a1) #undef a0 #undef a1 -- 2.39.3