View Single Post
  #4   Spotlight this post!  
Unread 04-10-2005, 15:29
sciguy125 sciguy125 is offline
Electrical Engineer
AKA: Phil Baltar
FRC #1351
Team Role: College Student
 
Join Date: Jan 2005
Rookie Year: 2004
Location: Sunnyvale, CA
Posts: 519
sciguy125 has a reputation beyond reputesciguy125 has a reputation beyond reputesciguy125 has a reputation beyond reputesciguy125 has a reputation beyond reputesciguy125 has a reputation beyond reputesciguy125 has a reputation beyond reputesciguy125 has a reputation beyond reputesciguy125 has a reputation beyond reputesciguy125 has a reputation beyond reputesciguy125 has a reputation beyond reputesciguy125 has a reputation beyond repute
Send a message via AIM to sciguy125 Send a message via MSN to sciguy125 Send a message via Yahoo to sciguy125
Re: 16 bit math on PIC

Alright, thanks guys, I'm surprised I didn't figure that out.

But I still have a problem

Let's say that I want to do the following:

00000010 01000001
+ 00000001 01001010
---------------------
00000011 10001011

The lower byte of the result takes a full 8 bits. However, according to the datasheet, the addwf instruction that I would use only goes up to 127 (7 bits which I presume is to keep it signed with the 8th bit). How would this affect what I want to do?

I guess a more general question on this topic is what happens if I perform an arthithmatic operation and end up with something larger than 127. addwf, subwf, and a few other instructions only work up to 127 (according to the datasheet). If I get 128 does it overflow and give me garbage (as I would expect from code in a high level language) or does it just overflow into the MSB and behave nicely?
__________________

-----BEGIN GEEK CODE BLOCK-----
Version: 3.12
GE/S/P a-- e y-- r-- s:++ d+ h! X+++
t++ C+ P+ L++ E W++ w M-- V? PS+ PE+
5- R-- tv+ b+ DI+++ D- G
------END GEEK CODE BLOCK------