# SXMicrocontrollerMathMethod

## Two's complement 8 bit

from Andy Warren

If [...] your original number is in a register, you can do it with this bit of code:

```	not	REG	;REG = two's-complement of REG.
inc	REG	;
```

or this one:

```	mov	W, /REG	;W = two's-complement of REG
;*** WARNING: ADDLW was expanded in three instructions! Check if previous instruction is a skip instruction.
;        ADDLW   1       ;(REG is unchanged).
mov	Hack, W
mov	W, #1	;(REG is unchanged).
```

If the original number is in W, the easiest way is:

```;*** WARNING: Manual replacement required for "SUBLW k" instruction (w = k - w). Check if previous instruction is a skip instruction.
SUBLW   0       ;W = two's-complement of W.
```

Clyde Smith-Stubbs [clyde at htsoft.com] of HI-TECH Software says

[These snippits do not handle the problem: REG = 0x80] because there is no correct result in this case. The value 0x80 interpreted as 2's complement is legal, and equal to -128. The negative of this, 128, is NOT representable as an 8 bit 2's complement number.

 file: /Techref/scenix/lib/math/neg/8bit_sx.htm, 1KB, , updated: 2004/6/10 14:40, local time: 2020/9/27 22:25, TOP NEW HELP FIND:  52.3.228.47:LOG IN

 ©2020 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions?Please DO link to this page! Digg it! / MAKE! PIC Microcontroller Math Method Two's complement 8 bit

After you find an appropriate page, you are invited to your to this massmind site! (posts will be visible only to you before review) Just type in the box and press the Post button. (HTML welcomed, but not the <A tag: Instead, use the link box to link to another page. A tutorial is available Members can login to post directly, become page editors, and be credited for their posts.

Attn spammers: All posts are reviewed before being made visible to anyone other than the poster.
 Did you find what you needed? "No. I'm looking for: " "No. Take me to the search page." "No. Take me to the top so I can drill down by catagory" "No. I'm willing to pay for help, please refer me to a qualified consultant" "No. But I'm interested. me at when this page is expanded."

### Welcome to sxlist.com!

Site supported by
& kind contributors
just like you!

(here's why

Copies of the site on CD
are available at minimal cost.

.