simple assembler for PIC12 microcontrollers
This guide was made for Linux. It may work on MacOS. For windows some details may be different.
- install Rust and Cargo to build the program
- run
cargo build --release
in root directory of this repository - copy file
target/release/pic12asm
to any directory in your PATH (eg.~/.local/bin
or/usr/local/bin
)
Simply put the executable file in a directory with executable files
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.
The DATA k
pseudo-instruction is replaced by value k
, made for instrrupt vector.
This instruction tells assembler to fill current bank with NOP
s and go to the next bank of ROM. Attempt to go to next bank without this instruction will cause an error.
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
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
- 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