⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 open.asm

📁 一个用汇编写的文本编辑器
💻 ASM
字号:
public   begi
desg segment para 'data'
       filename  label byte
        maxname  db  16
        namelen  db ?
        pathnam  db  16 dup (' ')
      	endcde db 0
        handle dw ?
        duf    db  1024 dup(' ')
        wrtpath db '*please input openpathnam*','$' 
	openmsg  db '* * * open error * * *',0dh,0ah
	readmsg  db '* * * read error * * *',0dh,0ah
        row db 1
        count dw ?
  a        db    0
  b        db    0
  c        db    0
  d        db    0
  e        db    0
  f        db    0
  han1     dw    ?
  han2     dw    ?
  buf      db    256 dup(?),'$'
  buff     db    256 dup(?),'$'
desg ends
cseg segment para 'code'
   begi proc far 
      assume cs:cseg,ds:desg,es:desg
   	push ds
	sub ax,ax
	push ax
	mov ax,desg
	mov ds,ax
	mov es,ax
	mov ax,0600h
	call scren
	call curs
	call openh
	cmp endcde,0
	jnz a1
        call  readh
	cmp endcde,0
	jnz a1
	call wen2  
         call savef
   a1:  ret
begi endp

openh proc near
        mov dx,offset wrtpath
        mov ah,9
        int 21h
  	mov ah,0ah
        lea dx,filename
        int 21h
        cmp namelen,0
        jz  b1
        mov al,0
        sub ch,ch
        mov cl,namelen
        lea  di,pathnam
        add di,cx
        neg  cx
        add cx,16
        rep stosb
        mov ax,0600h
	call scren
	call curs
  	mov ah,3dh
  	mov al,0
  	lea dx,pathnam
  	int 21h
  	jc b1
  	mov handle,ax
     ret
  b1:	mov endcde,01
        lea dx,openmsg    
    	call errm
     ret
openh endp
readh proc near
          mov ah,3fh
          mov bx,handle
          mov cx,1024
          lea dx,duf 
          int 21h
          mov count,ax
          jc  c1
          cmp ax,0
          je c2
          cmp duf,1ah
          je c2
          ret
  c1:     lea dx,readmsg
          call errm
  c2:     mov endcde,01
          ret
readh endp
errm proc near
  	mov ah,40h
	mov bx,01
  	mov cx,21
  	int 21h
      ret
errm endp
scren proc near
       mov bh,1eh
       mov cx,0100h
       mov dx,184fh
       int 10h
     ret
scren endp
curs proc near
   mov ah,02
   mov bh,0
   mov dl,0
   mov dh,row
   int 10h
ret
curs endp
;*************************************************************
wen2    proc      near
        mov   ah,2
        mov   dh,2
        mov   dl,1
        int   10h
        mov   dx,offset wrtpath
        mov   ah,9
        int   21h
  	mov   ah,0ah
        lea   dx,filename
        int   21h
        mov   al,0
        sub   ch,ch
        mov   cl,namelen
        lea   di,pathnam
        add   di,cx
        neg   cx
        add   cx,16
        rep   stosb
;------------------------
    mov      ax,3d02h
    mov      dx,offset pathnam
    int      21h      
    mov      bx,ax
    mov      ah,3fh
    mov      cx,256        ;将文件中的字符读出
    mov      dx,offset buf
    int      21h       
;--------------------------------------------    
    mov      ah,2
    mov      dh,1
    mov      dl,0
    int      10h
    lea      dx,buf
    mov      ah,09h
    int      21h        ;输出文件中的内容
   ;------------
repeat1:
    mov      ah,07h
    int      21h
    cmp      al,48h   ;行减一
    jne      x1
    call     y1
    jmp      repeat1
x1:     
    cmp      al,4bh   ;列减一
    jne      x2
    call     y2
    jmp      repeat1
x2:
    cmp     al,50h ;行加一
    jne     x3
    call    y3
    jmp     repeat1
x3:     
  cmp       al,4dh   ;列加一
  jne       x4
  call      y4         
  jmp       repeat1 
x4:     
  cmp       al,3fh 
  jne       x5                  ;删除光标前的文字
  call      delf
    mov      ah,40
    mov      bx,han2
    mov      cx,256       ;将buf中的字符写入文件
    mov      dx,offset  pathnam
    int      21h
  jmp       repeat1
x5:
  cmp       al,40h      ;添加文字
  jne       x6 
  call      addf
    mov      ah,40
    mov      bx,han2
    mov      cx,256       ;将buf中的字符写入文件
    mov      dx,offset pathnam
    int      21h
  jmp       repeat1    ;块操作从F9开始
;********************************************************
x6:
  cmp       al,43h
  jne       x7
  call      block
  jmp       repeat1        
x7:
  cmp       al,44h
  jne       repeat1
    ret
wen2  endp
y1   proc    near   ;光标移动
  push  ax
  push  bx 
  push  dx
  mov  ah,3
  int  10h
  mov  ah,2            ;行减一
  dec  dh
  int  10h
  pop  dx
  pop  bx
  pop  ax
  ret
y1   endp
;----------------------------------------
y2   proc    near
  push  ax
  push  bx
  push  dx
  mov  ah,3
  int  10h
  mov  ah,2
  dec  dl              ;列减一
  int  10h    ;83
  pop  dx
  pop  bx
  pop  ax
  ret
y2   endp
;--------------------------------------
y3   proc    near
  push  ax
  push  bx
  push  dx
  mov  ah,3
  int  10h
  mov  ah,2
  inc  dh            ;行加一     
  int  10h
  pop  dx
  pop  bx
  pop  ax
  ret
y3   endp
;--------------------------------------------
y4   proc    near
  push  ax
  push  bx
  push  dx
  mov   ah,3
  int   10h
  mov   ah,2
  inc   dl            ;列加一 
  int   10h
  pop   dx
  pop   bx
  pop   ax
  ret
y4      endp
;----------------------------------------
delf   proc   near
      push      ax
      mov       ah,3h
      int       10h
      mov       a,dl
      mov       b,dh
      mov       dh,0
      lea       bx,buf
      add       bx,dx
      mov       cx,256
ded:
      mov       ah,[bx+1]
      mov       [bx],ah
      add       bx,1
      loop      ded
      call      clen
      mov       bh,0
      mov       ah,2
      mov       dh,1
      mov       dl,0
      int       10h
      lea       dx,buf
      mov       ah,09h
      int       21h
      mov       bh,0
      mov       dh,b
      mov       dl,a
      mov       ah,2
      int       10h
      pop       ax
      ret
delf    endp
;-----------------------------
addf   proc     near      
      push      ax
cha:
      mov       ah,07h
      int       21h
      mov       c,al
      cmp       al,3eh
      je        chan
      mov       ah,3h
      int       10h
      mov       a,dl
      mov       b,dh
      mov       dh,0
      lea       bx,buf
      add       bx,255
      mov       ax,255
      sub       ax,dx  
      mov       cx,ax
aed:
      mov       ah,[bx]
      mov       [bx+1],ah
      dec       bx
      loop      aed
      call      clen
      mov       al,c
      mov       [bx+1],al
      mov       bh,0
      mov       ah,2
      mov       dh,1
      mov       dl,0
      int       10h
      lea       dx,buf
      mov       ah,09h
      int       21h
      mov       bh,0
      inc       a
      mov       dh,b
      mov       dl,a
      mov       ah,2
      int       10h
      jmp       cha
chan:
      pop       ax
      ret
addf    endp
;----------------------------------------
block   proc    near
    mov      ah,03
    int      10h
    mov      a,dl 
    ;取当前坐标a
xx:
    mov      ah,07h
    int      21h
    cmp      al,48h   ;行减一
    jne      xx1
    call     y1
    jmp      repeat1
xx1:     
    cmp      al,4bh   ;列减一
    jne      xx2
    call     y2
    jmp      repeat1
xx2:
    cmp     al,50h ;行加一
    jne     xx3
    call    y3
    jmp     repeat1
xx3:     
    cmp       al,4dh   ;列加一
    jne       xx4
    call      y4         
    jmp       repeat1 
xx4:
    cmp       al,43h
    jne       xx
    mov       ah,3h
    int       10h
    mov       b,dl
    ;取当前坐标b
;*******************************************
xxx:
    mov      ah,07h
    int      21h
    cmp      al,48h   ;行减一
    jne      xxx1
    call     y1
    jmp      repeat1
xxx1:     
    cmp      al,4bh   ;列减一
    jne      xxx2
    call     y2
    jmp      repeat1
xxx2:
    cmp     al,50h ;行加一
    jne     xxx3
    call    y3
    jmp     repeat1
xxx3:     
    cmp       al,4dh   ;列加一
    jne       xxx4
    call      y4         
    jmp       repeat1 
xxx4:
    cmp       al,43h
    jne       xx
    mov       ah,3h
    int       10h
    mov       c,dl
;-----------------------------------------
    lea       dx,buf
    mov       ah,0
    mov       al,a
    add       dx,ax      ;dx zhi xiang a dian
    mov       al,b
    sub       al,a
    mov       cl,al
    mov       ch,0   
    lea       bx,buff
xxx5:                        ;jiang zhi  gei buff
    xchg      dx,bx
    mov       ah,[bx]
    xchg      bx,dx
    mov       [bx],ah
    inc       bx
    inc       dx
    loop      xxx5
;-------------------------------------
    lea       dx,buf
    mov       ah,0
    mov       al,a
    add       dx,ax      ;zhixiang a 
    mov       al,c
    sub       al,b
    mov       cl,al
    mov       ch,0   
    lea       bx,buf
    mov       al,b
    add       bx,ax        ;zhixiang b
xxx6:
    mov       ah,[bx]
    xchg      bx,dx
    mov       [bx],ah
    xchg      bx,dx             ;jiang zhi gei ziji
    inc       bx
    inc       dx
    loop      xxx6
;***************************************************
    mov       al,b
    sub       al,a
    mov       cl,al
    mov       ch,0   
    lea       bx,buff
xxx7:
    mov       ah,[bx]
    xchg      bx,dx
    mov       [bx],ah
    xchg      bx,dx
    inc       bx
    inc       dx        ;30
    loop      xxx7      ;828 buff jiang zhi gei buf    
    call      clen
      mov       bh,0
      mov       ah,2
      mov       dh,1
      mov       dl,0
      int       10h
      lea       dx,buf
      mov       ah,09h
      int       21h
      mov       bh,0
      mov       dh,b
      mov       dl,a
      mov       ah,2
      int       10h    
   ret      
block   endp
clen   proc   near
     push      ax
     push      bx
     push      cx
     push      dx
     mov       ah,02h
     mov       dh,1
     mov       han1,25d
cle:
     mov       ah,2h
     mov       dl,0
     int       10h
     mov       ah,09h
     mov       al,' '
     mov       bl,1eh
     mov       bh,0
     mov       cx,80
     int       10h
     inc       dh 
     dec       han1
     cmp       han1,01h
     jne       cle
     pop       dx
     pop       cx
     pop       bx
     pop       ax
     ret
clen    endp
;*************************************************************
savef proc near
  mov ah,3ch
  mov cx,0
  lea  dx,pathnam
  int 21h
  mov handle,ax
  mov ah,40h
  mov bx,handle
  mov cx,1024
  lea dx,buf
  int 21h
  mov ah,3eh
  mov bx,handle
  int 21h
  ret 
savef endp
;********************
cseg ends 
   end begi
  end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -