• AVR Freaks

AnsweredHot!Place block of code at specific address

Author
upand_at_them
Super Member
  • Total Posts : 585
  • Reward points : 0
  • Joined: 2005/05/16 07:02:38
  • Location: Pennsylvania
  • Status: online
2020/05/23 12:31:54 (permalink)
0

Place block of code at specific address

Can I place a block of code at a specific address without causing the subsequent code to follow it?  The reason is that I want to <include> a file that contains DT's that I want at a specific address.
 
org 0x1F00
string1: dt "string1\0"
string2: dt "string2\0"
string3: dt "string3\0"
 
Func2 ; I want this to follow whatever code was before the string stuff
 nop
 return

post edited by upand_at_them - 2020/05/23 12:35:09
#1
du00000001
Just Some Member
  • Total Posts : 3850
  • Reward points : 0
  • Joined: 2016/05/03 13:52:42
  • Location: Germany
  • Status: offline
Re: Place block of code at specific address 2020/05/23 14:57:00 (permalink)
0
Once you understand that the block of DTs is not code (but const/data), you might find a way.
(I'm not using assembly, but know about the basic concepts of allocation/linkage.)
  • Make the DT block a const/data section (whatever precise definition applies - there should be some directive to achieve this).
  • Now make the following code a code section.
  • There should even some linker directive to locate ome named section at some absolute address. Although I assume that the "ORG directive solution" might be somewhat easier for you to use.

PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
#2
ric
Super Member
  • Total Posts : 28006
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: online
Re: Place block of code at specific address 2020/05/23 14:57:35 (permalink)
0
Not in absolute mode. You will have to include it AFTER the other stuff if you want it at the end.
The only way to avoid that is to finish it with an ORG to set the address pointer back to where you want, but it has to be a constant value known at assemble time.
 
Can be done easily in relocatable mode.

I also post at: PicForum
Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
NEW USERS: Posting images, links and code - workaround for restrictions.
To get a useful answer, always state which PIC you are using!
#3
upand_at_them
Super Member
  • Total Posts : 585
  • Reward points : 0
  • Joined: 2005/05/16 07:02:38
  • Location: Pennsylvania
  • Status: online
Re: Place block of code at specific address 2020/05/23 15:08:53 (permalink)
0
Is relocatable mode the way to go?  I've never used it.
#4
du00000001
Just Some Member
  • Total Posts : 3850
  • Reward points : 0
  • Joined: 2016/05/03 13:52:42
  • Location: Germany
  • Status: offline
Re: Place block of code at specific address 2020/05/23 15:13:06 (permalink)
0
relocatable is the way.

PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
#5
ric
Super Member
  • Total Posts : 28006
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: online
Re: Place block of code at specific address 2020/05/23 15:13:37 (permalink)
0
upand_at_them
Is relocatable mode the way to go?  I've never used it.

Maybe, or it may cause you more problems.
I don't understand why you can't just include your file of DTs after all your code.
 

I also post at: PicForum
Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
NEW USERS: Posting images, links and code - workaround for restrictions.
To get a useful answer, always state which PIC you are using!
#6
upand_at_them
Super Member
  • Total Posts : 585
  • Reward points : 0
  • Joined: 2005/05/16 07:02:38
  • Location: Pennsylvania
  • Status: online
Re: Place block of code at specific address 2020/05/23 15:34:54 (permalink)
0
I could do that, but currently that file has other code in addition to the DTs.  Since the code and those DTs went together I was expecting to keep them in the same file, instead of having yet another file to manage.
#7
ric
Super Member
  • Total Posts : 28006
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: online
Re: Place block of code at specific address 2020/05/23 15:44:05 (permalink)
0
upand_at_them
I could do that, but currently that file has other code in addition to the DTs.

You left that detail out of your first post,

Since the code and those DTs went together I was expecting to keep them in the same file, instead of having yet another file to manage.

Sounds like you'll have to learn how to use relocatable mode then.
Have you read the MPASM User Guide that comes with MPLABX?
You haven't mentioned which PIC you are using. There are example template files for some (but not all) PICs in the MPASMX folders.

I also post at: PicForum
Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
NEW USERS: Posting images, links and code - workaround for restrictions.
To get a useful answer, always state which PIC you are using!
#8
upand_at_them
Super Member
  • Total Posts : 585
  • Reward points : 0
  • Joined: 2005/05/16 07:02:38
  • Location: Pennsylvania
  • Status: online
Re: Place block of code at specific address 2020/05/23 17:04:35 (permalink)
0
I only have MPLAB 8.86, and I think MPLABX won't install on my WinXp machine.  I actually don't even use MPLAB, just the few times I need to debug, but almost all of my debugging is done in code.  I edit in UltraEdit and compile with MPASM command line.  Chip is 16F1825/9.  I'm reading the User's Guide now.
 
#9
ric
Super Member
  • Total Posts : 28006
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: online
Re: Place block of code at specific address 2020/05/23 17:14:54 (permalink) ☄ Helpfulby upand_at_them 2020/05/24 08:44:31
0
Nearest template to that device will be
C:\Program Files (x86)\Microchip\MPASM Suite\Template\Object\16F1827TMPO.ASM
 

I also post at: PicForum
Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
NEW USERS: Posting images, links and code - workaround for restrictions.
To get a useful answer, always state which PIC you are using!
#10
upand_at_them
Super Member
  • Total Posts : 585
  • Reward points : 0
  • Joined: 2005/05/16 07:02:38
  • Location: Pennsylvania
  • Status: online
Re: Place block of code at specific address 2020/05/23 17:22:56 (permalink)
0
Thanks, I'll check it out.
#11
1and0
Access is Denied
  • Total Posts : 10999
  • Reward points : 0
  • Joined: 2007/05/06 12:03:20
  • Location: Harry's Gray Matter
  • Status: offline
Re: Place block of code at specific address 2020/05/23 18:00:32 (permalink) ☼ Best Answerby upand_at_them 2020/05/24 08:44:20
0
upand_at_them
Can I place a block of code at a specific address without causing the subsequent code to follow it?  The reason is that I want to <include> a file that contains DT's that I want at a specific address.
 
org 0x1F00
string1: dt "string1\0"
string2: dt "string2\0"
string3: dt "string3\0"
 
Func2 ; I want this to follow whatever code was before the string stuff
 nop
 return


 
It IS easy in absolute mode. ;)
NEXTORG set     $
 
        org     0x1F00
string1: dt "string1\0"
string2: dt "string2\0"
string3: dt "string3\0"
 
        org     NEXTORG
Func2   ; I want this to follow whatever code was before the string stuff
        nop
        return

#12
1and0
Access is Denied
  • Total Posts : 10999
  • Reward points : 0
  • Joined: 2007/05/06 12:03:20
  • Location: Harry's Gray Matter
  • Status: offline
Re: Place block of code at specific address 2020/05/23 18:02:18 (permalink)
0
du00000001
Once you understand that the block of DTs is not code (but const/data), 

The directive DT creates a string of RETLW instructions.
 
#13
ric
Super Member
  • Total Posts : 28006
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: online
Re: Place block of code at specific address 2020/05/23 18:03:24 (permalink)
0
Thanks Harry. That was my first thought, but wasn't sure if you could save the value of the current address pointer.
Years since I've bothered doing a full project in assembler.
 

I also post at: PicForum
Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
NEW USERS: Posting images, links and code - workaround for restrictions.
To get a useful answer, always state which PIC you are using!
#14
upand_at_them
Super Member
  • Total Posts : 585
  • Reward points : 0
  • Joined: 2005/05/16 07:02:38
  • Location: Pennsylvania
  • Status: online
Re: Place block of code at specific address 2020/05/23 18:10:37 (permalink)
0
1and0 It IS easy in absolute mode. ;)
NEXTORG set     $
 
        org     0x1F00
string1: dt "string1\0"
string2: dt "string2\0"
string3: dt "string3\0"
 
        org     NEXTORG
Func2   ; I want this to follow whatever code was before the string stuff
        nop
        return






Excellent!
#15
upand_at_them
Super Member
  • Total Posts : 585
  • Reward points : 0
  • Joined: 2005/05/16 07:02:38
  • Location: Pennsylvania
  • Status: online
Re: Place block of code at specific address 2020/05/23 18:12:24 (permalink)
0
ricYears since I've bothered doing a full project in assembler.

 
I'm starting to regret it myself.
 
#16
1and0
Access is Denied
  • Total Posts : 10999
  • Reward points : 0
  • Joined: 2007/05/06 12:03:20
  • Location: Harry's Gray Matter
  • Status: offline
Re: Place block of code at specific address 2020/05/23 18:19:24 (permalink)
0
upand_at_them
I'm starting to regret it myself.

Don't be. You will gain a better appreciation and understanding of the language and able to write efficient code and debug better if and when you go to a higher language.
#17
Jump to:
© 2020 APG vNext Commercial Version 4.5