Skip to content

Instantly share code, notes, and snippets.

@dannvix
Created November 11, 2009 15:17
Show Gist options
  • Save dannvix/232018 to your computer and use it in GitHub Desktop.
Save dannvix/232018 to your computer and use it in GitHub Desktop.
TITLE Reversing a String
INCLUDE Irvine32.inc
.data
buffer BYTE 100 DUP(0)
byteCount DWORD ?
.code
main PROC
; Read string from stdin
mov edx, OFFSET buffer
mov ecx, SIZEOF buffer
call ReadString
mov byteCount, eax
; Push the string into stack
mov ecx, eax
mov esi, 0
Push:
movzx eax, buffer[esi]
push eax
inc esi
loop Push
; Pop the string from stack, in reverse
mov ecx, byteCount
mov esi, 0
Pop:
pop eax
mov buffer[esi], al
inc esi
loop L2
; Print the string to stdout
mov edx, OFFSET buffer
call WriteString
call Crlf
exit
main ENDP
END main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment