Pointers and references: Difference between revisions

Content added Content deleted
Line 16: Line 16:
LDA $0101,X ;load the byte most recently pushed on the stack into A without pulling it off the stack.</lang>
LDA $0101,X ;load the byte most recently pushed on the stack into A without pulling it off the stack.</lang>


Note that in a subroutine, the value at <code>$0101,x</code> is typically the low byte of the program counter, plus 1. It may be different depending on how many registers you pushed onto the stack prior to entry as well. In this example, we'll look at a hand-written translation of the following [[C]] function:
Note that in a subroutine, the value at <code>$0101,x</code> is typically the low byte of the program counter, plus 1. It may be different depending on how many registers you pushed onto the stack prior to entry as well. In this example, we'll look at a hand-written translation of the following [[C]] function (I'm ignoring 8-bit overflow just to keep things easier to write.)
<lang C>inline unsigned char foo (unsigned char a, unsigned char b, unsigned char c){
<lang C>inline unsigned char foo (unsigned char a, unsigned char b, unsigned char c){
return a+b+c;
return a+b+c;
Line 34: Line 34:
LDA $0106,X ;LDA #arg_C
LDA $0106,X ;LDA #arg_C
CLC
CLC
ADC $0105,X ;ADC #arg_B
ADC $0105,X
CLC
ADC $0104,X ;ADC #arg_A
ADC $0104,X ;ADC #arg_A
;we have the desired value in A, now return.
;we have the desired value in A, now return.