1 Replies - 5240 Views - Last Post: 10 March 2011 - 02:20 PM

#1 wale89   User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 21
  • Joined: 30-September 09

how to restrict input to 6 character string

Posted 10 March 2011 - 06:29 AM

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. In which line do I have to change it? Can someone help me??
Give me some guide...since i am a beginners in Assembly..thank you very much..

This are the 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

part1:
	;print the main message of program1
    mov dx, offset MSG_part1
    print_output
part1_loop:

    ;print the message to promt the user to enter the string
    mov dx, offset MSG_prompt_part1
    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
	
    mov dx, offset input+2     ; print just string which located in the third place of ofset.
    print_output
       
    ;print newline 
    mov dx, offset newline
    print_output                  
	
	jmp part1_loop

stop:
    ; wait for any key...
	
	mov dx, offset MSG_any_key
	print_output
	
    mov ax, 0 
    int 16h
    
    ret



MSG_prompt_part1		db  "-------------------------------------------------------------------------------",13,10,13,10
					db  "Please enter your string here: "
					db  "$"  

MSG_part1				db  "--Part 1--",13,10
					db  "* This program to echo your keyboard entry by :",13,10
					db  "* John    *",13,10
					db  "* Chris   *",13,10
					db  "*                               *",13,10
					db  "*Press <Enter> to exit          *",13,10
					db "$"
MSG_urstris    		db  "Your input string is $"
input				db  100,?, 100 dup(' ')  ;used for scan_input
newline				db  13,10,'$'
MSG_any_key			db "Press any key to terminate$"

end





Is This A Good Question/Topic? 0
  • +

Replies To: how to restrict input to 6 character string

#2 ishkabible   User is offline

  • spelling expret
  • member icon





Reputation: 1747
  • View blog
  • Posts: 5,898
  • Joined: 03-August 09

Re: how to restrict input to 6 character string

Posted 10 March 2011 - 02:20 PM

i would just use scanf.

;assume that .msg is the constant "%6s" and .str is the place you want to store the string
push .str
push .msg
call [scanf]


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1