flat assembler
Message board for the users of flat assembler.

Index > DOS > Help With Input

Author
Thread Post new topic Reply to topic
Jakevfr



Joined: 03 Feb 2007
Posts: 26
Jakevfr
I'm attempting to optimize the libraries I made earlier and have had some success so far, but have run into a problem. The backspace. Below is my code, and it was working just fine just an hour ago, but now it won't show up correctly (It still works like it should though). If you could help me out I'd appreciate it.
Code:
org 100h

call getStr
mov dx, ax
mov ah, 09h
int 21h

mov ax, 4c00h
int 21h

getStr:
    push bx cx dx
    xor ax, ax
    xor bx, bx
    xor cx, cx
    xor dx, dx
    mov dl, '?'
    mov ah, 02h
    int 21h

    .loop:
        xor ax, ax
        int 16h
        mov cl, al

        cmp cl, 13
        je .exit
        cmp cl, 8
        je .backspace

        mov dl, al
        mov ah, 02h
        int 21h

        mov [input+bx], cl
        inc bl
        cmp bl, 99
        jae .exit
        jmp .loop

    .backspace:
        cmp bl, 0
        jbe .loop
        mov ah, 02h
        mov dl, ' '
        int 21h
        mov dl, 8
        int 21h
        dec bl
        jmp .loop

    .exit:
        mov [input+bx], '$'
        call endl
        pop dx cx bx
        mov ax, input
        ret

endl:
    mov ah, 02h
    mov dl, 13
    int 21h
    mov dl, 10
    int 21h
    ret

input db 100 dup (?)    

Thanks Smile

EDIT: Also, how should I go about doing this:
Code:
mov [var], ax    

Should I make the variable dw, or is there some special way I can move ax into a DB variable?
Post 21 Mar 2007, 21:55
View user's profile Send private message Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1901
DOS386
Quote:

Code:
mov [var], ax
    

Should I make the variable dw


Definitely YES.

Quote:
is there some special way I can move ax into a DB variable


Is there some special way how to store 16 gallons of trinitroglycerole
into a 8 gallons bottle ? Laughing

Probably NO, silly idea, doesn't fit Laughing

Quote:

The backspace. Below is my code, and it was working just fine just an hour ago, but now it won't show up correctly (It still works like it should though)


Strange. Something must have happened 1 hour ago Laughing

Try:

Code:
        mov ah,2
        mov dl, 8
        int $21
        mov dl, ' '
        int $21
        mov dl, 8
        int $21 
    

_________________
Bug Nr.: 12345

Title: Hello World program compiles to 100 KB !!!

Status: Closed: NOT a Bug
Post 22 Mar 2007, 05:33
View user's profile Send private message Reply with quote
Jakevfr



Joined: 03 Feb 2007
Posts: 26
Jakevfr
Thanks
Post 22 Mar 2007, 14:48
View user's profile Send private message Reply with quote
bsc021



Joined: 19 Apr 2007
Posts: 1
bsc021
I am doing a project and would like you to post a working input code.
I need to input two numbers to be multiplied and then give the output.

-Thanks
Post 19 Apr 2007, 19:43
View user's profile Send private message Reply with quote
Jakevfr



Joined: 03 Feb 2007
Posts: 26
Jakevfr
I will once I get back to my computer with all that stuff on it.

Sorry for not replying sooner, been busy and haven't made it to the forums in a while :/
Post 04 May 2007, 02:50
View user's profile Send private message Reply with quote
Jakevfr



Joined: 03 Feb 2007
Posts: 26
Jakevfr
Alright here is the code I have... updated to. I'm not sure if this code is better, but it removes the need for a variable making it smaller, which I like.

Just call geti and ax will contain the number inputed.

Code:
geti:
        xor ax,ax
        push ax
        call getc
        cmp al,'-'
        jne ooops
        mov cx,1
        call putc
        call getc
ooops:
        call putc
        cmp al,13
        je .exit
        sub al,0x30
        xor dx,dx
        mov dl,al
        pop ax
        add ax,dx
        push ax

.getii:
        call getc
        call putc
        cmp al,13
        je .exit
        sub al,0x30
        xor dx,dx
        mov dl,al
        pop ax
        imul ax,10
        add ax,dx
        push ax
        jmp .getii

.exit:
        pop ax
        cmp cx,1
        jne noneg
        neg ax
noneg:
        push ax
        mov al,10
        call putc
        pop ax
        ret

getc:
    xor ax,ax
    int 0x16
    ret

putc:
    mov ah,0x0e
    int 0x10
ret
    


EDIT: Added PutC, I knida forgot it Confused
Post 04 May 2007, 02:56
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. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.