Iceman
Iceman

Reputation: 35

WHY DOES THIS NOT PRINT TWICE?

I need help getting this to print 2 times. Any suggestion?

        .stack 100H

        .model small

        .386

        .data

        source      DB      "Something in here", 10, 13
        lsource     EQU     ($ - source)
        target      DB      128 DUP (?) 
        ltarget     EQU     ($ - target)

        .code
main:
        mov ax, @data                       ;   set up data addressability
        mov ds, ax

                                            ;   mov string from source to destination   

        cld                                 ;   clear direction flag = forward
        mov cx, lsource                     ;   set REP counter
        mov si, OFFSET source               ;   set si to point to source
        mov di, OFFSET target               ;   set di to point to target       
        rep movsb


        mov ax, 4000h                       ;   dos service to display...
        mov bx, 1                           ;   to screen
        mov cx, lsource                     ;   number of bytes
        mov dx, OFFSET source               ;   where to get data
        int 21h

        mov ax, 4000h                       ;   dos service to display...
        mov bx, 1                           ;   to screen
        mov cx, ltarget                     ;   number of bytes
        mov dx, OFFSET target               ;   where to get data
        int 21h


        mov ah, 4ch
        int 21h


        end main

Why won't it print 2 times?

Upvotes: 0

Views: 122

Answers (1)

rkhb
rkhb

Reputation: 14399

rep movsb copies CX bytes from DS:SI to ES:DI. You didn't initialize ES. Insert a mov es, ax just one line after mov ds, ax.

Upvotes: 2

Related Questions