Review


Know the Concepts

  • What is a record?

  • What is the advantage of fixed-length records over variable-length records?

  • How do you include constants in multiple assembly source files?

  • Why might you want to split up a project into multiple source files?

  • What does the instruction incl record_buffer + RECORD_AGE do? What addressing mode is it using? How many operands does the incl instructions have in this case? Which parts are being handled by the assembler and which parts are being handled when the program is run?

Use the Concepts

  • Add another data member to the person structure defined in this chapter, and rewrite the reading and writing functions and programs to take them into account. Remember to reassemble and relink your files before running your programs.

  • Create a program that uses a loop to write 30 identical records to a file.

  • Create a program to find the largest age in the file and return that age as the status code of the program.

  • Create a program to find the smallest age in the file and return that age as the status code of the program.

Going Further

  • Rewrite the programs in this chapter to use command-line arguments to specify the filesnames.

  • Research the lseek system call. Rewrite the add-year program to open the source file for both reading and writing (use $2 for the read/write mode), and write the modified records back to the same file they were read from.

  • Research the various error codes that can be returned by the system calls made in these programs. Pick one to rewrite, and add code that checks %eax for error conditions, and, if one is found, writes a message about it to STDERR and exit.

  • Write a program that will add a single record to the file by reading the data from the keyboard. Remember, you will have to make sure that the data has at least one null character at the end, and you need to have a way for the user to indicate they are done typing. Because we have not gotten into characters to numbers conversion, you will not be able to read the age in from the keyboard, so you'll have to have a default age.

  • Write a function called compare-strings that will compare two strings up to 5 characters. Then write a program that allows the user to enter 5 characters, and have the program return all records whose first name starts with those 5 characters.




Programming from the Ground Up
Programming from the Ground Up
ISBN: 0975283847
EAN: 2147483647
Year: 2006
Pages: 137

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net