Jump to content
  • entries
    39
  • comments
    57
  • views
    124,711

Procedure Calls 1


DanBoris

2,273 views

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.

0 Comments


Recommended Comments

There are no comments to display.

Guest
Add a comment...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...