Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help me finish assembly code: Create a menu for a program as shown below. Option 1 will request a string from the user. This

Please help me finish assembly code:

Create a menu for a program as shown below.

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.

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

the Code:

TITLE MENU.asm

Include Irvine32.inc

;//Macros ClearEAX textequ ClearEBX textequ ClearECX textequ ClearEDX textequ ClearESI textequ ClearEDI textequ maxLength = 51d

.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 opt3: 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

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

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Fundamentals Of Database Management Systems

Authors: Mark L. Gillenson

2nd Edition

0470624701, 978-0470624708

More Books

Students also viewed these Databases questions