Solved

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

Posted on 2000-04-07
7
187 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
  • 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
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 viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

920 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now