The StringReverse function
The StringReverse function reverses a string starting from the positions specified in the BL (start position) and BH (end position) registers. If both registers are 0, the function reverses the whole string.
Parameters: AX: pointer to the string; BL: start position; BH: end position.
Return value: The function does not return a value.
Flag state: The function does not modify the flags.
Program source code (Example 1: the whole string)
An example program for the Intel 8086 assembler demonstrating the use of the StringReverse function to reverse a string in whole or in part.
title .model small .stack 100h data segment public string db "Dovgopolov Evgeny Sergeevich\0" data ends code segment public ; Start of the code segment assume ds:data, cs:code include Handyfar.inc ; Include the file with functions main proc ; Start of the main procedure call SetDataSegment ; Call the SetDataSegment procedure xor bx, bx ; Clear the bx register - reverse the whole string lea ax, ds:[string] ; Load the address of the variable string into the ds:ax register call StringReverse ; Call the StringReverse procedure (ax:string, bx:0) call WriteString ; Call the WriteString procedure (ax) xor al, al ; Clear the al register call ExitProcess ; Call the ExitProcess procedure main endp ; End of the main procedure code ends ; End of the code segment end main ; End of file. The main procedure is the entry point
hcivegreS ygnevE volopogvoD
Example taken from the textbook "HANDYFAR - MASM (Evgeny Sergeevich Dovgopolov)".
Program source code (Example 2: part of the string)
title .model small .stack 100h data segment public string db "Dovgopolov Evgeny Sergeevich\0" data ends code segment public ; Start of the code segment assume ds:data, cs:code include Handyfar.inc ; Include the file with functions main proc ; Start of the main procedure call SetDataSegment ; Call the SetDataSegment procedure mov bh, 0 ; Clear the bh register - reverse the string to the end mov bl, 11 ; Copy 11 into the bl register - the start position to begin from lea ax, ds:[string] ; Load the address of the variable string into the ds:ax register call StringReverse ; Call the StringReverse procedure (ax:string, bl:11, bh:0) call WriteString ; Call the WriteString procedure (ax) xor al, al ; Clear the al register call ExitProcess ; Call the ExitProcess procedure main endp ; End of the main procedure code ends ; End of the code segment end main ; End of file. The main procedure is the entry point
Dovgopolov hcivegreS ygnevE
Example taken from the textbook "HANDYFAR - MASM (Evgeny Sergeevich Dovgopolov)".
Program source code (Example 3: part of the string)
title .model small .stack 100h data segment public string db "Dovgopolov Evgeny Sergeevich\0" data ends code segment public ; Start of the code segment assume ds:data, cs:code include Handyfar.inc ; Include the file with functions main proc ; Start of the main procedure call SetDataSegment ; Call the SetDataSegment procedure mov bh, 18 ; Copy 18 into the bh register - the end position to finish at mov bl, 11 ; Copy 11 into the bl register - the start position to begin from lea ax, ds:[string] ; Load the address of the variable string into the ds:ax register call StringReverse ; Call the StringReverse procedure (ax:string, bl:11, bh:18) call WriteString ; Call the WriteString procedure (ax) xor al, al ; Clear the al register call ExitProcess ; Call the ExitProcess procedure main endp ; End of the main procedure code ends ; End of the code segment end main ; End of file. The main procedure is the entry point
Dovgopolov ygnevE Sergeevich
Example taken from the textbook "HANDYFAR - MASM (Evgeny Sergeevich Dovgopolov)".