Question: So I am currently working on creating a little text editor in assembly using dosbox and TLINK/TASM. So far, my proj2.com reads the buff.asm file,

So I am currently working on creating a little text editor in assembly using dosbox and TLINK/TASM. So far, my proj2.com reads the buff.asm file, writes it to video memory, allows one to move the cursor, write a new character where the cursor is, and supposedly saves it into the screen array. I tried writing it back to buff.asm but it starts writing at the end of the file rather than the start and whatever it writes has boxes in between each character.

So if the file is

 Hello World

And I rewrite the file to "okay" it becomes

 Hello Worldo[]k[]a[]y[]

I would really appreciate it if someone could shed some light as to what I can do to solve my issue.

buff.asm:

 hello world! wow!

proj2.asm:

 .model tiny .code org 100h start: mov ax, 0003h ; set video mode to text 80x25 int 10h mov bx,0b800h ; set up video memory mov es,bx mov cx,25*80 ; clear screen push di sub di,di mov ax,0720H clear: mov es:[di],ax add di,2 loop clear pop di ; ///////////////////////////////////////////// ; OPEN FILE ; ///////////////////////////////////////////// mov ah, 3dh ; open file mov al, 2 mov dx, offset filename int 21h jnc cont1 jmp exit ; end if error cont1: mov inh, ax ; file handle ; ///////////////////////////////////////////// ; READ FILE ; ///////////////////////////////////////////// mov di, 0 mov si, 0 read: mov ah, 3fh ; read from file mov bx, inh mov dx, offset filebuff mov cx, 1 int 21h jnc cont2 jmp exit cont2: cmp ax, 0 jz next mov dl,filebuff cmp dl, 1AH ; skip to end if end of file je next cmp dl, 0DH ; skip to start if end of line je read cmp dl, 0AH ; skip if start of new line je nextline ;mov cx, 80 ;mov si, offset filebuff ;mov di, 0 ; ;l1: ; mov al, [si] ; mov es:[di], al ; inc si ; inc di ; inc di ; loop l1 mov es:[di], dl ; write to video memory add di, 2 jmp read nextline: add si, 160 mov di, si jmp read ; ////////////////////////////////////////////////////// TEST next: mov ah,02h ; set cursor to top mov bh,0 mov dh,0 mov dl,0 int 10h decide: mov ah,00h ; wait for input int 16h cmp ah,48h ; move cursor up je up cmp ah,4Bh ; move cursor left je left cmp ah,50h ; move cursor down je down cmp ah,4Dh ; move cursor right je right cmp al,1BH ; 'exit' prompt je exit mov ah,0eh int 10h jmp decide ; if no correct input, loop ; \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ up proc ; begin 'up' cmp dh,00 je decide mov ah,2 mov bh,0 sub dh,1 int 10h jmp decide up endp ; \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ left proc ; begin 'left' cmp dl,00 je decide mov ah,2 mov bh,0 sub dl,1 int 10h jmp decide left endp ; \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ down proc ; begin 'down' cmp dh,24 je decide mov ah,2 mov bh,0 add dh,1 int 10h jmp decide down endp ; \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ right proc ; begin 'right' cmp dl,79 je decide mov ah,2 mov bh,0 add dl,1 int 10h jmp decide right endp ; \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ ; ///////////////////////////////////////////// ; END PROGRAM ; ///////////////////////////////////////////// exit proc ; begin 'exit' ; ////////////////////////////////////////////////////////// ; WRITE TO FILE ; ////////////////////////////////////////////////////////// mov cx, 25 mov di, 0 ss_loop: mov ax, es:[di] mov screen[di],ax add di,1 loop ss_loop mov ah, 40h ; write to file mov dx, offset screen mov cx, 25 mov bx, inh int 21h jnc ok jmp decide ok: ; ////////////////////////////////////////////////////////// mov cx,25*80 ; clear screen push di sub di,di mov ax,0720H clear2: mov es:[di],ax add di,2 loop clear2 pop di mov ah,02h ; set cursor to top mov bh,0 mov dh,0 mov dl,0 int 10h mov ah, 3eh ;close file mov bx, inh int 21h mov ax,4c00h ; end program int 21h exit endp ; end 'exit' jmp decide filename db 'buff.asm', 0 inh dw ? filebuff db ? screen dw 80*25 dup(?) mssge db "wrt$" end start

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!