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.

C codeint i,j;i = i + j;LSByte addditionif C=1, add 1 toMSByteMSByte adddition16-bit AdditionPIC16 assemblyCBLOCK 0x040i:2,j:2ENDC;; i = i + jmovf j,w ; w ← j (LSB)addwf i,f ;i LSB ← w + i LSBbtfsc STATUS, Cincf i+1,f ;i MSB ← i MSB + 1movf j+1,w ; w ← j (MSB)addwf i+1,f ; i MSB← w +i MSB16-bit Subtraction using Carry Flag0x 34 10- 0x 22 400x 11 D0- ~C flagSubtract two LSBytes,if Cflag =0 after subtraction (a borrow), then decrement (-1)MSByte before MSByte subtractionV 0.1 7V 0.1 8C codeint i,j;i = i - j;LSByte subtractionif C=0, subtract 1from MSByteMSByte subtraction16-bit SubtractionPIC16 assemblyCBLOCK 0x040i:2,j:2ENDC;; i = i - jmovf j,w ; w ← j (LSB)subwf i,f ;i LSB ← i LSB - wbtfss STATUS, Cdecf i+1,f ;i MSB ← i MSB - 1movf j+1,w ; w ← j (MSB)subwf i+1,f ; i MSB← i MSB - wV 0.1 9addwfc f, dsubwfb f, dPIC16 assemblyPIC18 Add/Sub with Carrymovf j,w ; w ←j(LSB)addwf i,f ;LSB additionbtfsc STATUS, Cincf i+1,f ;MSB+1movf j+1,w ; w← j (MSB)addwf i+1,f ;MSB addition; d ← d + f + Cflag (add with carry); d ← f - d - ~Cflag (subtract with borrow)int i,j;i = i + j;PIC18 assemblymovf j,w ; w ←j(LSB)addwf i,f ; LSB additionmovf j+1,w ; w← j (MSB)addwfc i+1,f ;MSB additionMSByte, use add with carryV 0.1 1016-bit Increment/DecrementOn the PIC18, the increment/decrement instructions affectthe Carry flag, so can do increment/decrement of LSBytefollowed by add-with-carry/subtract-with-borrow to MSByte.On the PIC16, the increment/decrement instructions onlyaffect the Z flag, so cannot use C flag approach if incf/decfused (can always just do add + 1). Use the procedure below:0x33 FF0x34 00+ 1- 10x34 000x33 FFIf LSByte = 0 after increment,then increment MSbyteIf LSByte = 0 before increment,then decrement MSbyteV 0.1 11C codeint i;i++;LSByte incrementif Z=0, continueZ=1, so MSByteincrement16-bit IncrementPIC16 assemblyCBLOCK 0x040i:2ENDC;; i++;incf i,f ; i(LSB)+ 1btfsc STATUS,Z;Z=0?incf i+1,f ;i MSB ← i MSB + 1skip...continue...V 0.1 122

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

Saved successfully!

Ooh no, something went wrong!