I've been searching through the entire manuals and I can't find a single mention of the Instruction Pointer. I need this for a SPU program that I'm writing. Maybe it has a different name? Can anyone tell me how I can access the address of the instruction that is to be executed? Thanks in advance for your help. UPDATE: Apperantly it's called the Program Counter, but how can I access it from within my SPU Program?
-
On most architectures it's called the Program Counter (PC) - Intel's a little non-conformist in its nomenclature in this regard. – Paul R Sep 21 '12 at 07:04
-
Thanks a million! This is really embarrassing, but I've only done assembly coding on the x86. But I have another question: Is it possible to read it without the SPU being stopped? – user1294986 Sep 21 '12 at 07:14
2 Answers
If you just want to get the instruction pointer, you can do it in assembly:
brsl r<n>, .+4
This loads the address of the next instruction into register r<n>
.

- 171,345
- 36
- 312
- 383
Seems like you can get the next instruction by executing a spe_context_run
operation:
int spe_context_run(spe_context_ptr_t spe, unsigned int *entry, unsigned int runflags, void *argp, void *envp, spe_stop_info_t *stopinfo)
entry
Input: The entry point, that is, the initial value of the SPU instruction pointer, at which the SPE program should start executing. If the value of entry is SPE_DEFAULT_ENTRY, the entry point for the SPU main program is obtained from the loaded SPE image. This is usually the local store address of the initialization function crt0 (see Cell Broadband Engine Programming Handbook, Objects, Executables, and SPE Loading).
Output: The SPU instruction pointer at the moment the SPU stopped execution, that is, the local store address of the next instruction that would be have been executed.
This parameter can be used, for example, to allow the SPE program to "pause" and request some action from the PPE thread, for example, performing an I/O operation. After this PPE-side action has been completed, you can continue the SPE program calling spe_context_run again without changing entry.
-
Thanks for your answer, but I would like to do this on the SPU, whereas spe_context_run runs a context and is on the PPU. – user1294986 Sep 21 '12 at 07:26
-
Ah, so you are *running* an SPU program, and want to get the instruction pointer? Please update your question and mention it. – nneonneo Sep 21 '12 at 07:35
-
Yes. Sorry for not being clear on that. Is there a way? From what I read from the instructions the SPU has to be disabled in order to read the SPU_NPC, but I would like to read it within my SPU Program. – user1294986 Sep 21 '12 at 07:39