It is currently Sat Dec 16, 2017 7:37 pm

All times are UTC - 7 hours





Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: HEX TO DEC
PostPosted: Mon Jun 12, 2017 3:17 am 
Offline

Joined: Fri Jun 02, 2017 2:45 am
Posts: 7
This is my code, it can convert hex (0000-FFFF) to DEC (0-65535)
[Code]; [2 bytes hexadecimal to 5 decimal]
; FlameCyclone 2017.6.11


 .ORG $8000
 
HEX_D = $70
DEC_D = $72
 
HEX_TO_DEC: ; Hexadecimal to decimal
 PHA ; protects current A and X data
 TXA
 PHA
 LDA #$FF
 STA HEX_D ; sets the high order of the hexadecimal number to be converted
 LDA #$FF
 STA HEX_D + 1 ; Sets the low bit of the hexadecimal number to be converted
 JSR DEC_CLEARN ; Clear the decimal data
 JSR TS_D ; Hexadecimal to decimal
 PLA ; recovery before A and X data
 TAX
 PLA
 RTS ; return

HEX_DEC_DATA_H: Decimal corresponding hexadecimal high
 .DB $27
 .DB $03
 .DB $00
 .DB $00
 .DB $00
 
HEX_DEC_DATA_L: Decimal corresponding hexadecimal low
 .DB $10
 .DB $E8
 .DB $64
 .DB $0A
 .DB $01
 
DEC_CLEARN: ; Clears the decimal data
 LDX #$00
 LDA #$00
 STA DEC_D
 STA DEC_D + 1
 STA DEC_D + 2
 STA DEC_D + 3
 STA DEC_D + 4
 RTS
 

TS_D: ; Hexadecimal conversion to decimal data
 LDA HEX_D ; Reads the hexadecimal digits to be converted
 CMP HEX_DEC_DATA_H, X ; High conversion of hexadecimal number to decimal number corresponding to decimal number
 BNE TS_D_S ; does not have the same conversion
 LDA HEX_D + 1 ; Read the decimal number to be converted to hexadecimal
 CMP HEX_DEC_DATA_L, X ; ​​the high level of the hexadecimal number to be converted to the decimal number corresponding to the decimal number
 BCC TS_D_RTS ; less than the current decimal not converted
TS_D_S: ; The conversion is started
 LDA HEX_D ; Reads the hexadecimal digits to be converted
 CMP HEX_DEC_DATA_H, X ; High conversion of hexadecimal number to decimal number corresponding to decimal number
 BCC TS_D_RTS ; less than the current decimal not converted
 LDA HEX_D + 1 ; Read the decimal number to be converted to hexadecimal
 SEC ; entry position 1
 SBC HEX_DEC_DATA_L, X ; ​​Low conversion of hexadecimal number to decimal place corresponding to decimal number
 STA HEX_D + 1 ; the result is sent to the lower hexadecimal number to be converted
 BCS D_DEC_HEX_D ; skip without borrow
 DEC HEX_D ; there is a borrow to convert hexadecimal highs
D_DEC_HEX_D: ; Hexadecimal highs decrease
 LDA HEX_D ; Reads the hexadecimal digits to be converted
 SEC ; entry position 1
 SBC HEX_DEC_DATA_H, X ; High conversion of hexadecimal digits to decimal places corresponding to decimal
 STA HEX_D ; the result is sent to the hexadecimal number to be converted
ADD_DEC_D: ; Decimal corresponding bit increments
 INC DEC_D, X ; Decimal corresponding bit increments
 JMP TS_D ; continue conversion
TS_D_RTS: ; Converts a decimal bit to the end
 INX ; counter increments
 CPX #$05 ; whether to convert 5 number
 BCC TS_D ; continue to convert the next bit without conversion
 RTS ; return [/ code]


Last edited by FlameCyclone on Wed Jun 14, 2017 1:57 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: HEX TO DEC
PostPosted: Mon Jun 12, 2017 3:34 am 
Offline
Formerly WheelInventor

Joined: Thu Apr 14, 2016 2:55 am
Posts: 1131
Location: Gothenburg, Sweden
This is cool!

Regarding the number of threads with one routine each, do you want a separate commentary on each of them? Or is the goal sharing your code? If so, is it for the sake of learning/comparing with others, or is the intention that others may use it? If so, do you have a license or code of use in mind? Sorry, lots of questions. :lol:

_________________
http://www.frankengraphics.com - personal NES blog


Top
 Profile  
 
 Post subject: Re: HEX TO DEC
PostPosted: Mon Jun 12, 2017 6:13 pm 
Offline
User avatar

Joined: Sun Sep 19, 2004 10:59 pm
Posts: 1393
Remark: since the main language of these forums is English (aside from the "International" section), it's a bit confusing for all of the comments in these samples to be in Chinese.

_________________
Quietust, QMT Productions
P.S. If you don't get this note, let me know and I'll write you another.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 7 hours


Who is online

Users browsing this forum: Google Adsense [Bot] and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group