Data Segment
Path dB 'goodjob. txt ', 0
Fileinfo dB 'possible is nothing'
Mok dB 'goodjob, creat file sucdess! $'
Merror dB 'Sorry, failed! '
Handle DW?
Data ends
Code segment
Assume DS: data, CS: Code
Start:
MoV ax, Data
MoV ds, ax
MoV CX, 0
MoV dx, offset path
MoV ah, 3ch
Int 21 h
JC Error
MoV handle, ax; Save handle
MoV dx, offset Mok; Calculate the number of character
Sub dx, offset fileinfo; The sum of character save in dx, and then move to CX
MoV CX, DX
MoV BX, handle
MoV dx, offset fileinfo; Write data to file
MoV ah, 40 h
Int 21 h
JC Error
MoV BX, handle; Close the Open File
MoV ah, 3eh
Int 21 h
JC Error
MoV dx, offset Mok; Write the message on screen that the program work well
MoV ah, 9
Int 21 h
JMP end1
Error:
MoV dx, offset merror; If program terminal unnormal, then tell puts the information on sreen
MoV ah, 9
Int 21 h
End1:
MoV ah, 7; Waiting for user to press any key to exit the program
Int 21 h
MoV ah, 4ch
Int 21 h
Code ends
End start