Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] MPLAB X error (executable code and data must be in appropriate columns)

Status
Not open for further replies.

mrinalmani

Advanced Member level 1
Joined
Oct 7, 2011
Messages
463
Helped
60
Reputation
121
Reaction score
58
Trophy points
1,318
Location
Delhi, India
Activity points
5,285
I have just installed MPLAB X but unfortunately I cannot find any example targeted for assembly language. All are intended for C

I wrote the following code and it did not work

MOVLW 25H
END

it shows an error (error 152) stating: executable code and data must be in appropriate columns

please help
 

Hi,

You need to specify which chip you are using in your code and some basic information for it to be able to Build properly; here is a simple example using a 16F877a.
You should be able to make it run with most 16F chips if you just change the 877a reference.

Let us know what chip you are working with if you cannot get it to run ok.


Edit, also see this post and entry #2 and #7 with the assembler help links
https://www.edaboard.com/threads/321043/#post1372506

Code:
		list p=16f877a
		#include  < p16f877a.inc>
		__CONFIG _CP_OFF & _WDT_OFF & _XT_OSC & _PWRTE_ON & _LVP_OFF
	
		cblock 0X20			; specify user regiaters
		d1
		d2
		d3
		endc



		org 	0x000
		GOTO	Main



Main  	CLRF	PORTB		; Set portb,c,d to digital outputs
		CLRF   	PORTC
		CLRF 	PORTD
		BANKSEL TRISA
		CLRF	TRISB
		CLRF 	TRISC
		CLRF 	TRISD
		BANKSEL 0

		
		MOVLW   25H
               
               MOVWF    d1


		END					; END OF PROGRAM CODE
 
Last edited:
Wha you are missing is the correct format of lines when you use assembly instructions.

Labels (Symbols) must start in the first position of a line.
Instructions and everything else must have at least one space at the beginning of the line or at least one space after a label.

You broke the rules by putting an instruction in the first column!

Brian.
 

Thanks! It worked, after selecting a default template containing similar initialization code mentioned above.
Is it possible to have the main code in a separate file and the processor-specific initializations in a separate one?
Thanks again...

- - - Updated - - -

@betwixt
It didnt help adding spaces or/and labels followed by spaces
 

If you used the template povided by Microchip it would have the spaces (or tabs) in the proper place already. What I told you still applies.

Yes, you can write a program in different modules, that's what the linker is there to do. Just add the different .asm files to the project and it should merge them and resolve references between them. You can even mix code written in different languages (C and asm for example) as long as their object code meets the standard. This is how library modules are incorporated into users programs.

Note that all the register names and bit names are already known to the assembler if you use it's template so you can use them freely in the program without any need to associate them with addresses.

Brian.
 
Thanks for the reply!
Another question... If there are several .ASM files in one project, how does the assembler know where to start? Is there some specific name for the starting file?
 

Hi,

Have never used linker etc as if you look on the web there is a lot of debate as to how practical it really is.

One simpler method is to write and store some of your sub-routines as 'Include' files and Call them from your main code as you would any other subroutine.
At the end of your Main code simply list these extra routines like this.


Code:
		#include "ds18b20_1.asm"
		#include "ds18b20_2.asm"
		#include "ds18b20_3.asm"
		#include "dht11.asm"

                END       ; end of  program code
 
To use multiple source files you have to (unless you are VERY careful) use 'relocatable' code. You still have to give it a starting point but it would typically be nothing more than a jump to a label somewhere in your code.

The method is not to use absolute addresses anywhere, use relocatable blocks instead which the compiler will then assign addresses to by itself. There is a good explanation in the help files but essentially you declare the variables to be 'initialized' or not and you wrap the sections of code in 'code' tags. The assembler will automatically work out which addresses are best and will arrange the sections of code so the fit in the available memory. The result may be instruction blocks in a different order to the way you wrote them but the references from one block to another will be updated so the program flow is still the same.

Brian.
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top