;********************************************************************************************** ;* * ;* LAB3-4.ASM - Assembler Laboratory ZMiTAC * ;* * ;* program that copies characters from keyboard to the file * ;* * ;********************************************************************************************** comment % ********************************************* * copy characters from keyboard to the file * ********************************************* % .model small .stack 512 .data text_file db "copy.txt", 0 character db ? handle dw ? .code assume ds:@data beginning: 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