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). add W, Hack
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: 2024/8/22 05:21,
18.224.64.30:LOG IN
|
©2024 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? <A HREF="http://piclist.com/tecHREF/scenix/lib/math/neg/8bit_sx.htm"> PIC Microcontroller Math Method Two's complement 8 bit</A> |
Did you find what you needed? |
![]() o List host: MIT, Site host massmind.org, Top posters @none found - Page Editors: James Newton, David Cary, and YOU! * Roman Black of Black Robotics donates from sales of Linistep stepper controller kits. * Ashley Roll of Digital Nemesis donates from sales of RCL-1 RS232 to TTL converters. * Monthly Subscribers: Gregg Rew. on-going support is MOST appreciated! * Contributors: Richard Seriani, Sr. |
Welcome to piclist.com! |
.