This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Describe how call instruction works in detail



Hello folks;

I also need some clarification. I'm practicing my assembly and wrote a test program to use the call instructions with various addressing modes.

I've hit a snag with the call instruction, using PC relative indexing, aka symbolic addressing. Here is a a snippet debugged from msp430-elf-objcopy. I am using TI/RedHat toolchain for MSP430, the date inside the release notes is 2015-09-07

F81C: 90 12 16 00 call sub1 ;PC rel. 0x0016 to 0xf834
F820: ....
F834: 30 41 sub1 ret

The description in the MSP430x1xx Family user guide (SLAU049F 2006 page 3.29) seems to agree with the debugger output.
o SP-2 -> SP (pre-decrement SP)
o PC+2 -> @SP (write PC to address referred to by SP)
o X(PC) -> PC (use value after the instruction word to jump to new PC address)

But:
o If the address of the X value was pushed to the stack, then RET would put the address of X into the PC
o Otherwise, if it's the address after the X value that's pushed then the offset provided by the assembler would be referring to a different instruction

So, not sure what to say... Thanks in advance.
  • Hi Krista,

    Looking at your code and example breakdown, I think you have the description of what is going on correct, but your suppositions at the end are not correct.

    I'll walk through your description in a little more detail to see if that helps clear up what is happening inside of the call instruction:

    Krista Hill said:
    o SP-2 -> SP (pre-decrement SP)


    The stack pointer gets decremented to the next location in preparation for the data that is about to be written to the stack.

    Krista Hill said:
    o PC+2 -> @SP (write PC to address referred to by SP)


    The value of PC+2 (which is the next instruction) gets stored to the stack.  Note that PC does not actually change at this point.  Also note that the "+2" refers to how many words the PC is incremented by, since the PC can only point to word locations (even addresses), the last bit of the PC is always '0'.  So PC+2 in this case refers to the address 0xF820.

    Krista Hill said:
    o X(PC) -> PC (use value after the instruction word to jump to new PC address)


    The value of PC + X is stored into PC.  Note that the PC is still the original PC (0xF81C) when adding the offset X (0x0016) to it, so it now points to the correct location (0xF834).

    Let me know if that helps clarify things.

    Mike

  • Mike Pridgen said:
    ... I think you have the description of what is going on correct, ...

    I disagree. I think that code will not work. (Try it!)

    I usually use "CALL #SUB1;"

    I occasionally use "CALL PTR1;", "CALL &PTR1;"  or "CALL Rn;", where PTR1 and Rn point to SUB1.

**Attention** This is a public forum