Assembly Program Help using Assembly Language for x86 Processors -by Kip Irvine
ID: 3861782 • Letter: A
Question
Assembly Program Help
using Assembly Language for x86 Processors -by Kip Irvine Library
Need help finishing this assignment:
Simple Assembly Menu with the following options
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
TITLE menu.asm
include irvine32.inc
clearEAX TEXTEQU
clearEBX TEXTEQU
clearECX TEXTEQU
clearEDX TEXTEQU
clearESI TEXTEQU
clearEDI TEXTEQU
.data
prompt1 byte 'MAIN MENU', 0ah, 0dh,
'=========', 0ah, 0dh,
'1. Enter a string', 0Ah, 0Dh,
'2. Convert the string to lower case', 0Ah, 0Dh,
'3. Remove all non-letter elements', 0Ah, 0Dh,
'4. Is the string a palindrome?', 0Ah, 0Dh,
'5. Print the string', 0Ah, 0Dh,
'6. Quit', 0Ah, 0Dh, 0h
oops byte 'Invalid Entry. Please try again.', 0h
UserInput byte 0h
theString byte 50 dup(0h),0h
theStringlen byte 0h
.code
main PROC
clearEAX
clearEBX
clearECX
clearEDX
clearESI
clearEDI
starthere: ; MAIN LOOP
call clrscr
mov edx, OFFSET prompt1
call WriteString
call ReadDec
mov userinput, al
opt1: ; option 1 : Enter a string
cmp userinput, 1
jne opt2
mov edx, OFFSET theString
mov ecx, LENGTHOF theString
call option1
mov theStringLen, al
jmp starthere
;Menu options
opt2: ; option 2: Convert the string to lower case
cmp userinput, 2
jne opt3
mov edx, OFFSET theString ; offset of the string for option 2, the length of user input string
movzx ecx, theStringLen ; length of string
call option2
jmp starthere
opt3: ; option 3: Remove all non-letter elements
cmp userinput, 3
jne opt4 ; if not option 3 go to option 4
mov edx, OFFSET theString ; offset of string
movzx ecx, theStringLen ; length of string
call option3
jmp starthere
opt4: ; option 4: Is it a palindrome
cmp userinput, 4
jne opt5 ; if not option 4 go to option 5
mov edx, OFFSET theString ; offset of string
movzx ecx, theStringLen ; length of string
call option4
jmp starthere
opt5: ; option 5: Print the String
cmp userinput, 5
jne opt6 ; if not option 5 got to option 6
mov edx, OFFSET theString ;offset of string to play with
call WriteString
jmp starthere
opt6: ; option 6: Quit
cmp userinput, 6
je theEnd ; jump if equal
mov edx, OFFSET oops ; if user enters an invalid entry from not in the menu options
call WriteString
call Waitmsg
jmp starthere
theEnd:
call WaitMsg
exit
main ENDP
;====================================================
option1 PROC uses EDX ECX
;Desc: Prompts the user to enter a string.
; User entered string will be stored in
; the array passed in EDX
;Receives: edx - offset of the string
; ecx - max length of the string
;Returns: eax - number of chars entered by the user
;=====================================================
.data
opt1prompt byte "Please enter a string.", 0Ah, 0Dh, "------> ", 0h
.code
push edx
mov edx, offset opt1prompt
call WriteString
pop edx
call ReadString
ret
option1 ENDP
// TO DO
option2 PROC
ret
option2 ENDP
option3 PROC
ret
option3 ENDP
option4 PROC
ret
option4 ENDP
option5 PROC
ret
option5 ENDP
option6 PROC
ret
option6 ENDP
end main
Explanation / Answer
Answer:
Assembly Language Code:
.LC0:
.string "Enter the String in uppercase : "
.LC1:
.string " The String in Lowercase = "
main:
push rbp
mov rbp, rsp
push rbx
sub rsp, 40
mov esi, OFFSET FLAT:.LC0
mov edi, OFFSET FLAT:std::cout
call std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)
lea rax, [rbp-48]
mov rdi, rax
call gets
mov DWORD PTR [rbp-20], 0
.L4:
mov eax, DWORD PTR [rbp-20]
movsx rbx, eax
lea rax, [rbp-48]
mov rdi, rax
call strlen
cmp rbx, rax
ja .L2
mov eax, DWORD PTR [rbp-20]
cdqe
movzx eax, BYTE PTR [rbp-48+rax]
cmp al, 64
jle .L3
mov eax, DWORD PTR [rbp-20]
cdqe
movzx eax, BYTE PTR [rbp-48+rax]
cmp al, 92
jg .L3
mov eax, DWORD PTR [rbp-20]
cdqe
movzx eax, BYTE PTR [rbp-48+rax]
add eax, 32
mov edx, eax
mov eax, DWORD PTR [rbp-20]
cdqe
mov BYTE PTR [rbp-48+rax], dl
.L3:
add DWORD PTR [rbp-20], 1
jmp .L4
.L2:
mov esi, OFFSET FLAT:.LC1
mov edi, OFFSET FLAT:std::cout
call std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)
mov rdx, rax
lea rax, [rbp-48]
mov rsi, rax
mov rdi, rdx
call std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)
mov eax, 0
add rsp, 40
pop rbx
pop rbp
ret
__static_initialization_and_destruction_0(int, int):
push rbp
mov rbp, rsp
sub rsp, 16
mov DWORD PTR [rbp-4], edi
mov DWORD PTR [rbp-8], esi
cmp DWORD PTR [rbp-4], 1
jne .L8
cmp DWORD PTR [rbp-8], 65535
jne .L8
mov edi, OFFSET FLAT:std::__ioinit
call std::ios_base::Init::Init()
mov edx, OFFSET FLAT:__dso_handle
mov esi, OFFSET FLAT:std::__ioinit
mov edi, OFFSET FLAT:std::ios_base::Init::~Init()
call __cxa_atexit
.L8:
nop
leave
ret
_GLOBAL__sub_I_main:
push rbp
mov rbp, rsp
mov esi, 65535
mov edi, 1
call __static_initialization_and_destruction_0(int, int)
pop rbp
ret
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.