From: Bernhard Urban Date: Thu, 28 Oct 2010 10:45:47 +0000 (+0200) Subject: isa/examples: code fixes X-Git-Tag: bootrom_v1~240 X-Git-Url: http://wien.tomnetworks.com/gitweb/?p=calu.git;a=commitdiff_plain;h=ed680dd42d0e4b6ac162cdbd801348d86a77f18d isa/examples: code fixes --- diff --git a/2_isa/src/bittwiddling.c b/2_isa/src/bittwiddling.c index 65c6349..9488e88 100644 --- a/2_isa/src/bittwiddling.c +++ b/2_isa/src/bittwiddling.c @@ -1,4 +1,3 @@ - #define B0 (0x55555555) #define B1 (0x33333333) #define B2 (0x0F0F0F0F) @@ -14,17 +13,3 @@ int countbits(int x) { x = (x + (x >> 16)) & B4; return x; } - -int computeparity(int x) - x ^= x >> 16; - x ^= x >> 8; - x ^= x >> 4; - x &= 0xf; - return (0x6996 >> x) & 1; -} - -void main(void) { - countbits(B0); - computeparity(B0); - computeparity(B0+1); -} diff --git a/2_isa/src/bittwiddling.s b/2_isa/src/bittwiddling.s index 6a2adb1..53861d5 100644 --- a/2_isa/src/bittwiddling.s +++ b/2_isa/src/bittwiddling.s @@ -1,21 +1,9 @@ - .data -.align 32 -;#define B0 (0x55555555) -B0: -.dw 0x55555555 -;#define B1 (0x33333333) -B1: -.dw 0x33333333 -;#define B2 (0x0F0F0F0F) -B2: -.dw 0x0F0F0F0F -;#define B3 (0x001F001F) -B3: -.dw 0x001F001F -;#define B4 (0x0000003F) -B4: -.dw 0x0000003F +B0: .fill 0x55555555 +B1: .fill 0x33333333 +B2: .fill 0x0F0F0F0F +B3: .fill 0x001F001F +B4: .fill 0x0000003F .text @@ -24,15 +12,15 @@ countbits: ;x == r1 ;load address of B0 into r3 - ldil r3,low(B0); - ldih r3,high(B0); + ldil r3, B0@lo; + ldih r3, B0@hi; ;x = (x & B0) + ((x >> 1) & B0); ;r0 = (x >> 1) lrs r0,r1,1; ;load B0 into r2 - ldx r2, r3; + ldw r2, 0(r3); ;(x >> 1) & B0 and r0, r0, r2; @@ -44,30 +32,27 @@ countbits: add r0, r0, r1; ;load B1 into r2, use displacment for address of B1 (or add?) - ldx r2, (r3)(B1-B0); + ldw r2, B1-B0(r3); ;x = (x & B1) + ((x >> 2) & B1); lrs r1, r0, 2; and r1, r1, r2; - and r0, r0, r2; - add r0, r0, r1; ;x = (x + (x >> 4)) & B2; - ldx r2, (r3)(B2-B0); + ldw r2, B2-B0(r3); lrs r1, r0, 4; and r1, r1, r2; and r0, r0, r2; - add r0, r0, r1; ;x = (x + (x >> 8)) /*& B3 */ lrs r1, r0, 8; add r0, r0, r1; - ldx r2, (r3)(B4-B0); + ldw r2, B4-B0(r3); ;x = (x + (x >> 16)) & B4; lrs r1, r0, 16; add r0, r0, r1; @@ -76,17 +61,3 @@ countbits: ;return x; ret; ;} - -int computeparity(int x) - x ^= x >> 16; - x ^= x >> 8; - x ^= x >> 4; - x &= 0xf; - return (0x6996 >> x) & 1; -} - -void main(void) { - countbits(B0); - computeparity(B0); - computeparity(B0+1); -} diff --git a/2_isa/src/bootrom.c b/2_isa/src/bootrom.c index 254faed..58a678c 100644 --- a/2_isa/src/bootrom.c +++ b/2_isa/src/bootrom.c @@ -35,7 +35,6 @@ #define UART_RECV_NEW 1 /* TODO: - * - need jump to register value * - uart: clear new_receive bit after the byte is copied? * (implementation issue...) */ diff --git a/2_isa/src/bootrom.s b/2_isa/src/bootrom.s index 6732e26..98d6df3 100644 --- a/2_isa/src/bootrom.s +++ b/2_isa/src/bootrom.s @@ -59,7 +59,6 @@ send_byte: ;----- send_word: - ; TODO: loop? (less codesize...) lrs r0, r1, 0 call send_byte lrs r0, r1, 8 @@ -102,7 +101,6 @@ recv_word: ret - ;----- bootrom: call recv_byte diff --git a/2_isa/src/palindrom.c b/2_isa/src/palindrom.c index e065673..b1d0685 100755 --- a/2_isa/src/palindrom.c +++ b/2_isa/src/palindrom.c @@ -3,7 +3,7 @@ u8 palindrom(u8* str, u8 len) { u8 *str1, *str2; if (len == 0) { - return 0; + return 1; } str1 = str; str2 = str + len - 1; diff --git a/2_isa/src/palindrom.s b/2_isa/src/palindrom.s index 8094db3..1aa4051 100755 --- a/2_isa/src/palindrom.s +++ b/2_isa/src/palindrom.s @@ -3,21 +3,21 @@ ; r1 = str addr ; r2 = str len (u8) - ldi r0, 0 - - cmp r1, 0 - retzs ; return 0 if strlen = 0 + ldis r0, 0 + cmpi r2, 0 + ldiszsd r0, 1 + retzs ; return 1 if strlen = 0 add r4, r1, r2 ; set r4 to end address - subi r4, 1 + subi r4, r4, 1 cmp r1, r4 ; if strlen = 1 return 1 brancheq- end schleife: - ldb r5, r1 - ldb r6, r4 + ldb r5, 0(r1) + ldb r6, 0(r4) cmp r5, r6 retnq ; return 0 when palindrom not satisfied diff --git a/2_isa/src/strncmp.c b/2_isa/src/strncmp.c new file mode 100644 index 0000000..2f9b333 --- /dev/null +++ b/2_isa/src/strncmp.c @@ -0,0 +1,10 @@ +int strncmp(const uint8_t *b1, const uint8_t *b2, size_t len) +{ + int diff=0; + + for (;len && (*b1) && (*b2) && !(diff); --len) { + diff = b1++ - b2++; + } + + return diff; +} diff --git a/2_isa/src/strncmp.s b/2_isa/src/strncmp.s index ab2682f..f4bce89 100644 --- a/2_isa/src/strncmp.s +++ b/2_isa/src/strncmp.s @@ -1,35 +1,22 @@ -int strncmp(const uint8_t *b1, const uint8_t *b2, size_t len) -{ - int diff=0; - - - for (;len && (*b1) && (*b2) && !(diff); --len) { - diff = b1[i] - b2[i]; - } - - return diff; -} - - -strncmp.s: +strncmp: ldis r5, 0 ; -:strfor +strfor: ldis r0, 0 ; -ldb r0, r1 ; r0 = (*b1) -ldb r5, r2 ; r5 = (*b2) -addi r3, 0 ; len == 0 -addinq r0, 0 ; (*b1) == 0 -addinq r5, 0 ; (*b2) == 0 +ldb r0, 0(r1) ; r0 = (*b1) +ldb r5, 0(r2) ; r5 = (*b2) +cmpi r3, 0 ; len == 0 +cmpinq r0, 0 ; (*b1) == 0 +cmpinq r5, 0 ; (*b2) == 0 ldiseq r0,0 ; reteq ; sub r0, r0, r5 ; diff = (*b1)-(*b2) -addi r0,0 ; diff!=0 +cmpi r0, 0 ; diff!=0 retnq ; -addi r1,1 ; ++b1 -addi r2,1 ; ++b2 -subi r3,1 ; ++len +addi r1, r1 ,1 ; ++b1 +addi r2, r2, 1 ; ++b2 +subi r3, r3, 1 ; --len branch strfor ;