View unanswered posts | View active topics It is currently Mon Sep 23, 2019 1:06 am



Reply to topic  [ 4 posts ] 
 Is the ORG directive a must? 
Author Message

Joined: Sat Jun 16, 2018 2:51 am
Posts: 41
In a system where data and program memory are separate, is the ORG assembler directive needed? It seems using labels would work just fine... For example in program memory all the instructions can be packed together (as there is no need to reserve space for data) and labels can be used to jump between code blocks.

Are there other use cases for ORG apart from memory reservation that I am missing. Maybe special kernel uses?

Thanks for any insight!


Wed Jan 23, 2019 9:44 pm
Profile

Joined: Sat Feb 02, 2013 9:40 am
Posts: 920
Location: Canada
In my opinion it's pretty much a must-have except for trivially simple programs. The assembler or program loader would have to make a ton of assumptions without org directives.

The ORG directive is used to place things at specific memory addresses. For instance, a .com program needs to be placed at address $0100. If software is going to be located in ROM then an ORG directive may be required. The org directive usually works independently for different program segments (code, data, bss, stack, tls, rodata, etc). An org directive can usually be omitted but then a value of zero is assumed for the appropriate counter. You are correct in your case if there are separate code and data areas and code and data are identified separately in software it may be possible to omit the org directive. Note that it’s sometimes desirable to place code in the data area, or data in the core area. Most assemblers expect the programmer to identify the area output to.
Usually there is a way to identify which program segment is being output to with additional directives: (code, data).
The org statement can be useful in data areas for identifying I/O locations. For instance, a video buffer may be identified with an org directive. org directives are also often used to identify vector areas which may be required to be at specific memory locations.
The following example shows the program segment being selected (bss, data or code) followed by an org directive for that segment.
Code:
         bss
         org      SCRATCHPAD      ; SCRATCHPAD = $FF400000
_inptr            dw      0
_bsptr            dw      0      ; BASIC storage pointer
         org      SCRATCHPAD + $AFF8
__brk_stack      dw      0

      data
      org      SYSDATA         ; SYSDATA = $FFD10000
      code   18 bits
      org      ROMBASE         ; start of ROM memory space

Sometimes the org directive has to be used carefully because the assembler wants to see the orgs increasing in address range. This depends on the assembler. Some better assemblers can re-arrange the code and data automatically so that its in order according to the org statements.


Another use for org is to align code in a assembler that doesn't support the align directive. It might be use to origin code at memory page boundaries or on cache lines for instance.

_________________
Robert Finch http://www.finitron.ca


Thu Jan 24, 2019 1:22 am
Profile WWW

Joined: Tue Dec 11, 2012 8:03 am
Posts: 267
Location: California
I see Rob posted while I was writing. I'll post this anyway.

You usually need to tell the assembler where to start laying down machine code. If it has a default that suits you ok, then I suppose the ORG directive would not be necessary to start.

I use the ORG a ton inside my program flow-control macros for nestable structures in assembly language without labels. I have an article on this at http://wilsonminesco.com/StructureMacros/, and longer examples starting about 60% of the way down the page at http://wilsonminesco.com/multitask/index.html, and more explanation of how the insides work at http://wilsonminesco.com/stacks/pgmstruc.html . A .lst (list) file output after the assembler runs would show hundreds of ORG occurrences if you have macro expansion turned on.

_________________
http://WilsonMinesCo.com/ lots of 6502 resources


Thu Jan 24, 2019 1:29 am
Profile WWW

Joined: Sat Jun 16, 2018 2:51 am
Posts: 41
Ah, I see. Thank you!


Thu Jan 24, 2019 2:05 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 4 posts ] 

Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group
Designed by ST Software