It is currently Sun Jul 22, 2018 4:09 am

 All times are UTC - 7 hours

 Page 1 of 1 [ 3 posts ]
 Print view Previous topic | Next topic
Author Message
 Post subject: HEX TO DECPosted: Mon Jun 12, 2017 3:17 am

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

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

.DB \$27
.DB \$03
.DB \$00
.DB \$00
.DB \$00

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

 Post subject: Re: HEX TO DECPosted: Mon Jun 12, 2017 3:34 am
 Formerly WheelInventor

Joined: Thu Apr 14, 2016 2:55 am
Posts: 1657
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.

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

Top

 Post subject: Re: HEX TO DECPosted: Mon Jun 12, 2017 6:13 pm

Joined: Sun Sep 19, 2004 10:59 pm
Posts: 1418
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

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 1 of 1 [ 3 posts ]

 All times are UTC - 7 hours