Are there two consecutive equal characters in the string
A program that checks whether two consecutive equal characters are present in the string.
Program source code
title .model small .stack 100h data segment public string db "Microsoft Macro Assembler$" strlen equ ($-string) charFound db "The character is: $" charNotFound db "There are no consecutive characters in the string!$" data ends code segment public assume ds:data, cs:code main proc mov ax, seg data ; Get the data segment address and store it in ax mov ds, ax ; Pass the data segment address from ax to ds mov cx, strlen ; Copy the value of the strlen variable into the cx register lea si, ds:[string] ; Load the address of the string variable into the ds:si register MainLoop: lodsb ; Load the byte at address ds:si into the al register. SI++ cmp al, byte ptr[si] ; Compare the value in al with the next character at ds:si je Found ; If ZF=1, then jump to the label Found loopnz MainLoop ; Loop while CX≠0 or ZF≠1 mov ah, 09h ; Copy the string output function number into ah lea dx, ds:[charNotFound] ; Load the address of the charNotFound variable into the ds:dx register int 21h ; Call the interrupt jmp Done ; Jump unconditionally to the Done label Found: mov ah, 09h ; Copy the string output function number into ah lea dx, ds:[charFound] ; Load the address of the charFound variable into the ds:dx register int 21h ; Call the interrupt mov ah, 02h ; Copy the console output function number into ah mov dl, al ; Copy the value of the found character into the dl register int 21h ; Call the interrupt Done: mov ax, 4C00h ; Copy the termination function number into ah and the value into al int 21h ; Call the interrupt main endp code ends end main
The character is: s
Example taken from the textbook "HANDYFAR - MASM (Evgeny Sergeevich Dovgopolov)".