how to restrict input to 6 character string

Discussion in 'Assembly Language Programming (ALP) Forum' started by wale89, Mar 10, 2011.

  1. wale89

    wale89 New Member

    Joined:
    Mar 10, 2011
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Hi..everybody..
    I have this simple assembly language program to read in string of user input then do the checking whether the string is a palindrome or not, and display the result of the checking.
    I wanted to slightly change the program to make it read the string of exactly certain number of character long, for example 6. Can anybody help?? Give me some guide...since i am a begginers in Assembly..thank you very much..

    This are the code..
    Code:
    
    org  100h
       
    print_output macro
        mov ah, 9
        int 21h                                                               
        
      ; input the string:
      ; the interupt module does fill the third array with input from keyborad
    
    endm                                                                                            
        
    scan_input macro
        mov ah, 0ah
        int 21h
        
        ;get string size                        
        xor bx, bx             ; zero the bx register 
        mov bl, input[1]          ; then save the size of s1 to base lower register               
                                              
        ;print string                           
        mov input[bx+2],'$'        ;close the string with dollar sign   
            
      ; input the string:
      ; the interupt module does fill the third array with input from keyborad
    
    endm             
    
    
    is_input_empty macro 
        ;lea bx, input    
        ;mov dl, [bx+1] ; get string size.
        mov dl, input[1] 
        cmp dl, 0
        je stop
    endm
    
    
    part2:
        ;print the main message of program2
        mov dx, offset MSG_part2
        print_output
    part2_loop:
    
        ;print the message to promt the user to enter the string
        mov dx, offset MSG_prompt_part2
        print_output
                      
        ;scan for input              
        mov dx, offset input
        scan_input  
         
        ;print newline 
        mov dx, offset newline
        print_output
        
        is_input_empty
        
        ;output the inputed string
        mov dx, offset MSG_urstris
        print_output
                                               
        ;print string                           
        mov dx, offset input+2
        print_output
           
        ;print newline 
        mov dx, offset newline
        print_output
        
        sub si, si           ;zero the si for increment   
        mov di, bx 
        dec di
         
        ;check for 1 character
        mov cx, bx;    
        cmp cx, 1
        je print_yes
                              
                              
        mov bx, offset input+2        ;get the string into bx    
        shr cx, 1                    ;divide cx by 2 by shifting to right 1 bit.
    
        myloop:
            mov al, [bx+di]
            mov dl, [bx+si]     
            cmp al, dl
            jne print_no
            inc si
            dec di  
        loop myloop  
                                               
        
    print_yes:
        mov dx, offset MSG_isPalindrom
        print_output
        jmp part2_loop
    
    print_no:
        mov dx, offset MSG_notPalindrom
        print_output
        jmp part2_loop
        
    stop:
        ; wait for any key...
        
        mov dx, offset MSG_any_key
        print_output
        
        mov ax, 0 
        int 16h
        
        ret
    
    
    MSG_prompt_part2        db  "-------------------------------------------------------------------------------",13,10,13,10
                        db  "Enter a String: "
                        db  "$"  
    
    MSG_part2                db  "--Part 2--",13,10
                        db  "* This program to check palindrome string by :",13,10
                        db  "* Rusydi Hasan Makarim (0721051)*",13,10
                        db  "* Cutifa Safitri (072656)       *",13,10
                        db  "* Haroon Shoukat Ali (0629753)  *",13,10
                        db  "*                               *",13,10
                        db  "*Press <Enter> to exit          *",13,10
                        db "$"
    MSG_urstris            db  "Your input string is $"
    MSG_isPalindrom        db  "PALINDROME !",13,10,'$'
    MSG_notPalindrom    db  "NOT A PALINDROME!",13,10,'$'
    input                db  100,?, 100 dup(' ')  ;used for scan_input
    newline                db  13,10,'$'
    MSG_any_key            db "Press any key to terminate$"
    
    end
    
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice