Complete load_pts_file function that reads multiple pairs of numbers from a file and finds the distance...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Complete load_pts_file function that reads multiple pairs of numbers from a file and finds the distance between every two numbers on a number line: Few steps as the guidance 1) Open/Read the .dat file into a pre-allocated given space, data_buffer. 2) The format is fixed in every single line of the file, parse the content and interpret each as an integer number. 3) Finding distances from the every-two-number, iteratively store the distance to an integer array (note: the base address is given in $a1). 4) Return the number of distances calculated. For example, Integer Array for lab3_pts.dat Return Value Distances 12 11 12 -34 11-12 [Before] [-1, -1, -1, -1, -1] [After] [1, 1, 7, 23, -1] The above example shows that load_pts_file function - opens/reads lab3_pts.dat file (into data_buffer), - parses and interprets '1' as the integer numbers, 1, and '2' as 2 - finds the distance of 1 and 2 to be 1 and updates the distance array - repeats the above two until the end of file, then returns 4 distances calculated. NOTE: you can safely assume I. the file will strictly follow such format in every single line. II. there will be at least one line in the file. III. The file won't exceed 300 bytes, i.e. you don't need to worry about out of memory in the given space, data_buffer. IV. The default values in data_buffer were all O. Arguments and Given parameters: >> $a0: the address of the string that represents the input file name, "lab3_pts.dat". >> $a1: the base address of an integer array that will be used to store distances >> data_buffer: the buffer that you use to hold data for file read/write (MAXIMUM: 300 bytes) # PART 3A (SYSCALL: file read, ASCII to Integer) # $a0: the address of the string that represents the input file name # $al: the base address of an integer array that will be used to store distances # data_buffer: the buffer that you use to hold data for file read (MAXIMUM: 300 bytes) load pts_file: li $v0, 13 Part 3A: your code begins here ## # system call for open file # a0 is already ready for file name li $a1, 0 li $a2, 0 syscall move $10, $v0 li $v0, 14 move $a0, $10 la li syscall # Open for reading (flags are 0: read, 1: write) # mode is ignored # open a file (file descriptor returned in $v0) # save the file descriptor # system call for read file # file descriptor $al, data_buffer # address of buffer from which to read $a2, 300 #max hardcoded buffer length # read file li $v0, 16 # close file move $20, $10 # file descrip to close syscall ### Part 3A: your code ends here ## jr $ra Complete load_pts_file function that reads multiple pairs of numbers from a file and finds the distance between every two numbers on a number line: Few steps as the guidance 1) Open/Read the .dat file into a pre-allocated given space, data_buffer. 2) The format is fixed in every single line of the file, parse the content and interpret each as an integer number. 3) Finding distances from the every-two-number, iteratively store the distance to an integer array (note: the base address is given in $a1). 4) Return the number of distances calculated. For example, Integer Array for lab3_pts.dat Return Value Distances 12 11 12 -34 11-12 [Before] [-1, -1, -1, -1, -1] [After] [1, 1, 7, 23, -1] The above example shows that load_pts_file function - opens/reads lab3_pts.dat file (into data_buffer), - parses and interprets '1' as the integer numbers, 1, and '2' as 2 - finds the distance of 1 and 2 to be 1 and updates the distance array - repeats the above two until the end of file, then returns 4 distances calculated. NOTE: you can safely assume I. the file will strictly follow such format in every single line. II. there will be at least one line in the file. III. The file won't exceed 300 bytes, i.e. you don't need to worry about out of memory in the given space, data_buffer. IV. The default values in data_buffer were all O. Arguments and Given parameters: >> $a0: the address of the string that represents the input file name, "lab3_pts.dat". >> $a1: the base address of an integer array that will be used to store distances >> data_buffer: the buffer that you use to hold data for file read/write (MAXIMUM: 300 bytes) # PART 3A (SYSCALL: file read, ASCII to Integer) # $a0: the address of the string that represents the input file name # $al: the base address of an integer array that will be used to store distances # data_buffer: the buffer that you use to hold data for file read (MAXIMUM: 300 bytes) load pts_file: li $v0, 13 Part 3A: your code begins here ## # system call for open file # a0 is already ready for file name li $a1, 0 li $a2, 0 syscall move $10, $v0 li $v0, 14 move $a0, $10 la li syscall # Open for reading (flags are 0: read, 1: write) # mode is ignored # open a file (file descriptor returned in $v0) # save the file descriptor # system call for read file # file descriptor $al, data_buffer # address of buffer from which to read $a2, 300 #max hardcoded buffer length # read file li $v0, 16 # close file move $20, $10 # file descrip to close syscall ### Part 3A: your code ends here ## jr $ra
Expert Answer:
Related Book For
Introduction to Java Programming, Comprehensive Version
ISBN: 978-0133761313
10th Edition
Authors: Y. Daniel Liang
Posted Date:
Students also viewed these databases questions
-
CANMNMM January of this year. (a) Each item will be held in a record. Describe all the data structures that must refer to these records to implement the required functionality. Describe all the...
-
can someone solve this Modern workstations typically have memory systems that incorporate two or three levels of caching. Explain why they are designed like this. [4 marks] In order to investigate...
-
A New York Times editorial argued that college students are taken advantage of by credit card companies: The credit card industry has made a profitable art of corralling consumers into ruinous...
-
a. Show that the polynomial nesting technique described in Example 6 can also be applied to the evaluation of f (x) = 1.01e4x 4.62e3x 3.11e2x + 12.2ex 1.99. b. Use three-digit rounding arithmetic,...
-
On January 1, Dora purchases 175 of the $1,000, 7%, 15-year bonds issued by Splash City, with interest receivable semiannually on June 30 and December 31 each year. Assuming the market interest rate...
-
A realtor uses a lock box to store the keys to a house that is for sale. The access code for the lock box consists of five digits. The first digit cannot be zero or nine and the last digit must be a...
-
World Boards Co. is a merchandising business. The account balances for World Boards Co. as of March 1, 2008 (unless otherwise indicated), are as follows: During March, the last month of the fiscal...
-
Pharoah Company operates a small factory in which it manufactures two products: A and B. Production and sales results for this year were as follows: A B Units sold 9,200 18,300 Selling price per unit...
-
CMS declined to create a rebuttable presumption that a transaction is fair market value. CMS's conclusion? What are the practical and policy implications of CMS's decision in this regard?
-
The friendly old woman sold 38 long-stemmed roses on street corner A and 45 on street corner B (all at the same price ). If the old woman sold $124.50 in total. What was the price of each rose?
-
A trail mix comprised of 47% peanuts is being mixed with a trail mix variety that is 71% peanuts to create a 61.8 lb. bag of trail mix that is 63% peanuts. How many pounds of the 47% peanuts trail...
-
1,-4,2,-3,-7,-6 If each number in the list above were to be multiplied by -3 , a new list would be formed consisting of the six products. How many of the six numbers on the new list would be negative...
-
the height of a certain tree will increase by 3% each year for the next six years, and then decrease by 5% over the following year. Compared tw today, how tall will the tree be seven years from now?
-
Discuss at least one key advantage of a two-way ANOVA, in comparison to the one-way ANOVA. Explain.
-
Use the data shown in the table to conduct a design of experiment (DOE) in order to test cause-and-effect relationships in business processes for the company. Determine the graphical display tool...
-
Q1) What is the a3 Value Q2) What is the a7 Value Q3) What is the a4 Value Q4) What is the b3 Value Q5) What is the b2 Value Q6) What is the sign of 2nd constraint? A pastry chef at a bakery wants to...
-
External auditors collect consulting fees from the same clients they perform independent audits for, which allows good and close relationship with the clients. True/false
-
To deal with the turmoil caused by the various accounting scandals, the SOX Act was passed in 1999. True/false
-
Auditors should not demand full access to the entire general ledger so that they can be more focused on the audit. True/false
Study smarter with the SolutionInn App