Skip to content

abirvalarg/pic12asm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pic12asm

simple assembler for PIC12 microcontrollers

Note

This guide was made for Linux. It may work on MacOS. For windows some details may be different.

installation

from sources

  1. install Rust and Cargo to build the program
  2. run cargo build --release in root directory of this repository
  3. copy file target/release/pic12asm to any directory in your PATH (eg. ~/.local/bin or /usr/local/bin)

From package

Simply put the executable file in a directory with executable files

Usage

don't forget about notes

You can use all instructions from the datasheet. Labels can be defined by adding a colon (:) after it's name, then it can be used instead of any number. As in other assemblers, everything that goes after a semicolon (;) is a comment and therefore ignored.

At this point you can only compile 1 file. Hopefully, it won't be a big problem because of limited resources of the platform.

Pseudo-instructions

DATA

The DATA k pseudo-instruction is replaced by value k, made for instrrupt vector.

BANK

This instruction tells assembler to fill current bank with NOPs and go to the next bank of ROM. Attempt to go to next bank without this instruction will cause an error.

Build

to build a file use following comand:

pic12asm input.asm output.bin

output.bin is a raw binary file ready to be flashed into your controller

Example

Here's an example of program for blinking a LED. I'm not sure if it works as intended on the hardware but it's a valid piece of code that can be built with this assembler.

DATA start
start:
        CLRWDT
        MOVLW 0b111110
        TRIS 6
        MOVLW 0
        MOVWF 1
        MOVLW 0b11010000
        OPTION
loop:
        BTFSC 1, 5
        GOTO isSet
        MOVLW 0
        MOVWF 6
        GOTO loop
isSet:
        MOVLW 1
        MOVWF 6
        GOTO loop

notes

  • Tested only with PIC12F509
  • Register names don't work yet, will be fixed in future versions
  • Destination select is always required if supported by instruction
  • Assembler doesn't check for all incorrect values