In 16 bit 2s complement signed arithmetic: 0111 1111 1111 1111 =3D +32767 0111 1111 1111 1110 =3D +32766 .. .. .. 0000 0000 0000 0001 =3D +1 0000 0000 0000 0000 =3D 0 1111 1111 1111 1111 =3D -1 1111 1111 1111 1110 =3D -2 .. .. .. 1000 0000 0000 0001 =3D -32767 1000 0000 0000 0000 =3D -32768 So, adding 1 to +32767 results in -32768. No number can be larger than=20 +32767 or smaller than -32768. To change the sign of a number, e.g. -10 to +10, invert all the bits and=20 add 1. Does that help? Kerry IVP wrote: > Hi all, and hi to my brain, wherever it went for Christmas. Come > back soon, miss you > > I'm trying to rationalise this testing and limiting to express it in=20 > assembler > > If Result > 32767 then Result =3D 32767 > > If Result < -32768 then Result =3D -32768 > > It would help if I could get an idea of how more-negative works > past 16 bits. I've not found anything specifically useful after some > looking around > > In this example, -32768 - (+20) > > mov #20,w0 ;temp0 =3D 20 =3D 0x0014 > mov w0,temp0 > mov -#32768,w1 ;temp1 =3D -32768 =3D 0x8000 > mov w1,temp1 > > mov temp0,w0 > mov temp1,w1 > sub w0,w1,w2 ;w2 =3D 0x8014 =3D -32748 > > In this example, -32768 - (-20) > > mov -#20,w0 ;temp0 =3D -20 =3D 0xFFEC > mov w0,temp0 > mov -#32768,w1 ;temp1 =3D -32768 =3D 0x8000 > mov w1,temp1 > > mov temp0,w0 > mov temp1,w1 > sub w0,w1,w2 ;w2 =3D 0x7FEC =3D -20 (bit15 =3D = 0) > > Questions - > > (1) what does - 32769 look like ? > (2) what would be a method to test for < -32768 on a dsPIC ? > > Should I be looking at the 40-bit Accumulators for this ? > > TIA > > Joe > =20 --=20 Internal Virus Database is out-of-date. Checked by AVG Anti-Virus. Version: 7.0.289 / Virus Database: 267.11.13 - Release Date: 10/6/05 --=20 http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .