10.5 Some Additional Hints

When a file is redirected as input, system service 3 tries to read in the number of bytes as specified. This means it does not return when there is a linefeed in the input. To get around this problem, it may be easier to restrict the program to read a byte at a time, and look for end-of-line (the linefeed character) in your code. You have to do this anyway, even if the system service reads one line at a time.

System service 3 returns a value in eax. When the system service reads successfully, eax returns the number of bytes actually read. At the end of file, eax returns a 0 because it cannot read past the end of a file. Use this to terminate the outer so you can exit the program.

I did not know that in div, the register that will eventually store the remainder supplies the most significant portion of the divident. As a result, you need to initialize dx to zero right before the divw instruction.

Copyright © 2009-04-16 by Tak Auyeung