flat assembler
Message board for the users of flat assembler.

Index > Main > Comparing Strings Confused

Goto page Previous  1, 2
Author
Thread Post new topic Reply to topic
bitshifter



Joined: 04 Dec 2007
Posts: 764
Location: Massachusetts, USA
bitshifter
Hmm, works good here on XP2.
What are you running it on?
What does it not do?
Post 25 Jun 2010, 10:34
View user's profile Send private message Reply with quote
Teehee



Joined: 05 Aug 2009
Posts: 568
Location: Brazil
Teehee
oi nathan Smile try this:

Code:
main:
    mov si, welcome 
    call printf 
     
    mloop: 
        mov si, prompt          ; The prompt is beginning 
        call printf

        mov di, input
        call getinput

        mov si, input
        mov di, cmd_hello       ; Command: hello
        call strcmp 
        jz .hello

        mov si, input
        mov di, cmd_help        ; Command: help
        call strcmp 
        jz .help

        mov si, input
        mov di, cmd_stats       ; Command: stats
        call strcmp 
        jz .stats

        mov si, input
        mov di, err_cmd         ; Command entered is invalid
        call printf 
        jmp mloop               ; Infinity loop 
         
        .hello: 
            mov si, msg_hello 
            call printf 
            jmp mloop 
         
        .help: 
            mov si, msg_help 
            call printf 
            jmp mloop 
             
        .stats: 
            mov si, ax 
            call printf 
            jmp mloop 

; === Functions === 
printf:
    mov ah, 0eh 
    mov bh, 99h 

    .nextchar: 
        lodsb 
        or al, al 
        jz .return 
        int 10h 
        jmp .nextchar 

    .return: 
        ret 

getinput: 
    xor cl, cl 
     
    .loop: 
        mov ah, 00h
        int 16h         ; Key press wait

        cmp al, 08h     ; Backspace key 
        je .backspace   ; Handle 
         
        cmp al, 0dh     ; Enter key 
        je .enter       ; Handle 
         
        cmp cl, 3fh     ; Inputted 63 characters 
        je .loop        ; Only backspace and enter are accepted 

        mov ah, 0eh    
        int 10h 
         
        stosb 
        inc cl 
        jmp .loop 
         
    .backspace: 
        cmp cl, 0       ; Begin of the input 
        je .loop        ; Ignore 
         
        dec di 
        mov byte[di], 0 ; Delete character 
        dec cl          ; Decrementing the string counter 
         
        mov ah, 0eh 
        mov al, 08h 
        int 10h         ; Print the backspace 
         
        mov al, ' ' 
        int 10h         ; Blank character 
         
        mov al, 08h 
        int 10h         ; Backspace one more time 
         
        jmp .loop       ; Goes back to the loop 
         
    .enter: 
        mov al, 0       ; Null terminator 
        stosb 
         
        mov ah, 0eh 
         
        mov al, 0dh     ; Enter character 
        int 10h 
         
        mov al, 0ah     ; Newline character 
        int 10h 
         
        ret 
         
strcmp:
        push cx ; I'm taking advantage of CL counter used in getinput.
        rep cmpsb
        pop cx
        ;ZF == 1 == equal
        ret 

welcome db "Welcome To The Second DOS Shell For Your DOS ", 0dh, 0ah, 0ah, 0 
prompt db ">", 0

input rb 255


; ==== Commands ========================== 
cmd_help db "help", 0
msg_help db "Valid Commands: help - hello", 0dh, 0ah, 0

cmd_hello db "hello", 0
msg_hello db "Hi all!", 0dh, 0ah, 0

cmd_stats db "stats", 0

err_cmd db "The command you entered doesn't exist!", 0dh, 0ah, 0    

however, your input reader routine let my processor in 100% of use.

_________________
Sorry if bad english.
Post 25 Jun 2010, 12:01
View user's profile Send private message Reply with quote
nathanpc



Joined: 23 Aug 2009
Posts: 40
Location: Brazil
nathanpc
Ainda estou tendo o mesmo problema amigo. Sad

I'm still having the same problem. Sad
Post 25 Jun 2010, 16:24
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
bitshifter



Joined: 04 Dec 2007
Posts: 764
Location: Massachusetts, USA
bitshifter
What are you running it in?
Is the segments and stack setup?
Post 25 Jun 2010, 23:18
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page Previous  1, 2

< 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 YouTube, Twitter.

Website powered by rwasa.