السلام عليكم و رحمة الله و بركاته
أنا طالب ادرس الاسمبلي عندي بروجكت حبيت تساعدوني فيه
هذا المطلوب من البرنامج :
1- انشاء ملف باسم "" بداخله عشرة ارقام من الصفر الى المئة .
2- اكتب البرنامج بالمواصفات التالية :
a. search for the file; exit with error message if not found.
b. open the file, read the contents and close the file.
c. display error and exit if the contents are not numbers.
d. find and display the average of the numbers in the file.
e. handle a file with more or less than 10 entries eg. 9, 11, 100
هذا البرنامج اللي كتبته :
; Assembly project .model small .stack .code ;;;;;;;Start code;;;;;;;;;;;;; mov ax,@data ; base address of data segment mov ds,ax ; put it in ds ;;;;;;;Start Message;;;;;;;;;; mov dx,offset StartMessage mov ah,09h int 21h ;;;;;;;;search for file;;;;;;; mov dx,offset File ; address of filename to look for mov cx,3Fh ; file mask 3Fh - any file mov ah,4Eh ; function 4Eh - find first file int 21h ; call dos service jc FileDontExist mov dx,offset FileExist mov ah,09h int 21h ;;;;;;;;open file;;;;;;;;;;;;; mov dx,offset FileName ; put offset of filename in dx mov al,2 ; access mode -read and write mov ah,3Dh ; function 3Dh - open the file int 21h ; call dos service jc OpenError ; jump if there is an error mov Handle,ax ; save value of handle ;;;;;;;;read file;;;;;;;;;;;;; mov dx,offset Buffer ; address of buffer in dx mov bx,Handle ; handle in bx mov cx,40 ; amount of bytes to be read mov ah,3Fh ; function 3Fh - read from file int 21h ; call dos service jc readError ; jump if carry flag set - error! ;;;;;;;;;C D E;;;;;;;;;;;;;;;; ; (?) ;;;;;;;;;close a file;;;;;;;;; mov bx,Handle ; put file handle in bx mov ah,3Eh ; function 3Eh - close a file int 21h ; call dos service jc closeError ; jump if there is an error ;;;;;;;;End Message;;;;;;;;;;; mov dx,offset EndMessage mov ah,09h int 21h ;;;;;;;;;;;;;EXIT;;;;;;;;;;;;;; mov ax,4C00h ; terminate program int 21h ;;;;;;;;;;;ERRORS;;;;;;;;;;;;;; FileDontExist: mov dx,offset NoFile jmp EndError OpenError: mov dx,offset OpenMessage jmp EndError readError: mov dx,offset readMessage jmp EndError closeError: mov dx,offset closeMessage jmp EndError EndError: mov ah,09h int 21h mov ax,4C01h int 21h ;;;;;;;;;;;;;;;;;;;;DATA;;;;;;;;;;;;;;;;;;;;;; .data StartMessage DB "This program display the average in DATA.TXT" DB ,"on the C drive.$" File DB "C:\data.txt",0 EndMessage DB " DONE $" FileExist DB "file exists$" NoFile DB "An error has occurred (SEARCHING)$" OpenMessage DB "An error has occurred (OPENING)$" readMessage DB "An error has occurred (READING)$" closeMessage DB "An error has occurred (CLOSING)$" FileName DB "C:\data.txt",0 ; name of file to open Handle DW ? ; to store file handle Buffer DB 100 dup (?) ; buffer to store data ;;;;;;;;;;;end code;;;;;;;;;;;;;;; END