Solved

Assembly........How to read 50 integers from a file

Posted on 2000-04-07
7
190 Views
Last Modified: 2010-04-02
Hi. I am trying to do a program that reads 50 integers from a file and calculates their average. I have no idea how to read from a file. Please if anyone knows I will appreciate you explain. Thanx
It is for an 8086
0
Comment
Question by:stinger_maniac
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 22

Accepted Solution

by:
nietod earned 60 total points
ID: 2692952
x86 assembly (well, no assembly language) doesn't provide any means to read from a file.   That has to be done through the use of an OS-specific technique.  i.e. by calling an OS-procedure or by performing a software interrupt to an OS service.

So we woud have to know what OS you are running on in order to read the file.

Also since the language varies from assembler to assembler  it would be good to know what assembler you are using

To do the average, though

INTARY DW 50 DUP (0)

   *   *   *


   MOV CX,50 ; Get number of ints to add.
   MOV BX,OFFSET INTARY ; Get -> 1st int to add.
   XOR AX,AX ; Clear the low word of the total.
   XOR DX,DX ; Clear the high word of the total.

CALAVGTOP: ADD AX,WORD PTR[BX]; Add int to low word of total.
    ADC,DX,0 ; Add carry to high word.
    ADD,BX,2 ; Point to next int.
    LOOP CALAVGTOP ; Loop back for next int.

  MOV BX,50 ; Get number of ints to divide by.
  DIV BX ; Calculate average in AX.

Let me know if you have any questions or any other information.
0
 

Author Comment

by:stinger_maniac
ID: 2694309
It is for dos and it is MASM 5.0
0
 
LVL 22

Expert Comment

by:nietod
ID: 2694446
INTARY DW 50 DUP (0)
FILNAM DB "C:\SOMEFILE.DAT",0

   *  *  *
; Assuming DS is set to the segment with the file naem and array
  MOV DX,OFFSET FILNAM ; Get -> file name
  MOV AL,0 ; Specify open read only, deny none.
  MOV AH,3DH ; Specify open file function
  INT 21H ; Open the file.
  JC ERRORHANDLER
  MOV BX,AX ; Get the file handle.
  MOV DX,OFFSET INTARY ; Get -> array.
  MOV CX,2*50 ; Get number of bytes to read.
  MOV AH,3FH ; Specify file read function.
  INT 21H ; Read the file.
  JC ERRORHANDLER
  MOV AH 3EH ; Specify close file function.
  INT 21H ; Close the file.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:stinger_maniac
ID: 2694812
can you explain a little bit what you are doing there?like comment the code
what does *  *  *  stand for?
thanx
=)
0
 

Author Comment

by:stinger_maniac
ID: 2694941
Adjusted points from 50 to 60
0
 
LVL 22

Expert Comment

by:nietod
ID: 2694954
I commented everything.  It just opens a file, reads out 100 bytes and closes the file.  All done through DOS service interrupts.

The *  * * is to break up the code intop sections as you will probably declare your data in a seperate part of the program from the code.
0
 

Author Comment

by:stinger_maniac
ID: 2703226
thanx
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question