Translation of common C constructs to msp430asm

Like switch case we can just look into how msp430 handles the following
C constructs.
1. Function:


The parameters to be passed to a function is stored in the registers (usually r12,r13,r14 & r15). It should be noted that a subroutine is called using #function name. On calling the subroutine the SP decrement by 2. and stores the return address to the stack(the address of the next instruction after the call instruction – PC’s value). Again a 2 is decremented to store the frame pointer,the value stored in r4.

Now the parameters for the function stored in the registers are pushed to the stack and accessed in the function frame as local variable of the function.

2. Pointers


Here the variable i=10 is pushed into stack 0x27e. Now the address 0x27c in r4 is moved to r15. r15 is incremented by 2(incd). This address location in r15 is stored in the address location pointed by r14. This creates a pointer which stores the address of another variable or value.

Here now value is changed to 20 by indexed mode of addressing through r15.

3. A local variable


Here the local variable is allocated a space in the stack frame itself.

4. Static variable


Here the value is moved to an address variable in RAM which is labelled as i.1194

5. Function pointer



Here the base address of the function is stored in the address location pointed by r4 and the address in r4 is stored to r15. Now r15 is a pointer to the function and used to call the function.