## Multiple source files

11 posts / 0 new
Author
Message

Greetings all!!

I am working on several big projects. Both profesionally and personally. I have several routines that I usually cut and paste out of working code into what I am currently working on. what i would like to do is just add a '.include' where i need the code. I tried a simple experiment and it worked. what I want to know is if this is kosher?

What I would do is create a bunch of .asm modules(spi_module, USART_module, etc.) out of pieces of working code as generics and then keep them in a library folder.

Seems like it should work based on my experiments of having several source files in my project, and adding the .include where I need them

Any thoughts?

Jim

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

"The critical shortage here is not stuff, but time." - Johan Ekdahl

"Step N is required before you can do step N+1!" - ka7ehk

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

Keep in mind that the assembler is simply inserting the code from the included file at the point of the .include statement. So it is in effect treating it as one long file. Because of this, the order that you include files might make a difference.

Regards,
Steve A.

The Board helps those that help themselves.

Yes, I do understand that. My experiments showed that you cannot merely insert it anywhere you please. I also noticed that where I place my .equ statements is critical as well.

If that is all I have to do in order to not have to keep track of solid code to use elsewhere then it is a small price to pay

Jim

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

"The critical shortage here is not stuff, but time." - Johan Ekdahl

"Step N is required before you can do step N+1!" - ka7ehk

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

Bits of one of my projects:

.nolist
.include	"m88def.inc"
.include	"c:\avr\lib\ASCII_table.asm"
.list

.include	"c:\avr\projects\dis25100\dis25100_equ.asm"
.include	"c:\avr\projects\dis25100\dis25100_ram.asm"
.include	"c:\avr\lib\int_v_m88.asm"

RESET:
;Disable Global Interrupt
cli
;Set up stack pointer
ldi		temp,high(ramend)
out		sph,temp
ldi		temp,low(ramend)
out		spl,temp
rcall	init

The above is needed at the start of the main file, at the end of the main file I add other library or other files, I don't find the order to make any difference. Defines however need to be included before you need them.

;Include files area
.include	"c:\avr\projects\dis25100\dis25100_init.asm"
.include	"c:\avr\lib\rs485com_mega88.asm"
.include	"c:\avr\lib\h2d_d2h8.asm"
.include	"c:\avr\lib\6x6_5x8_dis25100.asm"
.include	"c:\avr\projects\dis25100\dis25100_mon.asm"
.include	"c:\avr\lib\cgn5x7_1252_ex1.asm"
.include	"c:\avr\lib\sw_timers.asm"
.include	"c:\avr\projects\dis25100\int_s_dis25100.asm"
.include 	"c:\avr\lib\TWI_master_m48_m88_m168.asm"
.include 	"c:\avr\lib\DS1307_driver.asm"
.include 	"c:\avr\lib\TSL2561_driver.asm"
.include 	"c:\avr\lib\luxmeter_calcs.asm"


John Samperi

Ampertronics Pty. Ltd.

https://www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

Ok, work with me here since I have always done a one-source code file untill now

I tried to put the .includes all in the same spot, but the code did not do what I wanted at all. so, what I did was place the .include in the subroutine where I would have either re-typed, or cut and pasted. That worked.

Jim

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

"The critical shortage here is not stuff, but time." - Johan Ekdahl

"Step N is required before you can do step N+1!" - ka7ehk

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

Quote:
place the .include in the subroutine where I would have either re-typed, or cut and pasted. That worked.
Then I would be looking at the rest of the code calling it :) or how your subroutine is written. For instance the routine rs485com_mega88.asm has RS485 driver code plus all the USART init, I can just include it into my project without looking at it and know it will work regardless of where it is located. One IMPORTANT thing to remember is that the first non comment line MUST have the type of memory it resides it ie all program code must have a .cseg all ram area must have a .dseg all eeprom area must have a .eseg otherwise you will confuse the assembler as it MAY try to put a ram variable in eeprom or flash. You can have more than 1 type of memory definition in your include file of course.
This is the 1st bit of the dis25100_ram.asm file

;====================
.DSEG
;====================

ramstart:

EEP_ADDR:			.byte	2	;Pointer to data in eeprom internal or external
scroll_time:		.byte	1	;Gets copied to scroll_delay every scan

A bit of the dis25100_init.asm file:

;DIS25100 program initialisation

.CSEG

init:
ldi		temp,1<<MISO|1<<input				;Enable pull ups on MISO and ICP
out		portb,temp							

A bit of the ds25100.asm file, this is at the end of the file where I put all my eeprom data, of course at the top of this file I have a .cseg.

;====================
.ESEG
;====================

;EEPROM Area

nothing:		;Don't use first location
.db	0

.db	0x1a

Have I confused you enough?? :lol:

John Samperi

Ampertronics Pty. Ltd.

https://www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

:D No not really, where things are funky is that I wrote several source files. I modularized things like putting the uart stuff in one file, my timer stuff in another. The reason for this is twofold. I wanted to make my life a little easier and I am teaching a kid programming and I though it might be easier for her to see what happens with everything broken down.

The only way I was able to get the multiple .asm files to load was to do a .include. Then I have two large tree branches, one for source code, and another for includes. If that is the way avrstidio wants it then so be it

Jim

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

"The critical shortage here is not stuff, but time." - Johan Ekdahl

"Step N is required before you can do step N+1!" - ka7ehk

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

Quote:
I wanted to make my life a little easier
Macros do that for you, may be a little early for your student though. SOMEONE should really write that tutorial about the use of include files and multifile projects in assembler :)

Quote:
I modularized things like putting the uart stuff in one file
Been doing that for a long time, another trick is to copy ALL interupt vectors from the data sheet of the chips you use and turn that into an include file, then supply another include file for the interrupt service routines, the standard version does nothing but do a RETI, you then copy this file to your project if you need to use interrupts and give it a personalised name that has relation to the project. Your real service routine go there. This makes up a good framework. You can see this from the above snippets.

.include   "c:\avr\lib\int_v_m88.asm" ;Interrupt vectors
then down the file
.include   "c:\avr\projects\dis25100\int_s_dis25100.asm" ;Service routines for the project.

John Samperi

Ampertronics Pty. Ltd.

https://www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

Of course a radical way to "modularise" things would be to switch to using the avr-as assembler form GCC (WinAVR) in which case each source module IS assembled in complete isolation and you can even then collect a few such .o files together into a .a library and just link your applications against it and the linker will only pull out those .o files that are used. Once you had a fully debugged uart.o (for example) there'd actually never be a need to re-assemble it again and you could still be using the one you assembled today in three years time. (this is all possible as GCC generates relocatable code and the linker is a relocating linker)

(but while the mnemonics are identical it'd be a lot of work to fix up all the directives and macros etc.)

Last Edited: Fri. Jul 20, 2007 - 12:21 PM

Good points by all!!

I think I have enough here to work on. Since this is an experiment and not the project I am working on a paid level I am going to put it on the back burner for now

Thanks all

Jim

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

"The critical shortage here is not stuff, but time." - Johan Ekdahl

"Step N is required before you can do step N+1!" - ka7ehk

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

My "student" has been reading the replies, and has informed me two thngs...

One, This site rocks. There is so much to learn from people who do this all the time

Second, a guy designed the software to do the programming. If a woman had done it it would have been done right from the start :shock:

Good thing she is a friend of mine's kid. Wise ass

Jim

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

"The critical shortage here is not stuff, but time." - Johan Ekdahl

"Step N is required before you can do step N+1!" - ka7ehk

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown