Login [Register]
Don't have an account? Register now to chat, post, use our tools, and much more.
This is an archived, read-only copy of the United-TI subforum , including posts and topic from May 2003 to April 2012. If you would like to discuss any of the topics in this forum, you can visit Cemetech's z80 & ez80 Assembly subforum. Some of these topics may also be directly-linked to active Cemetech topics. If you are a Cemetech member with a linked United-TI account, you can link United-TI topics here with your current Cemetech topics.

This forum is locked: you cannot post, reply to, or edit topics. Z80 & 68k Assembly => z80 & ez80 Assembly
Author Message
AHBAD_ALVIN


Advanced Newbie


Joined: 18 Sep 2010
Posts: 74

Posted: 06 Oct 2010 05:22:21 pm    Post subject:

Hello, I have a quick question...

For my parser, I want to change decimal numbers written in ASCII code to pure hex code. I know this is possible, as Axe and the OS do this quite frequently. How exactly do I do this quickly and memory efficiently?
Back to top
calc84maniac


Elite


Joined: 22 Jan 2007
Posts: 770

Posted: 06 Oct 2010 08:24:00 pm    Post subject:

Here is a z80 routine I whipped up, which will read ASCII digits pointed to by DE into a binary number in HL, stopping when a non-digit character is reached.

Code:

;Start with 0
  ld hl,0
digitLoop:
;Read character and make sure it is a digit
  ld a,(de)
  sub '0'
  cp 10
  jr nc,notADigit
;Increment pointer
  inc de
;Multiply HL by 10
  ld b,h
  ld c,l
  add hl,hl
  add hl,hl
  add hl,bc
  add hl,hl
;Add the digit value in A to HL
  add a,l
  ld l,a
  jr nc,digitLoop
  inc h
  jr digitLoop
notADigit:

Edit: Made it actually stop where the non-digit was found instead of the character afterward.


Last edited by Guest on 06 Oct 2010 08:25:12 pm; edited 1 time in total
Back to top
AHBAD_ALVIN


Advanced Newbie


Joined: 18 Sep 2010
Posts: 74

Posted: 07 Oct 2010 04:21:12 am    Post subject:

calc84maniac wrote:

Here is a z80 routine I whipped up, which will read ASCII digits pointed to by DE into a binary number in HL, stopping when a non-digit character is reached.

Code:

;Start with 0
  ld hl,0
digitLoop:
;Read character and make sure it is a digit
  ld a,(de)
  sub '0'
  cp 10
  jr nc,notADigit
;Increment pointer
  inc de
;Multiply HL by 10
  ld b,h
  ld c,l
  add hl,hl
  add hl,hl
  add hl,bc
  add hl,hl
;Add the digit value in A to HL
  add a,l
  ld l,a
  jr nc,digitLoop
  inc h
  jr digitLoop
notADigit:

Edit: Made it actually stop where the non-digit was found instead of the character afterward.

Thanks for your help! Smile
Back to top
AHBAD_ALVIN


Advanced Newbie


Joined: 18 Sep 2010
Posts: 74

Posted: 07 Oct 2010 12:41:44 pm    Post subject:

Oh, and I just improved it some while fooling around with Mimas during my history class. But of course, this is only a minor addition so that it only reads five digits of a number (next addition will to make it only accept numbers less than 65353).


Code:

;Start with 0
  db DD
  ld l,5
  ld hl,0
digitLoop:
;push the a register and then compare to IXL
  dec ix
  push af 
  ld a,0
  db DD
  cp l
  jr z,notADigit 
  pop af
;Read character and make sure it is a digit
  ld a,(de)
  sub '0'
  cp 10
  jr nc,notADigit
;Increment pointer
  inc de
;Multiply HL by 10
  ld b,h
  ld c,l
  add hl,hl
  add hl,hl
  add hl,bc
  add hl,hl
;Add the digit value in A to HL
  add a,l
  ld l,a
  jr nc,digitLoop
  inc h
  jr digitLoop
notADigit:
  ret
Back to top
Display posts from previous:   
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
    »
» View previous topic :: View next topic  
Page 1 of 1 » All times are GMT - 5 Hours

 

Advertisement