For what are registers used in CodeVision

Go To Last Post
6 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm searching after this info everywhere, but nowhere is it described in such detail that I would like know. If you know about something I would be very thankful for the link. The Atmel Assembler document it's just describing the ASM and Registers at all, but not usage behaviour of CodeVision.

Now I have one C code with ASM ISR and I would like to know what are really restrictions and for what is CodeVision using the registers when it's making the asm from the C.

As I see on page 15 in:
http://courses.cit.cornell.edu/e...

"do not use r0 - r3 and r21-r31 -> any other registers are OK"

Now I understand that I could use all of them but I need them to push and pop them later. Just the r4-r20 can be used without worrying that are used somewhere in the C code before the asm? For example main loop and everything is in CodeVision C and irq is in ASM, can I use R4-R20 without storing the previous values in the stack? And the rest can be used when I will back up them back before leaving (perhaps storing the R29,R28 of the Y reg in different reg, because if will mess with the Yreg I will change address of the push stack)

But what he stores I the r0-r3? Bit variables? I think the default setting is for 16bit so why it's r0-r3, not r0-r1.

So when I will set the bitvariables to max (104=13bytes) and if I won't use any bitvariable I will restrict the C code using the register, which ones? R0-R12?

The registers R26-R31 are for X Y Z. Ok and what he is doing with r21-r25, or that's the working space for the c code?

And whay it's using ST -Y,Rr instead of PUSH. I thought it will use PUSH to store the thing in different stack, but it doesn't use PUSH at all. For example instead of doing inc Rr it's doing SubI Rr,-1 (it's the same result just the SUBI will fill SREG and that can be much faster when used for jumps). But I would like to know the detailed reasons why it's dealing with registers like it's doing now.

The registers R0-R15 can't be used with some instructions like LDI etc... but all of them can be used with bit access SBRC etc...?

And the last:
Can be PC changed somehow different without using jumps and skips instructions etc...

The point why I'm asking so many perhaps stupid questions is that because in CodeVision is no help explaining how it's using the registers and why it's using exactly them. When I will be done to project should be completely in ASM, but before that will keep in ASM just ISR and I need veeeeeeeeery badly as many registers as I could get without worrying that I will mess with the C code (I could use all 32 registers if I could :) ) And with ones I could alter after backuping, or I could alter without backuping but it could have some consenquences (if you know which ones). It's all because speed in some I have buffers, in some I have preloaded variables, because I can't do LDI R10,0xff with R10, but I could do LDI R16,0xff MOV R10,R16 but it takes more cycles, the fastest way is MOV R10,R-global_static_register_with_stored_0xff.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

By the time you wrote all that, you could have read the official CodeVision documentation.

You realise that you get a full .ASM listing and you can study just how CV generates code.

You are obviously familiar with the idea of PUSH/POP CALL/RET and other methods of manipulating the stack.

If you so desire, you can push or save every register, do your business and restore afterwards.

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

See the CodeVision Help under Compiler Operation and RAM Memory Organization and Register Allocation.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

usage behaviour of CodeVision.

Each compiler will have its own model of code generation. Regular readers will know that I am a fan of the CodeVision model for several reasons: Liberal allowance for global register variables; register-based "bit" variables; local register variables in high registers; and virtually all registers available when in #asm.

First, look in the manual/Help for the current "rules". E.g.

Quote:
Including Assembly Language in Your Program
...
The registers R0, R1, R22, R23, R24, R25, R26, R27, R30 and R31 can be freely used in assembly routines.
However when using them in an interrupt service routine the programmer must save, respectively restore, them on entry, respectively on exit, of this routine.
and
Quote:
Allocation of Variables to Registers
In order to fully take advantage of the AVR architecture and instruction set, the compiler allocates some of the program variables to chip registers.
The registers from R2 up to R14 can be allocated for global bit variables.
The register R15 can be allocated to local bit variables.

You may specify how many registers in the R2 to R14 range are allocated ...


You must have missed those sections.

Given the above (direct control over nearly half of the AVR registers for global register variable) along with CV's "smart ISR" register saving, IME >>there is rarely a need to #asm in ISRs just for speed.<< Admittedly there may be some operations where ASM would have an advantage if the algorithm needs stuff not in C--rotate; arithmetic other than 8/16/32 bit; carry.

For an extreme example using nearly all of the global register variables for a critical ISR, and nearly no register saving (and that could also be avoided--see the discussion) look for REG_PARTIAL in this thread:
https://www.avrfreaks.net/index.p...

Please digest the above information first, and maybe play with a couple of example programs and ISRs, examining the .LST files. I'll be happy to address any particulars, but many of your questions above are n/a once the code generation model is grasped.

Short answer:
R0-R1 -- MUL results and LPM on some AVR models. Compiler working otherwise.
R2-R14 -- global register variables, "bit" and otherwise
R16-R21 -- local register variables.
R22-R31-- compiler working registers. In #asm only R28-R29 (Y, the data stack pointer) is "hands-off" but even that could be saved and restored if really needed.

AFAIK no other compiler brand's code generation model has as liberal a register usage policy, and AFAIK you couldn't do my 100% C ISR in the link with any other brand (and have it be as tight).

Lee

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

david.prentice wrote:
By the time you wrote all that, you could have read the official CodeVision documentation.

I think the problem was I had the documentation opened too long (2 months) and started to miss the things, I was reading before and after, just not on the right place :)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

theusch wrote:
Quote:

usage behaviour of CodeVision.

Please digest the above information first, and maybe play with a couple of example programs and ISRs, examining the .LST files. I'll be happy to address any particulars, but many of your questions above are n/a once the code generation model is grasped.

Thank you for yours extensive answer, now I found the correct pages in manual (you can't imagine how long I was desperate to find them in manual :) )

Now I have something to digest, thanks. I will print them, read them before sleep to have beautiful and fulfilling dreams :) (why it's sounds so sick when I just described my feelings)