| | |
convert ASCii chacracter to decimal
Please support our Assembly advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Nov 2006
Posts: 134
Reputation:
Solved Threads: 3
•
•
•
•
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
•
•
Join Date: Nov 2006
Posts: 134
Reputation:
Solved Threads: 3
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.
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.
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.
•
•
Join Date: Nov 2006
Posts: 4
Reputation:
Solved Threads: 0
thanks for your reply 
here the code

here the code
Assembly Syntax (Toggle Plain Text)
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 3:13 pm.
![]() |
Similar Threads
- display the number of capitals letters in the sentence (Assembly)
- Stuck on a program I am working on, converting a ASCII charchter to 7 Bit (Assembly)
Other Threads in the Assembly Forum
- Previous Thread: Convert into a procedure
- Next Thread: How to integrate code with machine
| Thread Tools | Search this Thread |
3d 68hc11 6811 adress alm array asic asm assembler assembly boot bootloader buffer compression cursor debug development directory division dos draw emulator endtask error file int10h integer interrupt language loop lsi nohau osdevelopment print program range read remainder requirements shape storage string text tsr x86






