Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Org ???

Status
Not open for further replies.

jumpjack

New Member
I'm completely confused about ORG "command", or "directive", or as you call it.
What is it for?
How many times it's needed in a source?
How does it differ among pic 16f84 and 16f628?

For example, what does such a program mean??

Code:
	org	0x0000
	goto	INIT
	NOP
	NOP
	NOP
	NOP
	org	0x0005
INIT	MOVLW	H'07'
	MOVWF	CMCON
	CLRF	PORTA
	CLRF	PORTB
	BSF	STATUS,RP0	;Select Bank 1
	CLRF	TRISA	;Port A is output
	CLRF	TRISB	;Port B is output
	BCF	STATUS,RP0	;Select Bank 0

If 0x0000 is address of first executed statement, why do I need a GOTO after it, and why is it used ORG 0x0005 after?!?
 
I'm completely confused about ORG "command", or "directive", or as you call it.
What is it for?
How many times it's needed in a source?
How does it differ among pic 16f84 and 16f628?

For example, what does such a program mean??

Code:
	org	0x0000
	goto	INIT
	NOP
	NOP
	NOP
	NOP
	org	0x0005
INIT	MOVLW	H'07'
	MOVWF	CMCON
	CLRF	PORTA
	CLRF	PORTB
	BSF	STATUS,RP0	;Select Bank 1
	CLRF	TRISA	;Port A is output
	CLRF	TRISB	;Port B is output
	BCF	STATUS,RP0	;Select Bank 0

If 0x0000 is address of first executed statement, why do I need a GOTO after it, and why is it used ORG 0x0005 after?!?

The goto is to jump over the interrupt vector, it's standard practice - in this case there's no need for the ORG 0x0005 as the NOP's already place the code at the correct address - so you could either delete the ORG, or delete the NOP's, but it's not detrimental in any way.

All ORG (ORiGin) does is set the current address, you need one at the start of the program, and may need others later on if you need to specify a particular address - most comon use is to set a table on a 256 byte boundary, or set the data EEPROM address.
 
The goto is to jump over the interrupt vector, it's standard practice - in this case there's no need for the ORG 0x0005 as the NOP's already place the code at the correct address - so you could either delete the ORG, or delete the NOP's, but it's not detrimental in any way.

All ORG (ORiGin) does is set the current address, you need one at the start of the program, and may need others later on if you need to specify a particular address - most comon use is to set a table on a 256 byte boundary, or set the data EEPROM address.

current address of WHAT?!?
I see it's also used to reserve space in RAM to define variables...
Why org 0x00, org 0x20, org 0x0c in different situations/processors?
 
current address of WHAT?!?
I see it's also used to reserve space in RAM to define variables...
Why org 0x00, org 0x20, org 0x0c in different situations/processors?

The address of the program counter - most (all?) modern PIC's have their reset vector at 0x0000 so the program needs to be assembled at that address.
 
current address of WHAT?!?
I see it's also used to reserve space in RAM to define variables...
Why org 0x00, org 0x20, org 0x0c in different situations/processors?
When you run the assembler it generates machine code from your source.
Where does the machine code get placed in memory?
The ORG command tells the assembler where to place the next instruction (machine code). Additional instructions are place sequentialy until the assembler see another ORG.
 
I see some confusion among "program counter" and "compiler memory location" here...
3v0's answer appears to be the right answer....
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top