Hardware Reference
In-Depth Information
in reverse order, we first push the number of bytes, then the address of the start of
the buffer, then the file descriptor and finally the call number ( READ or WRITE ).
This order of stacking the arguments was chosen to be the same as the standard C
language calling sequence in which
read(fd, buffer, bytes);
is implemented by pushing the parameters in the order bytes , buffer , and finally fd .
The CLOSE call requires just the file descriptor and returns 0 in AX if the file
could be closed successfully. The EXIT call requires the exit status on the stack and
does not return.
The LSEEK call changes the read/write pointer in an open file. The first argu-
ment is the file descriptor. Since the second argument is a long, first the high-order
word, then the low word should be pushed onto the stack, even when the offset
would fit into a word. The third argument indicates whether the new read/write
pointer should be computed relative to the start of the file (case 0), relative to the
current position (case 1), or relative to the end of the file (case 2). The return value
is the new position of the pointer relative to the start of a file, and can be found as a
long in the DX : AX register combination.
Now we come to the functions that are not system calls. The GETCHAR func-
tion reads one character from standard input, and puts it in AL . AH is set to zero.
On failure, AX is set to
1. The call PUTCHAR writes a byte on standard output.
The return value for a successful write is the byte written; on failure it is
1.
The call PRINTF outputs formatted information. The first argument to the call
is the address of a format string, which tells how to format the output. The string
''%d'' indicates that the next argument is an integer on the stack, which is con-
verted to decimal notation when printed. In the same way, ''%x'' converts to hex-
adecimal and ''%o'' converts to octal. Furthermore, ''%s'' indicates that the next
argument is a null-terminated string, which is passed to the call through a memory
address on the stack. The number of extra arguments on the stack should match
the number of conversion indications in the format string.
For example, the call
printf(
′′
x = %d and y = %d\n
′′
,x,y);
prints the string with the numerical values of x and y substituted for the ''%d''
strings in the format string. Again, for compatibility with C, the order in which the
arguments are pushed is ''y'', ''x'', and finally, the address of the format string.
The reason for this convention is that printf has a variable number of parameters,
and by pushing them in the reverse order the format string itself is always the last
one and thus can be located. If the parameters were pushed from left to right, the
format string would be deep in the stack and the printf procedure would not know
where to find it.
In the call PRINTF , the first argument is the buffer, to receive the output string,
instead of standard output. The other arguments are the same as in PRINTF .
The
 
Search WWH ::




Custom Search