This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

shared variable slots

The feature of shared variables in C is a wonderful saver of DATA space. Can the same be implemented in assembler ?

Erik

Parents
  • Hi Erik!

    Well, I think, you just have to use your memoryspace carefully.

    What I do is being restrictive with reserving space for global or static variables. I store all the local stuff in registers and the first thing I do in a subroutine is to save all used registers on stack.

    This requires commenting the souce code, though, because the variables are just named R0..R7 and don't have names that describe their purpose.

    I also use temporary storage like a place to store the result of 32bit or floating point calculation, but that has to be used very carefully. That means, I cannot be sure that the content of that location in memory will survive a subroutine call.

    Sure, a linker will be able to generate a more compact memory usage from C code, but I have done some pretty big projects in just assembler before I had the C compiler and it all worked out well. Programming assembler requires lotsa discipline and commenting. I think, I am faster with C, but will still do a couple of things in assembler.

    Take care
    Sven.

Reply
  • Hi Erik!

    Well, I think, you just have to use your memoryspace carefully.

    What I do is being restrictive with reserving space for global or static variables. I store all the local stuff in registers and the first thing I do in a subroutine is to save all used registers on stack.

    This requires commenting the souce code, though, because the variables are just named R0..R7 and don't have names that describe their purpose.

    I also use temporary storage like a place to store the result of 32bit or floating point calculation, but that has to be used very carefully. That means, I cannot be sure that the content of that location in memory will survive a subroutine call.

    Sure, a linker will be able to generate a more compact memory usage from C code, but I have done some pretty big projects in just assembler before I had the C compiler and it all worked out well. Programming assembler requires lotsa discipline and commenting. I think, I am faster with C, but will still do a couple of things in assembler.

    Take care
    Sven.

Children
  • One comment that Sven made about using registers as variables. In Keil, you can equate variable names with registers so that you can, within a local program segment, have meaningful names for variables stored in registers.

    testvar  equ  R5
    testvar2 equ  R6
    
    tp1:
        mov  A,testvar
        mov  B,testvar2
        add  A,B
    
        ret
    

    This is a nice feature as it makes reading the code more straitforward.

  • Hi Tom!

    That's an excellent idea. Have never seen that before and actually never thought about it, since when I write the programm, I know the purpose I use the registers for anyway and I usually comment my programms a lot.

    Your method is much better.

    Take care
    Sven