12.07.2015 Views

Extended Precision Operations Little Endian vs Big Endian Which is ...

Extended Precision Operations Little Endian vs Big Endian Which is ...

Extended Precision Operations Little Endian vs Big Endian Which is ...

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Signed Right Shift (>>)Signed Right Shift in PIC16 AssemblyThe value 0x80 = -128 in two’s complement.Recall that right shift <strong>is</strong> same as divide by two. Then-128 >> 1 == -128 / 2 == -64 == 0xC0If unsigned right shift <strong>is</strong> performed (0 shifted into MSB), then0x80 >> 1 == 0x40 == +64 , the wrong answer!!When doing a signed right shift, the MSB must be kept thesame value (th<strong>is</strong> <strong>is</strong> also known as an arithmetic right shift).Makes sense, dividing a negative number by 2 should notchange the sign!!b7 b6 b5 b4 b3 b2 b1 b0C codesigned char i;i >> 1;Set carry to besame as sign bitbefore shift.PIC16 assembly;; i >> 1bcf STATUS,C ;clear carrybtfsc i,7 ;sign bit =1?bsf STATUS,C ;set carryrrf i ;i >> 1V 0.1 19V 0.1 20Signed Left Shift ( j true if i <strong>is</strong> to left of j,need for -i and +j to swap places if want to useunsigned compar<strong>is</strong>on0xFF2560x80128-1280x7f127+127-1 -i +jSwap sides of -i, +j by complementing sign bits0x00000x0000V 0.1 23PIC16: Signed Compar<strong>is</strong>on Algorithm #1Steps for i > j signed compar<strong>is</strong>onoperand adjustment1. Load j into w reg.2. Complement w sign bit by XOR’ing with 0x80.3. Store in temporary location (you pick), call th<strong>is</strong> temp.4. Load i into w reg.5. Complement w sign bit by XOR’ing with 0x80.6. Subtract w from temp (new j -newi).Unsigned compare7. If carry = 0, then i > jV 0.1 244

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!