bmandl
Full Member level 4
Hello guys.
I learned PIC assembly about 10 years back, when I started with microcontrollers. Back then, I never heard of relocatable programming with assembler. From then, I never used assembler again, because I was programing in C. But now I decided to do a project in assembler, because I like challenge. I want to learn relocatable way of programming with assembler, so I can build a libraries over time and use them across the projects. I got some simple LED blinking program, written in absolute mode, now I am strugling to change it to relocatable. I split the code in two .asm files and I can assembly them separately, but if I want to build a project, the linker gives me the error. I am using MPLABX and here is the whole output:
What am I doing wrong and how can I build a relocatable assembler program in MPLABX? In addition, how can I make a assebly library later, when I have a lot of object files?
Here is the code:
MAIN PROGRAM
DELAY PROGRAM
Thank you for your help.
I learned PIC assembly about 10 years back, when I started with microcontrollers. Back then, I never heard of relocatable programming with assembler. From then, I never used assembler again, because I was programing in C. But now I decided to do a project in assembler, because I like challenge. I want to learn relocatable way of programming with assembler, so I can build a libraries over time and use them across the projects. I got some simple LED blinking program, written in absolute mode, now I am strugling to change it to relocatable. I split the code in two .asm files and I can assembly them separately, but if I want to build a project, the linker gives me the error. I am using MPLABX and here is the whole output:
CLEAN SUCCESSFUL (total time: 102ms)
make -f nbproject/Makefile-default.mk SUBPROJECTS= .build-conf
make[1]: Entering directory 'D:/Documents/MPLABX/relocatable_code_example.X'
make -f nbproject/Makefile-default.mk dist/default/production/relocatable_code_example.X.production.hex
make[2]: Entering directory 'D:/Documents/MPLABX/relocatable_code_example.X'
"C:\Program Files (x86)\Microchip\MPLABX\v4.01\mpasmx\mpasmx.exe" -q -p12f675 -l"build/default/production/blinking_led.lst" -e"build/default/production/blinking_led.err" -o"build/default/production/blinking_led.o" "blinking_led.asm"
Message[302] D:\DOCUMENTS\MPLABX\RELOCATABLE_CODE_EXAMPLE.X\BLINKING_LED.ASM 52 : Register in operand not in bank 0. Ensure that bank bits are correct.
Message[302] D:\DOCUMENTS\MPLABX\RELOCATABLE_CODE_EXAMPLE.X\BLINKING_LED.ASM 55 : Register in operand not in bank 0. Ensure that bank bits are correct.
Message[312] D:\DOCUMENTS\MPLABX\RELOCATABLE_CODE_EXAMPLE.X\BLINKING_LED.ASM 73 : Page or Bank selection not needed for this device. No code generated.
"C:\Program Files (x86)\Microchip\MPLABX\v4.01\mpasmx\mpasmx.exe" -q -p12f675 -l"build/default/production/delay.lst" -e"build/default/production/delay.err" -o"build/default/production/delay.o" "delay.asm"
"C:\Program Files (x86)\Microchip\MPLABX\v4.01\mpasmx\mplink.exe" -p12f675 -w -m"dist/default/production/relocatable_code_example.X.production.map" -z__MPLAB_BUILD=1 -odist/default/production/relocatable_code_example.X.production.cof build/default/production/blinking_led.o build/default/production/delay.o
MPLINK 5.08, LINKER
Device Database Version 1.38
Copyright (c) 1998-2011 Microchip Technology Inc.
Error - section '.udata' can not fit the section. Section '.udata' length=0x00000003
Errors : 1
nbproject/Makefile-default.mk:140: recipe for target 'dist/default/production/relocatable_code_example.X.production.hex' failed
make[2]: Leaving directory 'D:/Documents/MPLABX/relocatable_code_example.X'
nbproject/Makefile-default.mk:90: recipe for target '.build-conf' failed
make[1]: Leaving directory 'D:/Documents/MPLABX/relocatable_code_example.X'
nbproject/Makefile-impl.mk:39: recipe for target '.build-impl' failed
make[2]: *** [dist/default/production/relocatable_code_example.X.production.hex] Error 1
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2
BUILD FAILED (exit value 2, total time: 1s)
What am I doing wrong and how can I build a relocatable assembler program in MPLABX? In addition, how can I make a assebly library later, when I have a lot of object files?
Here is the code:
MAIN PROGRAM
Code:
; ***********************************************************
;
; file: blinking_led.asm
; target: PIC12f675
; author: David Henry
; licence: This program is licensed under the terms of the
; MIT licence. You can get a copy of it at:
; http://www.opensource.org/licenses/mit-license.php
;
; This program makes blinking alternatively two LEDs (D0
; and D1).
;
; ***********************************************************
; use PIC 12F675
list p=12f675
#include <p12f675.inc>
; set configuration word.
__CONFIG _CPD_OFF & _CP_OFF & _BODEN_OFF & _MCLRE_OFF & _WDT_OFF & _PWRTE_ON & _INTRC_OSC_NOCLKOUT
extern count1,count2,wait
UDATA
temp res 1
reset CODE 0x0
goto main
CODE
main
; -------------------------------------------------------
; program's main entry point.
; -------------------------------------------------------
; init wait counters
movlw 0xff
banksel count1
movwf count1
banksel count2
movwf count2
banksel GPIO
clrf GPIO
banksel CMCON
movlw 0x7
movwf CMCON
; init GPIO
banksel ANSEL ; enter bank 1
clrf ANSEL
banksel TRISIO
movlw B'11001110'
movwf TRISIO ; configure I/O
banksel temp ; enter bank 0
movlw B'00010000' ; setup GPIO's output mask
movwf temp ; save it to temp
loop
; -------------------------------------------------------
; program's main loop.
; -------------------------------------------------------
movf temp,w ; load GPIO's output mask
movwf GPIO
xorlw B'00110000' ; light on alternatively LEDs #0 and #1
movwf temp ; save the modified mask
pagesel wait
call wait ; burn some cycles before switching LEDs
goto loop ; repeat forever
end
DELAY PROGRAM
Code:
list p=12f675
#include <p12f675.inc>
UDATA
count1 res 1
count2 res 1
GLOBAL count1,count2
CODE
wait
GLOBAL wait
; -------------------------------------------------------
; wait function. perform a little tempo.
; -------------------------------------------------------
nop ; consume one cycle
banksel count1
decfsz count1,f ; decrement first counter
goto wait ; until reaching zero
movlw 0xff ; reload first counter
banksel count1
movwf count1
banksel count2
decfsz count2,f ; decrement second counter
goto wait ; until reaching zero
movlw 0xff ; reload second counter
banksel count2
movwf count2
retlw 0
end
Thank you for your help.