| | |
Help on Storing Strings from Keyboard...
![]() |
•
•
Join Date: Apr 2007
Posts: 15
Reputation:
Solved Threads: 0
Hey I am doing a program in palindromes.
Don't worry, I dont want any code (I read the sticky). But this is my first semester using it, and my second program. I am having trouble in storing the word from the user. Right now it only stores one character. How can I make it save the entire word? What am I doing wrong?
Should I save the word one letter at a time in a loop so I can make it go in reverse order? Using Pops and Pushes?
I am using Tasm. Here is my code for reference
[code = language][inline code]
MSG1 DB ' Enter a word $'
theword db 20 dup( ' '), 0
ItIs DB 'The word is a Palindrome $'
ItIsNot DB 'The word is not a Palindrome $'
....
....
GetPut:
lea dx,MSG1 ;addr. of 1st msg
mov ah,9 ;set for str. displ.
int 21H ;call DOS to displ.
;DISPLAY MESSAGE ABOVE;
mov ah,1 ;set func. to Get
int 21H ;call DOS (val-AL)
;USER ENTERS STRING ABOVE;
mov theword,al ;move input to theword
lea dx,theword ;move the word to dx register
mov ah,9 ;move 9 to ah signaling output
int 21h ;call the interrupt
[/inlinecode]
[\code]
The current output is that it only allows me to type in one letter. Then the letter is echo'd (with no space in between). And the string that the word is a palindrome
If someone can show me how to have the user entered a string from they keyboard, and how I store it, that will be a big help.
Don't worry, I dont want any code (I read the sticky). But this is my first semester using it, and my second program. I am having trouble in storing the word from the user. Right now it only stores one character. How can I make it save the entire word? What am I doing wrong?
Should I save the word one letter at a time in a loop so I can make it go in reverse order? Using Pops and Pushes?
I am using Tasm. Here is my code for reference
[code = language][inline code]
MSG1 DB ' Enter a word $'
theword db 20 dup( ' '), 0
ItIs DB 'The word is a Palindrome $'
ItIsNot DB 'The word is not a Palindrome $'
....
....
GetPut:
lea dx,MSG1 ;addr. of 1st msg
mov ah,9 ;set for str. displ.
int 21H ;call DOS to displ.
;DISPLAY MESSAGE ABOVE;
mov ah,1 ;set func. to Get
int 21H ;call DOS (val-AL)
;USER ENTERS STRING ABOVE;
mov theword,al ;move input to theword
lea dx,theword ;move the word to dx register
mov ah,9 ;move 9 to ah signaling output
int 21h ;call the interrupt
[/inlinecode]
[\code]
The current output is that it only allows me to type in one letter. Then the letter is echo'd (with no space in between). And the string that the word is a palindrome
If someone can show me how to have the user entered a string from they keyboard, and how I store it, that will be a big help.
Last edited by gparadox; Apr 26th, 2007 at 3:09 pm.
•
•
Join Date: Apr 2007
Posts: 15
Reputation:
Solved Threads: 0
OK I figured out how to store string input.
but the output disappears, I want it to stay.
Now I need an idea of how to check if it is an palindrome or not.
but the output disappears, I want it to stay.
Assembly Syntax (Toggle Plain Text)
TITLE Proj2 PAGE 56,90 ; file: Proj2.asm ; author: xxxxx ; date: 04/26/07 ; Based on: xxxxx ; ; ---------------------------------------- ; ---------------------------------------- .MODEL SMALL .STACK 100H .DATA CR EQU 0DH ; Carriage Return Code LF EQU 0AH ; Line Feed Control Code DOSEXIT EQU 4CH ; DOS exit code for 21h int para_list LABEL BYTE max_len db 20 act_len db ? theword db 20 DUP(' ') MSG1 DB 'Enter a word $' ItIs DB 'The word is a Palindrome $' ItIsNot DB 'The word is not a Palindrome $' ; --------- End of Data Segment ---------- .CODE Main PROC ;------------------------------------------ ; The routine performs basic ; "housekeeping" operations necessary in ; any Assembly Language Program running ; under DOS or Windows... ; 1 - Establish Addressability to the ; Data Segment of the program. ;------------------------------------------ HouseKeeping: mov ax,@data ;get addr. of DSeg. mov ds,ax ;set in DS Reg. ;------------------------------------------ ; Routine "GetPut" will... ; 1 - Display prompt message. ; 2 - capture user provided ASCII ; letter (located in AL register). ; 3 - Convert the letter to it's decimal ; equivalent. ; 4 - Display the converted letter within ; an "echoing" message. ;------------------------------------------ Prompt: lea dx,MSG1 ;addr. of 1st msg mov ah,9h ;set for str. displ. int 21H ;call DOS to displ. ;DISPLAY MESSAGE ABOVE; GetWord: mov ah,0Ah ;set func. to Get String lea DX,Para_list ;load address of para list int 21H ;call DOS (val-AL) mov theword,al ;move input to theword lea dx,theword mov ah,9 int 21h ;------------------------------------------ ; The routine sets the exit code and ; calls DOS. This is the appropriate ; technique for terminating a non- ; resident program running under DOS. ;------------------------------------------ PgmExit: mov ah,DOSEXIT ;set Exit code int 21H ;and call DOS Main EndP End Main
Now I need an idea of how to check if it is an palindrome or not.
Last edited by gparadox; Apr 26th, 2007 at 7:12 pm. Reason: to put it in code format
•
•
Join Date: Apr 2007
Posts: 15
Reputation:
Solved Threads: 0
For some reason it is writing it backwards, but it skips the first letter. If I enter georgios, it will display 'soigroe'.
Any idea why it is skipping the first letter?
Any idea why it is skipping the first letter?
Assembly Syntax (Toggle Plain Text)
TITLE Proj2 PAGE 56,90 ; file: Proj2.asm ; author: Georgios Zavolas ; date: 04/26/07 ; Based on: j dzubacks work ; I used your Lab05 as a template for this ; ---------------------------------------- ; ; ; This program will take a name entered by the user ; and display it backwards. It will also tell the ; user whether the word is a palindrome or not. ; ---------------------------------------- .MODEL SMALL .STACK 100H .DATA CR EQU 0DH ; Carriage Return Code LF EQU 0AH ; Line Feed Control Code DOSEXIT EQU 4CH ; DOS exit code for 21h int para_list LABEL BYTE max_len db 20 act_len db ? theword db 20 DUP(' ') MSG1 DB 'Enter a word $' ItIs DB 'The word is a Palindrome $' ItIsNot DB 'The word is not a Palindrome $' MSG2 DB 'The word backwards is $' wordbw DB 12 DUP(20H),'$' ; --------- End of Data Segment ---------- .CODE Main PROC ;------------------------------------------ ; The routine performs basic ; "housekeeping" operations necessary in ; any Assembly Language Program running ; under DOS or Windows... ; 1 - Establish Addressability to the ; Data Segment of the program. ;------------------------------------------ HouseKeeping: mov ax,@data ;get addr. of DSeg. mov ds,ax ;set in DS Reg. ;------------------------------------------ ; Routine "GetPut" will... ; 1 - Display prompt message. ; 2 - capture user provided ASCII ; letter (located in AL register). ; 3 - Convert the letter to it's decimal ; equivalent. ; 4 - Display the converted letter within ; an "echoing" message. ;------------------------------------------ Prompt: lea dx,MSG1 ;addr. of 1st msg mov ah,9h ;set for str. displ. int 21H ;call DOS to displ. mov ah, 06h mov al,00h int 10h ;DISPLAY MESSAGE ABOVE; GetWord: mov ah,0Ah ;set func. to Get String lea DX,Para_list ;load address of para list int 21H ;call DOS (val-AL) mov theword,al ;move input to theword ;Clear Screen mov ax,0600h mov bh,07 mov cx,0000 mov dx,184fh int 10h ;Clear Screen ChangeWord: CLD MOV CX,20 LEA SI,theword LEA DI,wordbw+11 L20: LODSB MOV [DI],AL DEC DI LOOP L20 ;Clear Screen mov ax,0600h mov bh,07 mov cx,0000 mov dx,184fh int 10h ;Clear Screen lea dx, wordbw mov ah,9 int 21h ;------------------------------------------ ; The routine sets the exit code and ; calls DOS. This is the appropriate ; technique for terminating a non- ; resident program running under DOS. ;------------------------------------------ PgmExit: mov ah,DOSEXIT ;set Exit code int 21H ;and call DOS Main EndP End Main
![]() |
Similar Threads
- Creating a Basic String Database (C++)
- Strings Program (C++)
- Having trouble displaying an Arrays. Please help. (C)
- Array/String intersect and Array/Array intersect code (C#)
- only a couple of hours to go... (C++)
- How do I create a program using an Array ? (C++)
- JSP and Oracle (JSP)
Other Threads in the Assembly Forum
- Previous Thread: Assembly Help in Programming
- Next Thread: 8086 Assembly Problems Help
| Thread Tools | Search this Thread |





