Integer I/O So that we can ultimately create some more interesting test programs, letâs add I/O for 16-bit unsigned integers to our system. We will need functions void readInt(int) and void writeInt(int). They are pretty much inverses of each other: readInt(int n) { *n = 0; use readString() to get input; convert the input string to its numeric value n; } writeInt(int x) { convert x to a string; use printString() to output; } 3460:4/526 Lab 2: Interrupt-Driven I/O Page 2 (Use interrupt 33, options 1 and 0 instead of readString() and printString(), respectively, in the final version of your code.) The problem is now converting integers to and from ASCII strings. These are common questions that turn up in job interviews; see http://www.programminginterview.com/content/strings. The trick now is to rewrite those functions to work under the restrictions of 16-bit ANSI C. For one thing bcc does not support integer division and modulus as primitive functions, so we have to provide them ourselves: int mod(int a, int b) { int x = a; while (x >= b) x = x - b; return x; } int div(int a, int b) { int q = 0; while (q * b <= a) q++; return (q - 1); } One thing that helps us is the fact that, since we are dealing exclusively with 16-bit integers, there are at most five digits (MAX_INT = 32767) to print with no sign. (We really should worry about overflow and underflow but wonât for now.) We also have to treat the integer zero as a special case
What are the codes for void readInt(int*) and void writeInt(int) ?