6502 32位 HEX 转 DEC

;[FC][32位HEX转DEC][20190402]
;FlameCyclone

 .ORG $8000
 
Hex_LL = $00
Hex_LH = $01
Hex_HL = $02
Hex_HH = $03
Dec_Digit = $04

DIGIT_COUNT = 10

;零页占用: 14字节
;  程序段: 0xA3字节
;$0xFFFFFFFF转4294967295耗时5508
;$0x3B9AC9FF转999999999耗时7532
; $0x5F5E0FF转99999999耗时6747
;  $0x98967F转9999999耗时5974
;   $0xF423F转999999耗时5133
;   $0x1869F转99999耗时4264
;    $0x270F转9999耗时3375
;     $0x3E7转999耗时2418
;      $0x63转99耗时1476
;      $0x09转9耗时486

 LDX #$FF
 TXS

 LDA #$FF
 STA Hex_LL
 LDA #$C9
 STA Hex_LH
 LDA #$9A
 STA Hex_HL
 LDA #$3B
 STA Hex_HH
 JSR Hex_To_Dec
 RTS

Hex_To_Dec: 
 LDY #$00
Dec_Clear:
 STA Dec_Digit,X
 INX
 CPX #DIGIT_COUNT
 BCC Dec_Clear
 DEX
Convert_Compare:
HH_Compare:
 LDA Hex_HH
 CMP Dec_Data_HH,X
 BCC Convert_Digit_End
 BNE Sub_LL
 LDA Hex_HL
HL_Compare:
 CMP Dec_Data_HL,X
 BCC Convert_Digit_End
 BNE Sub_LL
 LDA Hex_LH
LH_Compare
 CMP Dec_Data_LH,X
 BCC Convert_Digit_End
 BNE Sub_LL
 LDA Hex_LL
LL_Compare:
 CMP Dec_Data_LL,X
 BCC Convert_Digit_End
Sub_LL:
 LDA Hex_LL
 SBC Dec_Data_LL,X
 STA Hex_LL
 BCS Sub_LH
 DEC Hex_LH
Sub_LH:
 LDA Hex_LH
 SEC
 SBC Dec_Data_LH,X
 STA Hex_LH
 BCS Sub_HL
 DEC Hex_HL
Sub_HL: 
 LDA Hex_HL
 SEC
 SBC Dec_Data_HL,X
 STA Hex_HL
 BCS Sub_HH
 DEC Hex_HH
Sub_HH:
 LDA Hex_HH
 SEC
 SBC Dec_Data_HH,X
 STA Hex_HH
Set_Digit:
 INY
 BNE Convert_Compare
Convert_Digit_End:
 STY Dec_Digit,X
 LDY #$00
 DEX
 BNE Convert_Compare
Convert_Finish:
 STA Dec_Digit
 RTS

Dec_Data_LL:
 .DB $01,$0A,$64,$E8,$10,$A0,$40,$80,$00,$00
Dec_Data_LH:
 .DB $00,$00,$00,$03,$27,$86,$42,$96,$E1,$CA
Dec_Data_HL:
 .DB $00,$00,$00,$00,$00,$01,$0F,$98,$F5,$9A
Dec_Data_HH:
 .DB $00,$00,$00,$00,$00,$00,$00,$00,$05,$3B

使用6502 Simulator编译

你可能感兴趣的:(6502,6502asm,FC,fc,6502,NES)