> Sorry guys I fat fingered my previous message. Here's the rest of it. > > Guys, I have a value in W that's signed. Adding this value to a set of > two > variables is easy enough: > addwf blahL,f > clrf wreg > addwfc blahH,f > > W contains a signed value. If the value of W is a negative, doing the > following doesn't work (to subtract it instead of adding it.) This should work for both positive and negative values in both blah and w. Are you sure the negative number is in two's complement form? For example, an 8 bit negative 1 is 0xff, negative 2 is 0xfe, etc. When teaching twos complement numbering, I tell my students to imagine a hexadecimal odometer that counts forwards and backwards. Starting at zero and going forwared (positive) we get 0x00, 0x01, 0x02, 0x03, etc. Starting from there and going backwards, we get 0x03, 0x02, 0x01, 0x00, 0xff, 0xfe, 0xfd, etc. So, 0xfd is -3. Another twos complement trick I read about MANY years ago in Byte magazine is to change the sign of the "weight" of the most significant bit if the byte (or word or whatever) is in twos complement form. Looking at the 0xfd example of above, we convert it to binary to get: 1111 1101. Applying our new binary weights, starting at the msb, we find this number is: (1 * -128) + 1*64 + 1*32 + 1*16 + 1*8 + 1+4 + 0*2 + 1*1 = -3 Harold -- FCC Rules Updated Daily at http://www.hallikainen.com - Advertising opportunities available! -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist