Jump to content





Photo

Procedure Calls 1

Posted by DanBoris, 26 November 2009 · 83 views

Action
Let's take a break from looking at Action! math and take a look at procedure calls. We will start up with something that is trivially simple:

Proc test()
Return

Proc main()
   Test()
Return


0E61: 4C 64 0E    JMP  $0E64      

0E64: 60          RTS        

0E65: 4C 68 0E    JMP  $0E68      

0E68: 20 61 0E    JSR  $0E61      
0E6B: 60          RTS     


Our main procedure starts at 0E68 and it begins with a call to procedure Test using a JSR. The procedure Test starts at 0E61 which immediately jumps to the RTS since the procedure is empty. What I haven’t been able to figure out is why the JMP instruction is there since it doesn’t jump over anything. I have yet to find a case where it actually jumps over something.

Next let’s look at how simple parameter passing is done:

Proc test(byte I)
Return

Proc main()
Test(1)
Return


0E88: 	  .BYTE #$00
0E89: 4C 8C 0E    JMP  $0E8C      

0E8C: 8D 88 0E    STA  $0E88      
0E8F: 60          RTS        

0E90: 4C 93 0E    JMP  $0E93      

0E93: A9 01       LDA  #$01     
0E95: 20 89 0E    JSR  $0E89      
0E98: 60          RTS  

This is the same as the first example, but now we pass a single BYTE parameter to the procedure. Here is an area where Action! does a good job at optimizing. Since there is only a single BYTE being passed it uses the most efficient way possible, it just passes it in the accumulator. At 0E93 the value 1 is loaded into the accumulator then the procedure is called. At 0E8C that value passed is stored in the local variable I. You will notice that space for this variable is allocated before the start of the procedure code, so this doesn’t answer the mystery of the JMP instruction.




February 2012

S M T W T F S
   1234
56789 10 11
12131415161718
19202122232425
26272829   

Recent Entries

Recent Comments

Tags