High score keeper
An arcade machine keeps its best score in a file called best.dat, so the record outlives any one game. Standard input gives a count and then that many scores. For each score, look at the file: if it does not exist yet, the score becomes the first record; if the score is higher than the saved one, it replaces it; otherwise the record stands. At the end, print the record from the file.
With the stdin box as given the program prints:
first score: 120
95 does not beat 120
new best: 180 (was 120)
180 does not beat 180
high score: 180
Talk to the file with system calls (requests the operating system carries out for your program): put the service number in x8, the arguments in x0 to x3, and run svc 0; the answer comes back in x0.
openat(56):x0=AT_FDCWD(the current folder),x1= the file name,x2= the flags,x3= the permission mode. The flags are bits, written in octal: 0 opens for reading, and01101asks for writing (01), creating the file when it is missing (0100), and emptying it when it is not (01000). A mode of0644lets the owner write it and everyone read it. A negative answer means the open failed; otherwise the answer is a file descriptor, the number you pass to the other calls.read(63) andwrite(64):x0= the descriptor,x1= the address of the memory to read into or write from,x2= how many bytes.close(57):x0= the descriptor.
The file holds the score as 8 raw bytes, exactly as the number sits in memory in saved, so one 8-byte read or write moves the whole thing. Scores can be larger than a 32-bit register holds.
What is checked
- every line for the scores in the stdin box, and for more score lists you cannot see
- the program exits cleanly
- the file work goes through system calls (
svcpresent)
specification
svcWe run your program on the input above and on the hidden ones, and compare what it does. Nothing is matched against a stored solution.