Link to home
Start Free TrialLog in
Avatar of adamgasior
adamgasiorFlag for Poland

asked on

MASM, copying one string (parameter) to another string variable

I would like to write program that store data entere from keypord in  a text file. The name of text file is gicen as a parameter in the command line.

When I want to copy the file name ( enetered as parameter) stored in PSP, something goes wrong and instead of storing inputed data in file I given, the data is stored in the file which name is "!!!!!!!"

What can be wrong,
Thanks for any help

The code is listed below( I marked section which doesn't function properly):

comment %
*********************************************
* copy characters from keyboard to the file *
*********************************************
%

.model small

.stack 512

.data
text_file BYTE 256 DUP(?)

character db ?
handle    dw ?

.code
      
      assume ds:nothing
beginning:
        mov bx, 80h             ; address of parameter in PSP block
        mov cl, ds:[bx]         ; parameter length
        xor ch, ch              ; cx - length
        or  cx, cx              ; is the parameter string empty?
        jz  ending


      mov ax, @data
      mov es, ax
      mov di, offset text_file

looping1:
         ; ****!!!!! here (below) is something wrong I suppose
       inc bx
       mov di,bx
      mov dl, ds:[bx]       ; load next character
             mov text_file[bx], dl

       loop looping1

        ;*****!!!!!! from this point everythink works fine

      assume ds:@data

        mov ax, @data           ; take address of data segment
        mov ds, ax              ; set the segment register
        mov ah, 3Dh             ; open file
        mov al, 1
        mov dx, offset text_file
        int 21h
        jnc opened              ; file opened
        mov ah, 3Ch             ; create file
        mov dx, offset text_file
        mov cx, 0               ; ordinary file
        int 21h
        jc  ending              ; jump if error
opened:
        mov handle, ax
        mov ah, 42h             ; go to the end of file
        mov bx, handle
        xor cx, cx              ; zero position
        xor dx, dx
        mov al, 2               ; from the end of the file
        int 21h
looping:
        mov ah, 08h
        int 21h                 ; read the character
        or  al, al              ; is character zero?
        jnz ok                  ; normal character
        mov ah, 08h             ; read second byte
        int 21h                 ; if special code
        jmp looping
ok:
        cmp al, 1Ah             ; Ctrl-Z - end of the text
        je  closing
        mov character, al
        mov ah, 02h
        mov dl, al
        int 21h                 ; display the character
        mov ah, 40h             ; write it to the file
        mov bx, handle
        mov dx, offset character
        mov cx, 1               ; one character
        int 21h
        jmp looping
closing:
        mov ah, 3Eh
        mov bx, handle
        int 21h
ending:
      mov ax, 4C00h           ; end of the program
      int 21h

end beginning
ASKER CERTIFIED SOLUTION
Avatar of mzvika
mzvika

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of grg99
grg99

Remember to clear the direction flag with "CLD" or very funny things will happen!