Hi again,

I just ran a couple of (semi-automated) tests and find arithmetics are
ok. For your reference, I attached the test suite and verifier.
To run, you need to patch gpsim-0.22.0 (see attached patch),

sdcc -mpic14 -p16f877 muldiv.c
gpsim -s muldiv.cod -c script.stc > output.log
perl muldiv.pl < output.log | less

(assuming you work on a Linux-like box).
Though Perl ain't good at verifying negative-valued results/operands,
you can manually verify the results: each line prints
.>>> (first operand) @@@ (second operand) *** (product) /// (quotient)

Results:
Division by 0 yields unexpected results: -1 (0xFFFFFFFF) if the first
operand is >= 0 (or unsigned), +1 (0x00000001) if the first operand is
less than 0 (result would be negative, so -1 is flipped...).

Tested with sdcc 2.7.2, r4852, gputils 0.13.4 beta (might be some CVS
version).

Regards,
Raphael


diff -rup gpsim-0.22.0/src/uart.cc ../gpsim-0.22.0/src/uart.cc
--- gpsim-0.22.0/src/uart.cc	2006-11-07 14:45:42.000000000 +0100
+++ ../gpsim-0.22.0/src/uart.cc	2007-06-15 11:23:17.000000000 +0200
@@ -120,6 +120,12 @@ void _TXREG::put(unsigned int new_value)
   trace.raw(write_trace.get() | value.get());
   value.put(new_value & 0xff);
 
+  if (isprint(new_value) || new_value == '\n' || new_value == '\r' || new_value == '\t') {
+    cout << (char)new_value;
+  } else {
+    cout << "[" << std::hex << new_value << "]";
+  }
+
   Dprintf(("txreg just got a new value:0x%x\n",new_value));
 
   // The transmit register has data,

#define NO_BIT_DEFINES 1
#include <pic14regs.h>

#define TYPE1	signed char

TYPE1
mult(TYPE1 op1, TYPE1 op2)
{
    return (op1 * op2);
}

TYPE1
divi(TYPE1 op1, TYPE1 op2)
{
    return (op1 / op2);
}

#define putc(c) do { TXREG = (c); } while (0)
void
puts(char *str)
{
    while (*str) {
	putc(*str);
	str++;
    }
}

void
print_long(unsigned long val)
{
    //static char hexits[] = "0123456789ABCDEF";
    unsigned char i;
    char c;
    for (i=0; i < 8; i++) {
	c = (val >> 28) & 0x0f;
	if (c < 10) c += '0';
	else c += 'A' - 10;
	putc(c);
	val <<= 4;
    }
}

static TYPE1 ops[] = { 0, 1, 2, 3, 4, 10, 20, 30, 50, 100, 500, 1000, 4000, 8000 };

void
done(void) {
}


void
main(void)
{
    TYPE1 op1, op2, res;
    unsigned char i,j;

    for (i = 0; i < sizeof(ops)/sizeof(TYPE1); i++) {
	op1 = ops[i];
	puts("###\n");
	for (j = 0; j < sizeof(ops)/sizeof(TYPE1); j++) {
	    puts(">>> "); print_long(op1);
	    op2 = ops[j];
	    puts(" @@@ "); print_long((unsigned long)op2);
	    res = mult(op1, op2);
	    puts(" *** "); print_long((unsigned long)res);
	    res = divi(op1, op2);
	    puts(" /// "); print_long((unsigned long)res);
	    putc('\n');

	    op1 = -op1;
	    puts(">>> "); print_long(op1);
	    puts(" @@@ "); print_long((unsigned long)op2);
	    res = mult(op1, op2);
	    puts(" *** "); print_long((unsigned long)res);
	    res = divi(op1, op2);
	    puts(" /// "); print_long((unsigned long)res);
	    putc('\n');
	    
	    op2 = -op2;
	    puts(">>> "); print_long(op1);
	    puts(" @@@ "); print_long((unsigned long)op2);
	    res = mult(op1, op2);
	    puts(" *** "); print_long((unsigned long)res);
	    res = divi(op1, op2);
	    puts(" /// "); print_long((unsigned long)res);
	    putc('\n');

	    op1 = -op1;
	    puts(">>> "); print_long(op1);
	    puts(" @@@ "); print_long((unsigned long)op2);
	    res = mult(op1, op2);
	    puts(" *** "); print_long((unsigned long)res);
	    res = divi(op1, op2);
	    puts(" /// "); print_long((unsigned long)res);
	    putc('\n');
	} // for j
    } // for i
    puts("done\n");
    done();
}


Attachment: muldiv.pl
Description: Perl program

Attachment: script.stc
Description: OpenOffice Calc template

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Sdcc-user mailing list
Sdcc-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sdcc-user

Reply via email to