User Tools

Site Tools


base:ascii_char_to_4_bit_integer

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

base:ascii_char_to_4_bit_integer [2015-04-17 04:30] (current)
Line 1: Line 1:
 +====== ASCII Char to 4 bit integer ======
  
 +
 +This is a very simple routine that converts an ASCII char contained in '​a'​ to a 4 bit number returned in '​a'​. ​
 +It can deal with upper/​lowercase hex letters '​a'​..'​f'​ as well as '​A'​..'​F'​ and returns the error code 255 for
 +nonvalid input like '​g'​..'​z',​ '​G'​...'​Z'​ or other non hex digits like interpunction,​ spaces, math symbols etc...
 + 
 +<code 6502acme>​
 +  sec
 +  sbc #'​0'​
 +  bcc error
 +  ​
 +  cmp #10
 +  bcc return
 +
 +nondigit
 +  and #$3f
 +  cmp #​('​f'​-'​0'​+1)
 +  bcs error
 +  cmp #​('​a'​-'​0'​)
 +  bcc error
 +  ​
 +  sbc #​('​a'​-'​0'​-10) ​
 +  rts
 +error
 +  lda #255
 +return
 +  rts
 +</​code>​
base/ascii_char_to_4_bit_integer.txt ยท Last modified: 2015-04-17 04:30 (external edit)