1

I have a procedure in assembly which supposed to take a string and 2 numbers that will represent the number of milliseconds to wait after printing each letter, also it first count the length of the string and then starts to print it letter by letter with a delay of %cx:%dx this is the code:

IDEAL
MODEL small
STACK 100h   
DATASEG
    x db 02
    string db "hello, my name is ____",0Ah, 0Dh,"and this is my game:",0Ah,0Dh ,'$'
    string2 db "this is a test ",0Ah ,'$'
    
CODESEG
    
proc PrintString
    xor dx, dx
    push bp
    mov bp, sp
    mov bp, [bp+8h] ;string offset
    xor cx, cx
    WhileLoop:
        mov dl, [byte ptr ds:bp] ;string offset in the ds
        inc bp
        inc cx
        cmp dl, 24h
        jne WhileLoop
    mov bp, sp
    mov bx, bp
    mov bp, [bp+8h] ; string offset
    sub cx, 1
    PrintLoop:
        mov dl, [byte ptr ds:bp]
        mov ah, 02h
        inc bp
        int 21h
        mov ah, 86h
        push cx
        ;watiting cx:dx milliseconds
        mov cx, [ss:bx+6]     ;push 03h
        mov dx, [ss:bx+4]     ;push 01615h
        int 15h
        pop cx
        loop PrintLoop
    pop bp
    ret
endp
    
    
start:
    mov ax, @data
    mov ds, ax
    push offset string
    push 03h
    push 01615h
    call PrintString
    pop ax
    pop ax
    pop ax
    xor ax, ax
    push offset string2
    push 05h
    push 01615h
    call PrintString
    
exit:
    mov ax, 4c00h
    int 21h
END start

everything works fine when the code looks like this. buf if I delete the x variable which I don't use even once in my code - the code suddenly doesn't work and the output looks like this: img1

it gets stuck at the h, sometimes it manages to print also the second letter ('e') also if I keep the variable x but I try to change the text to something else it also doesn't work:

enter image description here

but if I make the string really short it works with or without the variable x:

enter image description here

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
user9609349
  • 91
  • 2
  • 8
  • 1
    This should **not** solve your problem, but depending on the DOS version (or DOS emulator) `int 21h` may change the `cx` register, so you should move the `push cx` instruction before the `int 21h` instruction. – Martin Rosenau Mar 28 '21 at 11:54
  • I assembled your program (without the variable `x`) with TASM 1.0 and tried it both under DOSBOX 0.74 and in a virtual machine running MS-DOS 6.22: It works perfectly. – Martin Rosenau Mar 28 '21 at 12:08
  • The symptoms you describe look like the `mov cx, [ss:bx+6]` instruction does not load the correct value of `cx`. Example: If this instruction loads `0x6B95` into `cx` instead of `3`, the computer will wait 30 minutes between two letters. The reason *might* be that `int 21h` modifies the `bx` register. The data located at the "real" position `ss:bx+6` might be dependent on the length of the strings... – Martin Rosenau Mar 28 '21 at 12:16
  • Can you use a debugger that supports data watchpoints to see if something is overwriting the memory you're printing from? – Peter Cordes Mar 28 '21 at 15:15
  • Even single-stepping with something as simple as DEBUG.COM should tell you something; you can see whether the registers have the wrong values, and/or if the memory still contains the correct string. Then you can start over and try to figure out how they got that way. If you're using TASM maybe you also have the Turbo Debugger. But it's really pretty hopeless to fix any bug in an assembly program without the aid of a debugger. – Nate Eldredge Mar 28 '21 at 16:06
  • 1
    By the way, there's a typo in your comment: the delay for `int 15h / ah = 86h` is in microseconds, not milliseconds: http://www.ctyme.com/intr/rb-1525.htm. But I think that's what you want - a delay of 0.2 seconds, not 200 seconds. – Nate Eldredge Mar 28 '21 at 16:07
  • 3
    Perhaps this is relevant: https://stackoverflow.com/questions/43194265/dosbox-is-buggy-with-int-15h-ah-86h – ecm Mar 28 '21 at 17:17

1 Answers1

1

I dont know the reason why but all you have to do is move to al a zero mov al, 0

user9609349
  • 91
  • 2
  • 8