[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 194
  • Last Modified:

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

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
stinger_maniac
Asked:
stinger_maniac
  • 4
  • 3
1 Solution
 
nietodCommented:
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
 
stinger_maniacAuthor Commented:
It is for dos and it is MASM 5.0
0
 
nietodCommented:
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
stinger_maniacAuthor Commented:
can you explain a little bit what you are doing there?like comment the code
what does *  *  *  stand for?
thanx
=)
0
 
stinger_maniacAuthor Commented:
Adjusted points from 50 to 60
0
 
nietodCommented:
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
 
stinger_maniacAuthor Commented:
thanx
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now