Need help to write a code in assembly languague (kip irvine32). Read in a string
ID: 3815199 • Letter: N
Question
Need help to write a code in assembly languague (kip irvine32). Read in a string from the user (up to 50 characters). Reverse the contents of the string. Display the string. USE STACK. I got how to reverse the string but not how to implement the STACK.
TITLE MASM Template
INCLUDE Irvine32.inc
.data
myString BYTE 51 DUP(0)
stringLength DWORD 0
.code
main proc
mov edx , OFFSET myString
mov ecx , 50
call ReadString
mov stringLength, eax
mov ebx, 2
xor edx, edx
div ebx
mov ecx, eax
xor esi, esi
mov edi, stringLength
dec edi
SWAPPER:
mov ah, myString[esi]
mov al, myString[edi]
mov myString[esi], al
mov myString[edi], ah
inc esi
dec edi
loop SWAPPER
mov edx, OFFSET myString
call WriteString
invoke ExitProcess, 0
main ENDP
END main
Explanation / Answer
Ans::
Program:
INCLUDE Irvine32.inc
.data
stringInput byte 50 dup(0)
promptIn byte "Enter the string: ",0
.code
swaping MACRO a,b
XOR a,b
XOR b,a
XOR a,b
ENDM
strlen proc
push ebp
mov ebp, esp
push ebx
mov eax, 0
mov ebx, [ebp+8]
Counter:
cmp byte ptr [ebx + eax], 0
je Done
inc eax
jmp counter
Done:
pop ebx
mov esp, ebp
pop ebp
ret TYPE ebp
strlen endp
strrev proc
Push ebp
MOV ebp, esp
Push eax
Push ebx
Push ecx
Mov ebx, [ebp+8]
Mov ecx, [ebp+8]
push ebx
call strlen
ADD ecx, eax
SHR al,1
count: CMP al,0
JZ finished
MOV ah, byte PTR [ebx]
swaping ah, byte ptr [ecx-1]
MOV BYTE PTR [ebx], ah
INC ebx
DEC ecx
DEC al
JMP count
finished: POP ecx
POP ebx
POP eax
MOV esp, ebp
POP ebp
RET (TYPE ebp)*4
strrev ENDP
main proc
mov eax, 0
mov edx, offset promptIn
call writeString
mov edx, offset stringInput
mov ecx, 51
call readString
push edx
call strrev
call crlf
call writestring
call crlf
exit
main endp
end main