convert ASCii chacracter to decimal

Please support our Assembly advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Nov 2006
Posts: 4
Reputation: TheFuture is an unknown quantity at this point 
Solved Threads: 0
TheFuture TheFuture is offline Offline
Newbie Poster

convert ASCii chacracter to decimal

 
0
  #1
Nov 26th, 2006
hi guys, I just wanna learn how to convert from ASCII character to the value e.g. input X then the output is 10 etc.

anyone know please help

thanks :lol:
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 134
Reputation: mathematician is an unknown quantity at this point 
Solved Threads: 3
mathematician mathematician is offline Offline
Junior Poster

Re: convert ASCii chacracter to decimal

 
0
  #2
Nov 26th, 2006
Originally Posted by TheFuture View Post
hi guys, I just wanna learn how to convert from ASCII character to the value e.g. input X then the output is 10 etc.

anyone know please help

thanks :lol:

xor ah,ah
int 16h ;read in ascii character ( in range '0' - '9' ) into al
sub al, 48 ;convert ascii character to integer in range 0-9
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 4
Reputation: TheFuture is an unknown quantity at this point 
Solved Threads: 0
TheFuture TheFuture is offline Offline
Newbie Poster

Re: convert ASCii chacracter to decimal

 
0
  #3
Nov 26th, 2006
thanks for your reply

but it too advance for me, it is posible show me in CPU Sim?

thanks so much
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 134
Reputation: mathematician is an unknown quantity at this point 
Solved Threads: 3
mathematician mathematician is offline Offline
Junior Poster

Re: convert ASCii chacracter to decimal

 
0
  #4
Nov 26th, 2006
It's not that complicated. Ascii characters are represented by numbers, so that, for example:

mov al, 'A' ;actually moves the number 65 into al, because that's its ascii code
mov al, 'B' ;actually moves the number 66 into al
mov al, C' ;moves 67 into al, and so on.

In the case of the numerals it's:

mov al, '0' ;moves the number 48 into al
mov al, '1' ;moves the number 49 into al
mov al, '2' ;moves the number 50 into al
mov al, '3' ;moves the number 51 into al

So if you subtract 48 from any of those four, you get 0, 1, 2 and 3 respectively - the conversion you want.
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 7
Reputation: embeddedravi is an unknown quantity at this point 
Solved Threads: 0
embeddedravi embeddedravi is offline Offline
Newbie Poster

Re: convert ASCii chacracter to decimal

 
0
  #5
Nov 27th, 2006
use ctoi function
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 4
Reputation: TheFuture is an unknown quantity at this point 
Solved Threads: 0
TheFuture TheFuture is offline Offline
Newbie Poster

Re: convert ASCii chacracter to decimal

 
0
  #6
Nov 27th, 2006
thanks so much for your help
but I know how to declares the character already .. the problem is how to get the program working
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,519
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1480
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: convert ASCii chacracter to decimal

 
0
  #7
Nov 27th, 2006
Originally Posted by TheFuture View Post
thanks so much for your help
but I know how to declares the character already .. the problem is how to get the program working
Where is your code? What have you tried? People here are not mind readers, so you need to post YOUR code. And please use code tags as described in the links in my signature.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 4
Reputation: TheFuture is an unknown quantity at this point 
Solved Threads: 0
TheFuture TheFuture is offline Offline
Newbie Poster

Re: convert ASCii chacracter to decimal

 
0
  #8
Nov 28th, 2006
thanks for your reply
here the code

  1. start:
  2. read A0
  3. push A0 ; save A0
  4. push A1 ; save A1
  5. load_fp A1 8 ; load parameter C
  6. ; compare to ASCII I to M
  7. load_c A0 73 ; ASCII I
  8. subtract A1 A0 ; A1 = int(C)
  9. jmpn A1 outof
  10. move A1 A0 ; copy it
  11. load_c A1 M ; max value
  12. subtract A1 A0 ; A1 = M - int(C)
  13. jmpn A1 outof
  14. ; return result
  15. store_fp A0 6 ; result
  16. endDA: ; restore accumulators
  17. pop A1
  18. pop A0
  19. return
  20. outof: ; return -ve
  21. store_fp A1 6 ; -ve
  22. jump endDA
  23.  
  24.  
  25. I: .data 2 73
  26. V: .data 2 86
  27. X: .data 2 88
  28. L: .data 2 76
  29. C: .data 2 67
  30. D: .data 2 68
  31. M: .data 2 77
Last edited by TheFuture; Nov 28th, 2006 at 3:13 pm.
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 1
Reputation: nazim123 is an unknown quantity at this point 
Solved Threads: 0
nazim123 nazim123 is offline Offline
Newbie Poster

Re: convert ASCii chacracter to decimal

 
0
  #9
Dec 1st, 2008
i'm having the same problem to....................would you be at UNI
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC