Question
In class Project & Homework Assignment. Create a menu for a program as shown below. (This will be done in class) Option 1 will request
In class Project & Homework Assignment.
Create a menu for a program as shown below. (This will be done in class) Option 1 will request a string from the user. This string may contain any character on the keyboard, both upper and lowercase letters (for now the strings are limited to a length of 50 characters). Option 2 will convert all elements of the string to lower case. Option 3 will remove all non-letter elements. Option 4 will determine if the string is a palindrome. Option 5 will display the string to the screen. Option 6 exits the program. If the user enters something other than 1 6 there should be an error displayed to the screen. We will develop the menu in class. Your homework will be to complete the functionality of the program. All the menu options dealing with strings require an offset to the input string to be passed to a procedure. At the end of every string procedure, the original string will reflect the changes caused by a given option. For example: If the user input string is : a#d A&B. After Option 2 is executed: The original string will reflect the changes and be: a#d a&b. After Option 3 is executed: The string will reflect the changes and be: adab A string must be entered before any string modifications can take place. You must create your own procedures to copy a string, compare a string, convert a string to uppercase, clear a string. Use of Irvine Library functions to copy a string or compare a string is specifically not allowed for this program. You may only use the following Irvine Library string operations: ReadString and WriteString. All other non-string Irvine Library procedures are available for your use. Do not use DumpRegs except for troubleshooting. DumpRegs should not be in a program submitted for grading. Menu 1. Enter a string
2. Convert the string to lower case
3. Remove all non-letter elements
4. Is it a palindrome?
5. Print the string
6. Quit
So far I have
Include Irvine32.inc
;//Macros ClearEAX textequ
.data Menuprompt1 byte 'MAIN MENU', 0Ah, 0Dh, '==========', 0Ah, 0Dh, '1. Enter a String:', 0Ah, 0Dh, '2. Convert all elements to lower case: ',0Ah, 0Dh, '3. Remove all non-letter elements: ',0Ah, 0Dh, '4. Determine if the string is a palindrome: ',0Ah, 0Dh, '5. Display the string: ',0Ah, 0Dh, '6. Exit: ',0Ah, 0Dh, 0h UserOption byte 0h theString byte maxLength dup(0) theStringLen byte 0 errormessage byte 'You have entered an invalid option. Please try again.', 0Ah, 0Dh, 0h
.code main PROC
call ClearRegisters ;// clears registers startHere: call clrscr mov edx, offset menuprompt1 call WriteString call readhex mov useroption, al
mov edx, offset theString mov ecx, lengthof theString opt1: cmp useroption, 1 jne opt2 call clrscr mov ebx, offset thestringlen call option1 jmp starthere
opt2: cmp useroption, 2 jne opt3 call clrscr movzx ecx, thestringlen call option2 jmp starthere
;;line 72 80 and probrably other errors opt3: cmp useroption, 3 jne opt5 call clrscr call option3 jmp starthere
opt5: cmp useroption, 5 jne opt6 call option5 jmp starthere opt6: cmp useroption, 6 jne oops jmp quitit oops: push edx mov edx, offset errormessage call writestring call waitmsg pop edx jmp starthere
quitit: exit main ENDP ;// Procedures ;// =============================================================== ClearRegisters Proc ;// Description: Clears the registers EAX, EBX, ECX, EDX, ESI, EDI ;// Requires: Nothing ;// Returns: Nothing, but all registers will be cleared.
cleareax clearebx clearecx clearedx clearesi clearedi
ret ClearRegisters ENDP ;// --------------------------------------------------------------- option1 proc uses edx ecx .data option1prompt byte 'Please enter a string of characters (50 or less): ', 0Ah, 0Dh, '--->', 0h
.code push edx ;//saving the address of the string mov edx, offset option1prompt call writestring pop edx
;//add procedure to clear string (loop through and place zeros)
call readstring mov byte ptr [ebx], al ;//length of user entered string, now in thestringlen
ret option1 endp
option2 proc uses edx ebx L2: mov al, byte ptr [edx+esi] cmp al, 41h jb keepgoing cmp al, 5ah ja keepgoing or al, 20h ;//could use add al, 20h mov byte ptr [edx+esi], al keepgoing: inc esi loop L2 ret option2 endp
option3 proc uses edx ebx ecx .data count byte 0 tmpArr byte 50 dup(?) ,0h .code
mov ecx, lengthOf theString mov esi, OFFSET theString L3: mov al, [esi] ;mov al, byte ptr [edx + esi] cmp al, 61h ;compares lower letter a jl continue cmp al, 7ah ;compares letter is <= z jg continue
inc esi inc count push eax
; for upper case continue: inc esi
loop L3
mov cl, count mov esi, offset tmpArr tmpLoop: pop eax mov [esi], al inc esi loop tmpLoop
mov esi, offset tmpArr mov cl, count pushBack: mov al, [esi] push eax
loop pushBack
;its all in the temp array now to move it back ;clear the string mov cl, count
mov edx, OFFSET theString stringFix: pop eax mov [edx], al
loop stringFix ;mov edx, OFFSET theString ret option3 endp
option5 proc uses edx .data option5prompt byte 'The String is: ', 0h .code call clrscr push edx mov edx, offset option5prompt call writestring pop edx call writestring call waitmsg ret option5 endp
END main
;procedure 3 won't print out the edited string when option 5 is called
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started