flat assembler
Message board for the users of flat assembler.

 Index > DOS > Number input routine
Author
me239

Joined: 06 Jan 2011
Posts: 200
me239
Hey guys, I was wondering if anyone had any routines for accepting input from the cli that converts the number entered into a WORD value.
19 Jul 2011, 06:27
AsmGuru62

Joined: 28 Jan 2004
Posts: 1419
AsmGuru62
Get the text from user using INT 21H (AH=0Ah).
Then convert received text into a number using following pseudo-code:
Code:
```RESULT=0

repeat until no more digits left within input text
SUB AL,'0'
RESULT = 10*RESULT + AL
end repeat
```

Here http://www.codexxi.com/MyTools.html#atFASMW I have some code like this in a sample project for IDE. Look in PROJECTS folder - IntCalc sub-folder.
19 Jul 2011, 11:09
me239

Joined: 06 Jan 2011
Posts: 200
me239
AsmGuru62 wrote:
Get the text from user using INT 21H (AH=0Ah).
Then convert received text into a number using following pseudo-code:
Code:
```RESULT=0

repeat until no more digits left within input text
SUB AL,'0'
RESULT = 10*RESULT + AL
end repeat
```

Here http://www.codexxi.com/MyTools.html#atFASMW I have some code like this in a sample project for IDE. Look in PROJECTS folder - IntCalc sub-folder.
Can you explain what's wrong?
Code:
```mov word[num], 0
mov si, msg
mov cx, 5
@@:
lodsb
mov ah, 0
xchg ax, bx
mov ax, [num]
mov dx, 10
mul dx
mov word[num], ax
loop @b
mov ax, [num]
int 20h
num dw  0
msg db  '1234', 0
```
20 Jul 2011, 00:55
LocoDelAssembly

Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
You forgot to subtract '0' (48). You use "sub bx, '0'" just before "add ax, bx" to fix this. Also note that you are setting up CX wrong, it should be 4 for your example to work properly.
20 Jul 2011, 02:13
me239

Joined: 06 Jan 2011
Posts: 200
me239
LocoDelAssembly wrote:
You forgot to subtract '0' (4. You use "sub bx, '0'" just before "add ax, bx" to fix this. Also note that you are setting up CX wrong, it should be 4 for your example to work properly.
Thanks! I got it now. Here is my whole routine
Code:
```org 100h
start:
mov word[num], 0
mov si, msg
@@:
lodsb
cmp al, 0
jz  @f
mov ah, 0
sub al, 30h
xchg ax, bx
mov ax, [num]
mov dx, 10
mul dx
mov word[num], ax
jmp @b
@@:
mov ax, [num]
num dw  0
msg db  '1234', 0
```
20 Jul 2011, 03:10
bitshifter

Joined: 04 Dec 2007
Posts: 764
Location: Massachusetts, USA
bitshifter
I hope something more goes here ...
Code:
```mov ax, [num]
...
num dw  0
```
20 Jul 2011, 03:53
me239

Joined: 06 Jan 2011
Posts: 200
me239
bitshifter wrote:
I hope something more goes here ...
Code:
```mov ax, [num]
...
num dw  0
```

actually it's a RET
20 Jul 2011, 04:20
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

 Jump to: Select a forum Official----------------AssemblyPeripheria General----------------MainTutorials and ExamplesDOSWindowsLinuxUnixMenuetOS Specific----------------MacroinstructionsOS ConstructionIDE DevelopmentProjects and IdeasNon-x86 architecturesHigh Level LanguagesProgramming Language DesignCompiler Internals Other----------------FeedbackHeapTest Area

Forum Rules:
 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot vote in polls in this forumYou cannot attach files in this forumYou can download files in this forum