Solve each of the following problems. To receive full marks on your documentatio
ID: 3701213 • Letter: S
Question
Solve each of the following problems. To receive full marks on your documentation, you should have excellent internal documentation (i.e, appropriate comments, but also choice of variable names), as well as excellent extemal documentation (ie, in the readme.txt file as described previously). 1. [60 points] Using the String Reverse program as a starting point [find this asm file uploaded on eCourse: a) Modify the program so the user can input a string containing between 1 and 50 characters b) Modify the program so it inputs a list of 32-bit integers from the user, and then displays the integers in reverse order 2. 40 points] Write a program that does the following: a. Assigns integer values to EAX, EBX, ECX, EDX, ESI, and EDI b. Uses PUSHAD to push the general-purpose registers on the stack c. Using a loop, your program should pop each integer from the stack and display it on the screenExplanation / Answer
1.a) getting string from user input:
TITLE Reversing a String (RevStr.asm)
; This program reverses a string.
INCLUDE Irvine32.inc
.data
aname BYTE 50 DUP(0)
.code
main PROC
; Push the name on the stack.
Mov edx,OFFSET aname
mov ecx, SIZEOF aname-1
call ReadString
L1: movzx eax, aName[esi] ; get character
push eax ; push on stack
inc esi
loop L1
; Pop the name from the stack, in reverse,
; and store in the aName array.
mov ecx, SIZEOF aname-1
mov esi, 0
L2: pop eax ; get character
mov aName[esi], al ; store in string
inc esi
loop L2
; Display the name.
mov edx,OFFSET aName
call Writestring
call Crlf
exit
main ENDP
END main
1 b) integer
TITLE Reversing a String (RevStr.asm)
; This program reverses a integer.
INCLUDE Irvine32.inc
.data
str1 BYTE "Enter a signed integer: ",0
array DWORD INTEGER_COUNT DUP(?)
.code
main PROC
mov esi,OFFSET array
mov ecx,INTEGER_COUNT
call PromptForIntegers
L1: movzx eax, [esi] ; get character
push eax ; push on stack
inc esi
loop L1
mov ecx,
mov esi, 0
L2: pop eax ; get character
mov [esi], al ; store in string
inc esi
loop L2
; Display the name.
mov edx,OFFSET array
call Writestring
call Crlf
exit
main ENDP
END main
PromptForIntegers PROC USES ecx edx esi
mov edx,OFFSET str1 ; "Enter a signed integer"
L1: call WriteString ; display string
call ReadInt ; read integer into EAX
call Crlf ; go to next output line
mov [esi],eax ; store in array
add esi,TYPE DWORD ; next integer
loop L1
ret
PromptForIntegers ENDP
2 a) ANSWER
PromptForIntegers PROC USES ecx edx esi
; Prompts the user for an arbitrary number of integers
; and inserts the integers into an array.
; Receives: ESI points to the array, ECX = array size
; Returns: nothing
;-----------------------------------------------------
mov edx,OFFSET str1 ; "Enter a signed integer"
L1: call WriteString ; display string
call ReadInt ; read integer into EAX
call Crlf ; go to next output line
mov [esi],eax ; store in array
add esi,TYPE DWORD ; next integer
loop L1
ret
PromptForIntegers ENDP
2 b) ANSWER:
if(OperandSize = 32) { //PUSHAD instruction
Temporary = ESP;
Push(EAX);
Push(ECX);
Push(EDX);
Push(EBX);
Push(Temporary);
Push(EBP);
Push(ESI);
Push(EDI);
}
2 c) ANSWER
.code
mov ecx,10 ; loop counter
L1: mov eax,100; ceiling value
call RandomRange ; generate random int
call WriteInt ; display signed int
call Crlf ; goto next display line
loop L1 ; repeat loop
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.