?? 32060624_王克_asmhomework_6_1.asm
字號:
; 32060624___王克__ASMHomeWork__6
;----------------------------------------------------------------
; ╭══════┤ 32060624___王克__ITRunner!! ├═════╮
; ║ ║
; ║ ║
; ║ ★ 匯編語言 第五次作業 ★ ║
; ║ |---------------------------------------------| ║
; ║ UNIX@WINDOWS TEXT CONVERT ║
; ║ 2005.1.4 ║
; ║ ║
; ╰ ════════════════════════════╯
;匯編程序說明:
;2005.1.4 1.實現WINDOWS和UNIX下文本格式的相互轉換。 2.用臨時文件的方法,相對簡單。
;━┅━┅━┅━┅━┅━┅━┅━┅━━┅━┅━┅━┅━┅━┅━┅━━┅━┅━━┅━
;************************************************************************
.MODEL SMALL
;mocros to use
disp_string macro _string
mov dx,offset _string
mov ah,09H
int 21h
endM
create_file macro _fileName, _HANDLE, _model
mov dx,offset _fileName
xor cx,cx
mov ah,3ch
int 21h
mov _handle, ax
endm
open_file macro _fileName,_HANDLE,_model
mov dx,offset _fileName
mov al,_model
mov ah,3dh
int 21h
mov _Handle,ax
endm
READ_FILE macro _handle, _buffer, _len
mov bx,_handle
mov dx,offset _buffer
mov cx,_len
mov ah,3fH
int 21h
endm
save_char macro _handle, _buffer, _bufLen
mov dx,offset _buffer
mov cx,_buflen
mov bx,_handle
mov ah,40h
int 21H
endm
close_file macro _handle
mov bx,_handle
mov ah,3EH
int 21H
endm
change_file macro _dstFileName,_srcfileName
mov dx,offset _srcfileName
mov di,offset _dstFileName
mov ah,56H
int 21h
endm
del_file macro _fileName
mov dx,offset _fileName
mov ah,41H
int 21h
endm
;*************************************************************************
STACK SEGMENT STACK
WORD 100 DUP(?)
STACK ENDS
DATA SEGMENT PARA
_FNameMaxLen byte 20H
byte ?
_fileName byte 20H DUP(0),00h
_Handle word ?
_buffer byte 1 DUP(?),0DH,'$'
_bufLen word ?
_tmpFileName byte 'temp.txt',00H
_tmpHandle word ?
_msg_input_Name byte 'Input file Name :','$'
_msg_unix_text byte 'Unix text, convert it to Win Text.',0DH,0AH,'$'
_msg_win_text byte 'Windows text, convert it to Unix Text.',0DH,0Ah,'$'
DATA ENDS
CODE SEGMENT PARA
ASSUME CS:CODE, DS:DATA, SS:STACK
;*************************************************************************
MAIN PROC FAR
MOV AX,DATA
MOV DS,AX
mov es,ax
disp_string _msg_input_Name ;DOS 09H to display a string
call getFileName ;ret BX the Length of filename
open_file _FileName, _Handle, 0 ;just read
create_file _tmpFileName, _tmpHandle ;create temp file to save
call convert_file
close_file _handle
close_file _tmpHandle
del_file _FileName ;delete the temp file
change_file _fileName,_tmpFileName ;change the temp file to src fileName
del_file _tmpFileName ;delete the temp file
mov ax,4c00H
int 21H
MAIN ENDP
;*************************************************************************
getFileName proc near
mov si,offset _FileName ;get the fileName char by char
xor bx,bx
next:
mov ah,01H
int 21H
cmp al,0DH
je return
mov [bx][si],al
inc bx
jmp next
return:
ret
getFileName endp
;*******************************************************************
convert_file proc near
next:
read_file _handle, _buffer, 1 ;ret ax,char num read
cmp ax, 0 ;if ax == 0 , have get end
je return ;EOF
cmp _buffer, 0Dh
je is_win_text
cmp _buffer, 0Ah
je is_unix_text
save_char _tmpHandle, _buffer, 1
jmp next
is_win_text:
disp_string _msg_win_text ;not save 0AH
read_file _handle, _buffer, 1
save_char _tmpHandle, _buffer, 1
jmp next
is_unix_text:
disp_string _msg_unix_text
save_char _tmpHandle, _buffer+1, 1 ;save a 0DH, append
save_char _tmpHandle, _buffer, 1 ;save 0AH
jmp next
return:
ret
convert_file endp
;*******************************************************************
CODE ENDS
END MAIN
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -