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

CARD Math Part 1


DanBoris

1,483 views

I can’t believe it’s been over a year since my last blog post, time sure does fly! I thought it was about time to get back to some posts and continue my Action! language topic.

 

Last time I talked about BYTE math, this time we will start looking at CARDinal math. In Action the CARD data type is a two byte unsigned value. Here is the first piece of Action! code:

 

CARD I

PROC MAIN()
I=1
I=I+1
RETURN

 

Here is the resulting disassembly:

 

0E6A: .BYTE #$00,#$00

0E6C: 4C 6F 0E    JMP  $0E6F      

0E6F: A0 00       LDY  #$00     
0E71: 8C 6B 0E    STY  $0E6B      
0E74: C8          INY        
0E75: 8C 6A 0E    STY  $0E6A      
0E78: EE 6A 0E    INC  $0E6A      
0E7B: D0 03       BNE  $0E80      
0E7D: EE 6B 0E    INC  $0E6B   

 

We start at memory location $E6A where two bytes are set aside for variable I, and then as usual we have a JMP to that start of the code.

 

The next four instructions assign the value 1 to I and you can see a nice little optimization here. First a 0 is put into the high byte of the variable. The low byte needs to have 1 in it and since the compiler knows that Y already contains 0 in can simply use the increment Y instruction to get a 1. This will save two bytes over using LDY #$01.

 

The next three instructions handle the I=I+1. Just like in the BYTE math the compiler knows that +1 is just an increment so uses the INC instruction on the low byte of the variable instead of doing an ADC. The branch checks for an overflow and if there is one we then increment the high byte of the variable.

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...