. Reverse a String “Towson University” with the following requirements: Use a lo
ID: 3770024 • Letter: #
Question
. Reverse a String “Towson University” with the following requirements:
Use a loop with indexed addressing
Push each character to the stack
Start at the beginning of the string, pop the stack in reverse order, insert each character back into the string
As a result, your output should be as follows.
Insert the following lines to display a string:
edx,OFFSET <variable name>
Writestring
Insert the following line to generate a new line:
crlf ; new-line creater
Prerequisite for Step2:
ReadString (from Irvine32 Library) The ReadString procedure reads a string from the keyboard, stopping when the user presses the Enter key. Pass the offset of a buffer in EDX and set ECX to the maximum number of characters the user can enter, plus 1 (to save space for the terminating null byte). The procedure returns the count of the number of characters typed by the user in EAX. Sample call:
.data
buffer BYTE 21 DUP(0) ; input buffer
byteCount DWORD ? ; holds counter
.code
mov edx,OFFSET buffer ; point to the buffer
mov ecx,SIZEOF buffer ; specify max characters
call ReadString ; input the string
mov byteCount,eax ; number of characters
ReadString automatically inserts a null terminator in memory at the end of the string. The following is a hexadecimal and ASCII dump of the first 8 bytes of buffer after the user has entered the string “ABCDEFG”:
41 42 43 44 45 46 47 00 ABCDEFG
The variable byteCount equals 7.
Step2. Extend Step1 to get a string from an user using ReadString procedure. Please comment out the declarations of variables used in Step1 rather than deleting them. Your output should be shown as below.
Step3. Write a program that does the following:
Assigns integer values to EAX, EBX, ECX, EDX, ESI, EDI, EBP
Use PUSHAD to push the general-purpose registers on the stack
Using a loop, your program should pop each integer from the stack and display it on the screen
Insert the following lines to display integers:
WriteDec ; load a decimal value currently stored in EAX register
crlf
Your output for this step should be as follows except the fourth value. Specifically, you have to know the order in which registers are pushed onto the stack.
Prerequisite for Step4:
WriteDec (from Irvine32 Library) The WriteDec procedure writes a 32-bit unsigned integer to the console window in decimal format with no leading zeros. Pass the integer in EAX. Sample call:
mov eax,295
call WriteDec ; displays: "295"
Step4. Create a procedure satisfying the following requirements:
Calculates and returns the sum of three 32-bit integers.
Receives: EAX, EBX, the two integers. May be signed or unsigned.
Returns: EBX = sum of EAX to EBX. e.g., if EAX=1 and EBX=10, the summation of this procedure should be 55.
Requires: nothing but EAX and EBX should be set before called.
Step5. All the steps should be done in one asm file. Comment all your source codes to let me know which part is involved in which step. Submit only single .asm file to blackboard.
Note: Save your work to a file and keep it for your recor
Explanation / Answer
Managed by the CPU, using two registers
SS (stack segment)
ESP (stack )
PUSH syntax:
PUSH r/m16
PUSH r/m32
PUSH imm32
Save and restore registers when they contain important values. PUSH and POP instructions occur in the opposite order.
push esi ; push registers
push ecx
push ebx
mov esi,OFFSET dwordVal ; display some memory
mov ecx,LENGTHOF dwordVal
mov ebx,TYPE dwordVal
call DumpMem
pop ebx ; restore registers
pop ecx
pop esi
Use a loop with indexed addressing
Push each character on the stack
Start at the beginning of the string, pop the stack in reverse order, insert each character back into the string
Source code
PUSHFD and POPFD
push and pop the EFLAGS register
PUSHAD pushes the 32-bit general-purpose registers on the stack
order: EAX, ECX, EDX, EBX, ESP, EBP, ESI, EDI
POPAD pops the same registers off the stack in reverse order
PUSHA and POPA do the same for 16-bit registers
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.