There are several ways to write tail. In order to gain familiarity with assembly language you must use the following algorithm. Read the entire input, keeping the last 4096 characters read in a buffer. Thus, at the end of the input, the buffer will contain the last 4096 characters of the input, or the entire input. The last 22 lines can be found by scanning backwards over the buffer looking for newline characters (character code 012), and these lines can be printed in a final forward scan through the buffer.
It's most efficient to maintain the buffer as a circular buffer. That is, when it fills up, subsequent input is placed at the front of the buffer. Thus, if the buffer is modeled as an array, buffer[0:4095], at the end of the input, the tail of the input is in buffer[j:4095] followed by buffer[0:k], where k<j and the length of the input is greater than 4096. If the length of the input, l, is less than 4096, the tail is in buffer[0:l-1].
Make sure your program handles boundary conditions correctly, for example, input with exactly 22 lines and 4096 characters, input with no characters, etc.
.seg "bss" global data -- initial value of zero .seq "data" global data .seg "text" .global _main .align 4 .proc 4 _main: save %sp, WINDOWSIZE ,%sp program body ret; restoreAssembler directives for both initialized and uninitialized data can appear in the global data area. For example, a 4096-byte buffer, called _buf, can be allocated with .common _buf, 4096. See SPARC Architecture, Assembly Language Programming, & C for syntactic details.
Execution begins by calling the procedure _main and terminates when _main returns via ret and restore instructions. To assemble, link, and load an assembly language program in a file, say, mytail.s, use the command:
lcc -o mytail -g mytail.slcc will call the assembler and linker for you. The -v option to lcc will show the commands that lcc executes.
/u/cs217/bin/submit 5 mytail.s,vwhere the mytail.s,v is the RCS file for your your implementation of tail.
Make sure your RCS file holds the latest revision when you submit it.
Due: submitted by 11:59pm, Mon. 4/1.