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:

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

thanks for your reply

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

thanks so much :)

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.

thanks so much for your help
but I know how to declares the character already .. the problem is how to get the program working :(

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.

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
This article has been dead for over six months. Start a new discussion instead.