Jump to content





CARD Math Part 1

Posted by DanBoris, 15 November 2009 · 395 views

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




July 2014

S M T W T F S
  12345
6789101112
13141516171819
2021222324 25 26
2728293031  

Recent Entries

Recent Comments

Tags