الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

[تنبيه - عنوان غير مناسب : ]I need help

بدأه c0000l في 11 أغسطس 2010 · 2 رد · 627 مشاهدة · في أرشيف قسم الـــ Assembly
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم و رحمة الله و بركاته

أنا طالب ادرس الاسمبلي عندي بروجكت حبيت تساعدوني فيه

هذا المطلوب من البرنامج :

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
#2

الأخ الكريم/الأخت الكريمة

السلام عليكم ورحمة الله وبركاته

مرحباً بكم في منتدى الفريق العربي للبرمجة

نود تنبيهك أن العنوان غير مناسب.

الرجاء اختيار عنوان مناسب أكثر في مواضيعك القادمة، وهذا بمثابة إشعار للأهمية.

وفي حال التكرار سيتعرض موضوعك للإغلاق والحذف!!!

قواعد المشاركة

/index.php?showtopic=29343

شاكرين لكم حُسن تعاونكم

#3
c0000l كتب:

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

C.

تفترض أن وجود أي char لا يساوي رقماً يجب أن يظهر خطأ يشير إليه، بالتالي افترض أن الأرقام مخزنة في الملف بالشكل

1

2

3

4

ونعتبر CRLF لا تشير إلى حرف أو رمز بالتالي يقبل وجودها وإلا لن يكون هناك أي طريقة أخرى.

بالتالي تستطيع قراءة محتوى الملف والبحث ضمن السلسلة المعادة عن أي قيمة خارج النطاق 13h,10h,30h-39h فإن وجد بايت واحد خارج هذا النطاق يتم إظهار رسالة الخطأ ويغلق البرنامج.

D.

بعد التأكد من أن محتوى الملف خالي من أي رموز عدا الأرقام و Line breaks تحتاج للمرور على هذه الأرقام، قراءة الرقم في كل سطر، تحويله إلى hex، جمعه (إضافته) إلى accumulator إلى أن تنتهي السلسلة.

إضافة: ربما تريد التحقق فيما إذا كان الرقم داخل المجال المحدد في نص المسألة [0 - 100].

بعد الانتهاء من الجمع تقسم الناتج على 10 للحصول على المتوسط ومن ثم تحول ناتج القسمة إلى dec وتطبعه على الشاشة.

E.

اكتب برنامجك الأساسي بحيث لا يكون لزاماً على الخوارزمية إيجاد 10 أرقام حصراً داخل الملف، بحيث يتم القراءة من السلسلة مهما كان طولها إلى أن تنتهي، وبهذا تحقق البند المطلوب دون الحاجة إلى كتابة إجرائية أو خوارزمية جديدة.

ضع محاولاتك

1

Do as I say, not as I do

We are Anonymous. We are Legion. We don't forgive. We don't forget

مواضيع مشابهة