Shop OBEX P1 Docs P2 Docs Learn Events
ORG, RES and constants in asm — Parallax Forums

ORG, RES and constants in asm

Jasper_MJasper_M Posts: 222
edited 2007-01-09 20:29 in Propeller 1
1) ORGs and RESs: It seems that org only sets program counter, and doesn't relocate data following it. What's the purpose of this? I'd have used it to insert empty space at the top of my program but I had to add long 0,0,0,0,0,0,0,... RES directive seems to just modify PC also. So: What to do? What's the purpose of ORG and RES if not relocating stuff? Will there be some directives to support relocation in future?

2) Assembly constants: Is there any way of defining a constant in assembly language? Putting them in CON section won't work because what I wanna do is to use constants that have assembly labels in them, eg. data_begin+45 ... I don't want to put them as register contents either because I don't want to waste my valuable RAM... And also, data_begin is followed by my initialization code (that'll be wiped out when I write data over it) so I can't use RES directive. It's not fun to search the whole file for #data_begin+ something always when I want to expand some portion of data (it's divided into sections of different lengths for different stuffs). So what to do? And if there are no assembly constant directives will there be someday?

Thank you in advance. ^_^

EDIT: Removed the "Why they have identical behavior (or am I mistaken)?" question after realizing that RES is relative and ORG absolute.

Post Edited (Jasper_M) : 1/9/2007 12:10:47 PM GMT

Comments

  • Ym2413aYm2413a Posts: 630
    edited 2007-01-09 15:10
    ORG is used to reset the PC (Program Counter) offset of your ASM code to zero.
    This is important because when a COG loads your ASM code. It's pulled from the HUB-RAM into the COG's RAM.

    Cog's don't directly execute ASM code from the 32k RAM, but instead execute it from a small 2k RAM (32x512) on the cog running it.

    ORG resets the (Program Counter) so the ASM code is compiled with the correct addressing for the 2k COG-RAM.

    EDIT: I'm not sure if this is the answer your looking for or if its something else more complex.

    Post Edited (Ym2413a) : 1/9/2007 3:25:27 PM GMT
  • Jasper_MJasper_M Posts: 222
    edited 2007-01-09 16:03
    Yes, I know about the cog and shared RAM. So ORG is meant to be used when ASM is preceded by data or another ASM block that's supposed to run on a different cog. So the ORG statement definitely has a purpose. But I don't see any use for ORG statements with a numeric parameter that set PC to a different value without relocating code. So there's no way to reposition code except by stuffing the gap with some longs... Will there be in some version?

    And Ym2413a, that was a partial answer, thank you for that ^__^ It didn't help me right now, but it's gonna save a lot of trouble when I'm gonna put 2 ASM programs in same spin file one day. Ie. thank you. ^.^
  • Mike GreenMike Green Posts: 23,101
    edited 2007-01-09 16:18
    ORG with a numeric parameter is used when an assembly routine relocates part of itself to a different part of RAM. Some of the video drivers do this so that a line buffer can be placed at location zero of the cog's memory.
  • Jasper_MJasper_M Posts: 222
    edited 2007-01-09 16:30
    Mike Green said...
    ORG with a numeric parameter is used when an assembly routine relocates part of itself to a different part of RAM. Some of the video drivers do this so that a line buffer can be placed at location zero of the cog's memory.

    Yes. I would use it to reposition my video driver code after a palette. But it won't work. The code after org is really at memory location #1 even though it's preceded by "jmp #Initialize" and "org 128". The PC is reset to 128 anyway. So I did this: "jmp #initialize" and add 127 longs after that. I think it'd be nice if there was a way to do this in a "cleaner" way.
  • Mike GreenMike Green Posts: 23,101
    edited 2007-01-09 16:38
    The ORG 128 is behaving as it is supposed to work. The code following it is assembled as if it appeared starting at location 128. It is the responsibility of the initialization code (at location zero) to copy the information to its proper location (as the other programs that use this technique do). The reason for not doing the automatic LONGs is that, this way, the code in HUB memory doesn't "waste" the zero locations. Remember, the whole assembly routine occupies HUB memory space. In your case, there would be 127 longs of HUB memory that can't realistically be used for anything else. A routine to copy cog to cog only takes 3 instructions and two data words if it's to be executed only once.
  • Jasper_MJasper_M Posts: 222
    edited 2007-01-09 16:46
    Mike Green said...
    The ORG 128 is behaving as it is supposed to work. The code following it is assembled as if it appeared starting at location 128. It is the responsibility of the initialization code (at location zero) to copy the information to its proper location (as the other programs that use this technique do). The reason for not doing the automatic LONGs is that, this way, the code in HUB memory doesn't "waste" the zero locations. Remember, the whole assembly routine occupies HUB memory space. In your case, there would be 127 longs of HUB memory that can't realistically be used for anything else. A routine to copy cog to cog only takes 3 instructions and two data words if it's to be executed only once.

    So I can decrease the binary size be replacing the zeroes by copying code. Ok, now I got it. Thank you very much ^^
  • Jasper_MJasper_M Posts: 222
    edited 2007-01-09 20:29
    Okay, new question.

    I'm trying to put an assembly label as a parameter in ORG statement. However, the value that gets as the parameter is not a cog address but an obj address. So they have an offset and are 4 times larger numbers than they should. Does this serve any purpose, or is it a bug or am I just not supposed to do that?
Sign In or Register to comment.