r4id4
r4id4

Reputation: 6077

Assembly x86 read a string character by character

I'm getting as input a string of numbers, i'd like to read it character by character in order to convert each digit in integer.

Example input: 54321

i need to convert it to the numeric value 54321 to make some operation.

This is the function i'm using to read

STRING                      DB      20,0 
                            RESB    20

   ;;;;;;;;;   Code here   ;;;;;;;;;

    MOV                     DX,STRING
    MOV                     AH,0Ah
    INT                                     21h

At least if you can tell me the logic or a function for 8086 useful to do that. Thanks

Upvotes: 2

Views: 6924

Answers (1)

Shibumi
Shibumi

Reputation: 715

A string is only an array. So the first letter is for example in "edx" the second letter in "edx+1" the third letter in "edx+2" and so on..

You can convert the characters back to integers with this calculation:

'chardigit' - 48 = integerdigit

this is possible because ascii '0' is 48. Here is an example:

"123"

'1' (or 49 in dec) - 48 = 1
'2' (or 50 in dec) - 48 = 2
'3' (or 51 in dec) - 48 = 3

I hope this is intelligible.

Upvotes: 3

Related Questions