Jump to content
IGNORED

DanBoris' Tech Blog - CARD Math Part 1


RSS Bot

Recommended Posts

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 IPROC MAIN()I=1I=I+1RETURN

 

Here is the resulting disassembly:

 

0E6A: .BYTE #$00,#$000E6C: 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.

 

http://www.atariage.com/forums/index.php?app=blog&blogid=52&showentry=6599

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

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