2

I wrote an assembly language program to replace two adjacent characters.

    Code             SEGMENT

                ORG   100h
                ASSUME CS:Code, DS:Code, SS:Code

start:          jmp     here
text           DB      "Sample text","$"

here:
                mov     bx, OFFSET text
loop:
                mov     al, [bx]
                cmp     al, '$'
                je      display
                inc     bx
                mov     ah, [bx]
                cmp     ah, '$'
                je      display
                mov     [bx - 1], ah
                mov     [bx], al
                inc     bx
                jmp     loop
display:
                mov     ah, 09h
                mov     dx, OFFSET text
                int     21h
end:
                mov     ax, 4C00h
                int     21h
Code            ENDS

                END  start  

The problem is that although the program correctly replaces the characters in the sample string, it also adds some other non-matching ASCII characters to the end:

enter image description here

I will be grateful for any help and comments on my code.

1201ProgramAlarm
  • 32,384
  • 7
  • 42
  • 56
Pioter47
  • 21
  • 1
  • If you want people to help you with your code, it's usually a good idea to comment your code with what you intend it to do. This way, it's easy to spot when the code does not do what you think it does. Without comments, it's a lot harder to understand the logic. – fuz Mar 21 '21 at 13:56
  • The code works fine on my machine. Make sure you have assembled and tested the most recent version of it. – fuz Mar 21 '21 at 13:59
  • I am so sorry for the sloppy code and thank everyone for their help. I consider the topic closed. – Pioter47 Mar 21 '21 at 18:52

0 Answers0