PE6) Reverse A String Using Modules

  • Reverse the letters of The Alphabet.
  • Create two modules for your program.
  • Create an include file.
  • Pass the procedure the offsets for two-byte arrays, one being the original string and the other a buffer large enough to contain the reversed Alphabet.
  • Any additional info required to reverse the string should be passed.

INCLUDE PE6)IncludeFile.inc           ;needed to include

.data
gandhi	BYTE	"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
nameSize = ($ - gandhi) - 1
buffer	BYTE	nameSize DUP(?)       ;buffer will contain the reversed string
.code
main PROC
	;pushing items on stack. :ESP is decremented
	push OFFSET gandhi + nameSize ;pushing gandhi (points at the end of gandhi array)
	push OFFSET buffer            ;pushing buffer (points to the front of buffer array)
	push LENGTHOF gandhi			

	call mainPortion              ;calling mainPortion procedure within MOD1
	
	INVOKE ExitProcess,0 ;exit
main ENDP

END main

Module 1:

; When making this program, call it PE6)Module1.asm

INCLUDE PE6)IncludeFile.inc         ;needed

.code                               ;needed
reverseString PROC
	;index adressing
L1:
	mov al, [esi]
	mov [edi], al
	dec esi
	inc edi
	loop L1
	ret
reverseString ENDP
END

Module 2:

; When making this program, call it PE6)Module2.asm

INCLUDE PE6)IncludeFile.inc         ;needed

.code                               ;needed
reverseString PROC
	;index adressing
L1:
	mov al, [esi]
	mov [edi], al
	dec esi
	inc edi
	loop L1
	ret
reverseString ENDP
END

Include File:

; When you make this file, call it PE6)IncludeFile.inc

.386                                   ;directive needed for programt
.model flat,stdcall                    ;directive needed for programt
.stack 4096                            ;directive needed for programt
ExitProcess PROTO, dwExitCode:DWORD

mainPortion PROTO               ;prototype to procedure in Module1 (Need this)
reverseString PROTO             ;prototype to procedure in Module2 (Need this)

Show Code