Good afternoon, how are yo all doing? I know that this is probably easy but I am missing something here. I have this assembly program that will display a menu a user enters there choice and based on the choice the program will jump to another part of the program. Right now I am working on the user picking the option to enter a sentence. But when I pick the choice or option and I jump to the lable of that part of the program to prompt the user the program will prompt for always for the sentence no matter what option in the menu I pick. I pick a number like a character to search for and it won't output the prompt for the character it will output for the sentence again. Why is it only prompting for the sentence when based on the option I am jumping to different parts of the program? How do I fix it? Thanks
Posted on 2004-10-04 07:20:01 by skull_block
The fix would depend very much upon the code, which we cannot see.
You'll get more help if you:
1) Post the code (if it's big cut it down to the essence of the problem).
2) Explain where you think your error is, and why you've come to that conclusion.

By doing both of these things, nine times out of ten you'll find the error yourself.

The problem you are seeing could be down to a myriad of reasons, check for buffers overflowing or not being updated properly, ensure that your code is jumping to the proper place (and returns correctly at the end).

Try breaking the problem down into sub-parts, make sure each sub-part works, then just put those sub-parts together. This makes things easier as you can debug a simple part without the overhead of all new-code, then if the error occurs when you've put the blocks together the only place the error can be is in the "glue".

Mirno
Posted on 2004-10-04 08:56:40 by Mirno
Thanks I should of figured you needed the code. I have been trying to break it down into smaller subs and one subs at a time. I will try some more and maybe post the code. Thanks
Posted on 2004-10-04 09:08:21 by skull_block
I have a really quick question I am new to assembly so I am still learning. How would you know if it is a buffer overflow? Thanks Or being updated?
Posted on 2004-10-04 09:22:29 by skull_block
Hello everyone. Here is my code and I can't understand when I pick either option 1 or 2 it just ask me the prompt to enter a sentence. Now remember don't laugh at me I am just learning MASM assembly. Thanks for all your help


Include C:\MASM615\Pcmac.inc
.Model small ;Small memory model
.586 ;Pentium Instruction set
.Stack 100h ;Stack area saves 256bytes

.Data
OutMessage Db 'Welcome to the search program',13,10,'$'
PromptChoice Db 'What would you like to do $'
Choice Db ?
Newline Db 13,10,'$'
OutSearch Db '1 Type a sentence and press entere when finished',13,10,'$'
outChar Db '2 Pick a character in the sentence you just typed to search for',13,10,'$'
Outlength Db '3 Find the length of the sentence you have type',13,10,'$'
Outsymbol Db '4 Pick a symbol,letter, or number in the sentence you just typed to replace the searched character',13,10,'$'
Outcapital Db '5 Capitalize all the letters in the sentence',13,10,'$'
OutExit Db '6 Exit the program',13,10,'$'
PromptString Db 'Enter a sentence and press enter when finished: $'
Buffer Db 15
string Db 15 dup ('?')
Promptchar Db 'Enter a character in the sentence to search for: $'
Buffer1 Db 5
Char1 Db 5 dup ('?')
PromptError Db 'Please enter one of the values giving, thank you $'
OutBlankStr Db 'There is no string to search',13,10,'$'
Total_It Db 'The total number of character in sentence is: $'




.code
EXTRN Getdec : Near, PutDec : Near
Search Proc
push ax
push bx
push cx
push dx
_Begin
theLoop:
_Putstr Newline
_PutStr OutMessage
_PUtStr PromptChoice
_PutStr Newline
_PutStr OutSearch
_PutStr Newline
_PutStr OutChar
_PutStr Newline
_PutStr Outlength
_PUtStr Newline
_PutStr OutSymbol
_PutStr Newline
_PutStr Outcapital
_PutStr Newline
_PutStr OutExit
call Getdec
jnc Goodnum
_Putstr PromptError
_Getch noEcho
cmp al,13
je theLoop
Goodnum:
mov al,Choice
cmp al,1
je Stringsearch
cmp al,2
je BeginChar
cmp al,3
cmp al,4
cmp al,5
cmp al,6
je Leave1


Stringsearch:
mov dx,Offset PromptString
mov ah,09h
int 21h
mov ah,0ah
mov dx,Offset Buffer
int 21h
jmp theLoop

BeginChar:
mov dx,Offset Promptchar
mov ah,09h
int 21h
mov ah,0ah
mov dx,Offset Buffer1
int 21h

Leave1:
pop dx
pop cx
pop bx
pop ax
_Exit 0;
Search ENDP
End Search







Posted on 2004-10-04 19:28:02 by skull_block


cmp al,3
cmp al,4
cmp al,5
cmp al,6
je Leave1

Stringsearch:
mov dx,Offset PromptString
mov ah,09h
int 21h


The cmp instructions for 3, 4, and 5, the results are thrown away. This means that only if AL is 6 does the code jump to exit. When the jump to exit is not taken the processor will carry on to the next instruction, in this case the "mov dx, Offset PromptString".

In other words, options 2 leads to BeginChar, 6 leads to Leave1, and ALL OTHERS lead to Stringsearch!

Note you'll suffer a similar problem with BeginChar as you've forgotten the jmp at the end of this code.

Also you may want to tidy up your menu like this:


OutMenu Db 'Welcome to the search program', 13, 10
Db 'What would you like to do', 13, 10
Db '1 Type a sentence and press entere when finished', 13, 10
Db '2 Pick a character in the sentence you just typed to search for', 13, 10
Db '3 Find the length of the sentence you have type', 13, 10
Db '4 Pick a symbol,letter, or number in the sentence you just typed to replace the searched character', 13, 10
Db '5 Capitalize all the letters in the sentence', 13, 10
Db '6 Exit the program'
NewLine Db 13, 10,'$'
...
.code
...
theLoop:
_Putstr NewLine
_Putstr OutMenu

By not putting the '$' terminator on the end of each line it becomes one very long string (the 13, 10 being carrage returns). This may or may not work, I've never really done DOS assembly programming, and certainly never used the _Putstr macro you've got here.

Mirno
Posted on 2004-10-05 05:46:03 by Mirno
I think you are missing out the following



mov ax, @data
mov ds, ax
Posted on 2004-10-05 06:40:41 by roticv
I assume your "Getch" macro returns the character typed in?

Then you must realize that it returns the character's ASCII code.

Finally you must realize that putting:
cmp al,1
compares it to the number 1, and that
cmp al,'1'
compares it to the ASCII code of the CHARACTER "1"
Posted on 2004-10-07 22:24:08 by AmkG
AmkG:
If I'm reading the code correctly, the _getch macro is only called if there is 'bad input':



call Getdec <----
jnc Goodnum <----
_Putstr PromptError
_Getch noEcho
cmp al,13
je theLoop
Goodnum: <----
mov al,Choice


So it's the result of the Getdec call that is of interest here. What I'm wondering is how Choice gets filled in...it doesn't appear to occur in the code anywhere prior to its use above. If it is ASCII-coded, then it does need to be '1','2', etc., like AmkG said.

skull_block:
I don't quite understand the part in the segment of code above with "cmp al,13 / je theLoop"...if you have bad input wouldn't you always want to jmp back to the top after displaying the error prompt? The way it's coded now, if al wasn't 13 for some reason following _Getch, your program would go on to Goodnum...
Posted on 2004-10-07 23:34:23 by sirchess
Hmm, you're right

So skull_block... what exactly does Getdec return, and where does it return it? We might assume that it returns the numeric equivalent of a typed decimal number, and that it returns the number in Choice, but is the source available? Where exactly does Choice put its data?

Come to think of it, the only reference to Choice I've seen is:
mov al,Choice

So Choice is, apparently, initialized to a random number (via Choice db ?), presumably 1 in this case?
Posted on 2004-10-07 23:51:27 by AmkG
Thanks for the help everyone. I have figured out what I was doing wrong. I really appreciate it. :)
Posted on 2004-10-09 09:41:38 by skull_block