Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
03/02/04 17:01
Read: times


 
#65822 - RE: How does ORG command work?
Responding to: ???'s previous message
ORG simply tells the assembler where to start putting the assembled code.

Well, I wish it were that simple, but it's not. From the Keil A51 Manual...

"When an ORG statement is encountered, the assembler calculates the value of the expression and changes the location counter for the current segment. If the ORG statement occurs in an absolute segment, the location counter is assigned the absolute address value. If the ORG statement occurs in a relocatable segment, the location counter is assigned the offset of the specified expression.

The ORG directive changes the location counter but does not produce a new segment. A possible address gap may be introduced in the segment. With absolute segments, the location counter may not reference an address prior to the base address of the segment."

Note that the ORG statement DOES NOT specify a physical address if used in a relocatable segment. Instead, it specifies an OFFSET from the beginning of where that segment is located.

Additionally, on most assemblers, if you create an absolute segment that starts at 0 (with CSEG at 0) and then use an ORG 0x8000 statement, the location counter changes to 0x8000. However, all that space from 0x0000 to 0x7FFF must be filled with something. And, it is. For example, the following program:

cseg at 0
org 0x8000
nop
end

is 32,769 bytes long. However, the following program:

cseg at 0x8000
nop
end

is only 1 byte long.

Be careful using ORG.

Jon

List of 13 messages in thread
TopicAuthorDate
How does ORG command work?            01/01/70 00:00      
   RE: How does ORG command work?            01/01/70 00:00      
   RE: didnt work            01/01/70 00:00      
   RE: How does ORG command work?            01/01/70 00:00      
      You mean uPSD3234A?            01/01/70 00:00      
         RE: You mean uPSD3234A?            01/01/70 00:00      
   RE: How does ORG command work?            01/01/70 00:00      
      RE: How does ORG command work?            01/01/70 00:00      
      RE: How does ORG command work?            01/01/70 00:00      
         RE: How does ORG command work?            01/01/70 00:00      
            RE: The beloved Keil C51/A51            01/01/70 00:00      
               RE: The beloved Keil C51/A51            01/01/70 00:00      
                  RE: The beloved Keil C51/A51            01/01/70 00:00      

Back to Subject List