Question: 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:

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
Step by Step Solution
There are 3 Steps involved in it
Sure lets create the function loadptsfile step by step to accomplish the task described 1 Open and read the file into the databuffer 2 Parse the content line by line 3 Extract pairs of numbers and com... View full answer
Get step-by-step solutions from verified subject matter experts
