User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Assembly section within the Software Development category of DaniWeb, a massive community of 426,575 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 1,658 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Assembly advertiser: Programming Forums
Views: 10381 | Replies: 7
Reply
Join Date: Nov 2006
Posts: 4
Reputation: TheFuture is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
TheFuture TheFuture is offline Offline
Newbie Poster

convert ASCii chacracter to decimal

  #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:
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Nov 2006
Posts: 99
Reputation: mathematician is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 1
mathematician mathematician is offline Offline
Junior Poster in Training

Re: convert ASCii chacracter to decimal

  #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  
Join Date: Nov 2006
Posts: 4
Reputation: TheFuture is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
TheFuture TheFuture is offline Offline
Newbie Poster

Re: convert ASCii chacracter to decimal

  #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  
Join Date: Nov 2006
Posts: 99
Reputation: mathematician is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 1
mathematician mathematician is offline Offline
Junior Poster in Training

Re: convert ASCii chacracter to decimal

  #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  
Join Date: Sep 2006
Posts: 7
Reputation: embeddedravi is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
embeddedravi embeddedravi is offline Offline
Newbie Poster

Re: convert ASCii chacracter to decimal

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

Re: convert ASCii chacracter to decimal

  #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  
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 11,184
Reputation: Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of 
Rep Power: 38
Solved Threads: 930
Moderator
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Most Valuable Poster

Re: convert ASCii chacracter to decimal

  #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.
I think it's about time we voted for senators with breasts. After all, we've been voting for boobs long enough. ~Clarie Sargent, Arizona senatorial candidate
Those who are too smart to engage in politics are punished by being governed by those who are dumber. ~Plato
Reply With Quote  
Join Date: Nov 2006
Posts: 4
Reputation: TheFuture is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
TheFuture TheFuture is offline Offline
Newbie Poster

Re: convert ASCii chacracter to decimal

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

start:
    read A0
    push A0 ; save A0
    push A1 ; save A1
    load_fp A1 8 ; load parameter C
; compare to ASCII I to M
load_c A0 73 ; ASCII I
subtract A1 A0 ; A1 = int(C)
jmpn A1 outof
move A1 A0 ; copy it
load_c A1 M ; max value
subtract A1 A0 ; A1 = M - int(C)
jmpn A1 outof
; return result
store_fp A0 6 ; result
endDA: ; restore accumulators
pop A1
pop A0
return
outof: ; return -ve
store_fp A1 6 ; -ve
jump endDA


I: .data 2 73
V: .data 2 86
X: .data 2 88
L: .data 2 76
C: .data 2 67
D: .data 2 68
M: .data 2 77
Last edited by TheFuture : Nov 28th, 2006 at 2:13 pm.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Assembly Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the Assembly Forum

All times are GMT -4. The time now is 9:45 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC