Jump to content

3

Omegamatrix's Blog



Hex to BCD conversion (0-99) Part Trois

Posted by Omegamatrix, in 6502 Math Routines 01 June 2015 · 748 views
Hex, BCD, Hex Conversion
I've covered some Hex to Decimal conversions like 0-255 and 0-65535 already in my blog, and have had done some previous solutions to 0-99 as well. Today I was thinking about converting a single byte from a hex value to BCD (0-99) once again. I came up with this routine which is the shortest, simplest, and fastest yet.;Hex2Bcd (good 0-99);22 bytes, 26 c...


Hex to Ascii String

Posted by Omegamatrix, in 6502 Math Routines 26 January 2015 · 949 views

I saw a topic on 6502.org about converting byte to hex string . I remembered Lee Davison's code shorts about converting 0 to 15 to ascii 0 to 15 by using decimal mode. I know Lee passed along this year so RIP Lee, I didn't know you but you seemed like a genius to me. :)
 
 
Using his basic code I came up with this for converting a byte:;HEX to...


Embedded Tables, Divide by 40, Mod 40

Posted by Omegamatrix, in Assembly Tricks, 6502 Math Routines 21 June 2014 · 1,132 views
Divide by 40, Mod 40
While posting my Unsigned Integer Division Routines on NesDev, a new member there said he was looking for a divide by 40 and mod 40. I wrote a few routines, but this one really sticks out as a neat idea.;Divide by and Mod 40 combined;38 bytes, 45 cycles;Y = value to be dividedInterlacedMultiplyByFortyTable: lda #0 ; dummy load, #0 used in LUT l...


Hex to Decimal (0-255) Pt II

Posted by Omegamatrix, in 6502 Math Routines 08 June 2014 · 1,096 views
hex to decimal
I had another go at an one byte 'hex to decimal' conversion routine. This time I kept it simple. It's a much better effort, and much quicker then before! :)
 
Boring stats:;--------------------------------;0-255 conversion stats;--------------------------------;cycles occurances ;47 - 20 ;48 - 0 ;49 - 10 ;50 - 36 ;51 - 0 ;52 - 40...


Hex to Decimal (0-65535)

Posted by Omegamatrix, in 6502 Math Routines 07 June 2014 · 1,482 views
hex to decimal, 16 bit, NES
Continuing with my Hex to Decimal routines, I have written one for 16 bit numbers. :)
 
This routine is really geared toward a NES. The NES has no decimal mode. I think most of the time programmers will just break their scores out into multiple bytes (one for each digit), and then handle rollover cases for greater than 9, and less than 0.
 
Here...


(16 bit division), Fast divide by 10

Posted by Omegamatrix, in 6502 Math Routines 26 May 2014 · 1,977 views
16 bit, divide by 10
I took a stab at making a 16 bit division routine tonight. I took the approach of dividing the high and low bytes separately, since I have already written a bunch of 8 bit division routines. I then corrected the result with a couple of small look up tables.
 
 
This is the 16 bit routine I came up with. At 111 cycles max, and 96 bytes total it's...


Hex to Decimal (0-255)

Posted by Omegamatrix, in 6502 Math Routines 24 May 2014 · 1,144 views
hex, decimal, bcd
This morning I decided to extend my Hex to BCD routines so that I can cover a whole byte. :)
 
 
This is what I came up with :;--------------------------------------- lda hexValue ;3 @3 (0 - 255) ldx #0 ;2 @5 hundreds digit = 0;divide by 10, and times result by 6 sta temp...


Hex to BCD conversion (0-99) Part Deux

Posted by Omegamatrix, in 6502 Math Routines 07 March 2014 · 1,561 views

Continuing with Hex to BCD routines, tonight I took a look at using a hybrid table approach.
.
.;Hex2Bcd (good 0-99);26 bytes, 30 cycles sta temp ;3 @3 lsr ;2 @5 lsr ;2 @7 lsr ;2 @9 lsr ;2 @11 tax ;2 @13 lda temp ;3 @16 and #$0F ;2 @18...


Hex to BCD conversion (0-99)

Posted by Omegamatrix, in 6502 Math Routines 25 February 2014 · 2,186 views
BCD
I can't sleep. I'm consumed by this problem and I keep thinking about it...
 
Tonight I discovered some of Batari's solutions for hex to bcd conversion here  and here . They are very compact solutions, and neat. I started to wonder if a constant (un-looped) cycle approach could be found without using tables. Then the insomnia crept in. :)...


Unsigned Integer Division Routines

Posted by Omegamatrix, in 6502 Math Routines 11 February 2014 · 2,315 views

In general, multiplication in assembly is easy, and division is a bitch. There are three basic approaches to doing division. The first is to just do a loop in which the divisor is continually subtracted: lda dividendValue ldx #0 sec.loopDivideBySeven inx sbc #7 bcs .loopDivideBySeven
The advantage to this approach is that it...





December 2018

S M T W T F S
      1
2345678
910111213 14 15
16171819202122
23242526272829
3031     

Recent Comments

Latest Visitors

0 user(s) viewing

0 members, 0 guests, 0 anonymous users