In: Computer Science
IN ASSEMLY LANGUAGE MASM! please show output run. Write a program that ask the user to write a string and reverse a string using indirect addressing (may not use the stack - push/pop). The string will be given by the user and be up to 64 characters long.
INCLUDE Irvine32.inc
INCLUDE macros.inc
MAX = 64
.data
source BYTE MAX DUP('#'),0
destination BYTE LENGTHOF source DUP('*'),0
actual_length DWORD ?
ask BYTE "Enter a String: ",0
.code
main proc
; ask user for input
mov edx, OFFSET ask
call WriteString
; read string from keyboard
mov edx, OFFSET source ; where to put string from keyboard
mov ecx, LENGTHOF source ; max num char to get (dont' over fill)
call ReadString ; get string
mov actual_length, eax ; how long is the string
call WriteString
mov esi, OFFSET source
mov ecx, SIZEOF source
call ShowBuffer
exit
main ENDP
.586
.model flat
.data
source byte "This is the source string", 0
.code
_main proc
mov esi, offset source ; load up start pointer.
mov edi, offset source ; set end pointer by finding zero byte.
dec edi
find_end:
inc edi ; advance end pointer.
mov al, [edi] ; look for end of string.
cmp al, 0
jnz find_end ; no, keep looking.
dec edi ; yes, adjust to last character.
swap_loop:
cmp esi, edi ; if start >= end, then we are finished.
jge finished
mov bl, [esi] ; swap over start and end characters.
mov al, [edi]
mov [esi], al
mov [edi], bl
inc esi ; move pointers toward each other and continue.
dec edi
jmp swap_loop
finished:
int 3 ; trap to enter debugger and check string.
; replace with whatever you need.
_main endp
end _main