flat assembler
Message board for the users of flat assembler.

Index > DOS > Number input routine

Author
Thread Post new topic Reply to topic
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.
Post 19 Jul 2011, 06:27
View user's profile Send private message Reply with quote
AsmGuru62



Joined: 28 Jan 2004
Posts: 1409
Location: Toronto, Canada
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
    AL = load next digit
        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.
Post 19 Jul 2011, 11:09
View user's profile Send private message Send e-mail Reply with quote
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
      AL = load next digit
        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
    add ax, bx
    mov word[num], ax
    loop @b
    mov ax, [num]
    int 20h   
num dw  0
msg db  '1234', 0
    
Post 20 Jul 2011, 00:55
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


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.
Post 20 Jul 2011, 02:13
View user's profile Send private message Reply with quote
me239



Joined: 06 Jan 2011
Posts: 200
me239
LocoDelAssembly wrote:
You forgot to subtract '0' (4Cool. 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
    add ax, bx
    mov word[num], ax  
    jmp @b   
@@:    
    mov ax, [num]  
num dw  0
msg db  '1234', 0
    
Post 20 Jul 2011, 03:10
View user's profile Send private message Reply with quote
bitshifter



Joined: 04 Dec 2007
Posts: 764
Location: Massachusetts, USA
bitshifter
I hope something more goes here ...
Code:
mov ax, [num]   
...
num dw  0
    
Post 20 Jul 2011, 03:53
View user's profile Send private message Reply with quote
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
Post 20 Jul 2011, 04:20
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar.

Powered by rwasa.