Pigmeo was a compiler and framework for writing microcontroller firmware in C# and other .NET languages, developed by Adrián Bulnes (Urriellu) between 2007 and 2010. This is a frozen, read-only archive of the project’s website, pigmeo.org; nothing here is maintained. Source code: github.com/Urriellu/pigmeo · Original capture: Wayback Machine · urriellu.net

CCS PCM Output 003 - Multiply by a power of 2

From Pigmeo Development Wiki

C language

#include <16F716.h>
 
#byte	PORTA=0x05
#byte	PORTB=0x06
#byte	Result=0x20
 
void main() {
	Result=PORTA*4;
}

Assembly language

0000:  MOVLW  00
0001:  MOVWF  0A
0002:  GOTO   004
0003:  NOP
.................... #include <16F716.h> 
.................... //////// Standard Header file for the PIC16F716 device //////////////// 
.................... #device PIC16F716 
.................... #list 
....................  
....................  
.................... #byte	PORTA=0x05 
.................... #byte	PORTB=0x06 
.................... #byte	Result=0x20 
....................  
.................... void main() { 
0004:  CLRF   04
0005:  MOVLW  1F
0006:  ANDWF  03,F
0007:  BSF    03.5
0008:  BSF    1F.0
0009:  BSF    1F.1
000A:  BSF    1F.2
.................... 	Result=PORTA*4; 
000B:  BCF    03.5
000C:  RLF    05,W  ;Rotate left PORTA and put result into W
000D:  MOVWF  20   ;W->Result
000E:  RLF    20,F  ;Rotate left Result
000F:  MOVLW  FC    ;MOVLW+ANDWF for clearing bits 0 and 1 in Result (I suppose it's because the carry bit can be 1, and we always want 0 after rotating
0010:  ANDWF  20,F
.................... } 
0011:  SLEEP

Conclusions

  • Multiply by a power of two should be done by rotating registers to the left