5.36 · exercise

Monster roster

Find the monster with the most hit points in a roster of up to eight, which the starter reads into roster, an array of structures. Each input line is a name of up to five letters, the monster's hit points, and its attitude, for example Troll 88 -35. Print the monster with the most hit points in this form:

strongest: Troll, 88 hp, attitude -35

If two monsters tie, the one listed first wins. If the roster has no monsters, print the roster is empty instead.

A structure (a struct in C) is a group of fields stored side by side, each at a fixed distance, its offset, from the start of the structure. The starter names the offsets: the name at 0, the attitude at 6, the hit points at 8, and each monster takes 12 bytes, so monster i starts at roster + i * 12. Load each field with its own size. The attitude is a signed halfword (16 bits): a 32-bit load at its offset would also pick up two bytes of the hit points, and an unsigned load turns -35 into 65501.

What is checked

  • one line naming the strongest monster, or the empty-roster line
  • the program exits cleanly
  • the attitude is loaded as a signed halfword (ldrsh present)
  • your program also runs on rosters you do not see: a tie, a single monster, an empty roster, the strongest listed last, and a roster where every monster has negative hit points

specification

stdin4 Imp 12 -80 Orc 45 -20 Troll 88 -35 Pixie 9 60
stdoutprints the right output
exitexits with the right code
sourceuses ldrsh
hiddenright output and exit code on 6 more inputs you do not see

We run your program on the input above and on the hidden ones, and compare what it does. Nothing is matched against a stored solution.

loading editor...

regfile

N clearZ clearC clearV clear

x0–x30 are the integer registers.

X0arg00x0000000000000000
X1arg10x0000000000000000
X2arg20x0000000000000000
X3arg30x0000000000000000
X4arg40x0000000000000000
X5arg50x0000000000000000
X6arg60x0000000000000000
X7arg70x0000000000000000
X8ind0x0000000000000000
X90x0000000000000000
X100x0000000000000000
X110x0000000000000000
X120x0000000000000000
X130x0000000000000000
X140x0000000000000000
X150x0000000000000000
X16ip00x0000000000000000
X17ip10x0000000000000000
X18pr0x0000000000000000
X190x0000000000000000
X200x0000000000000000
X210x0000000000000000
X220x0000000000000000
X230x0000000000000000
X240x0000000000000000
X250x0000000000000000
X260x0000000000000000
X270x0000000000000000
X280x0000000000000000
X29fp0x0000000000000000
X30lr0x0000000000000000
SP0x0000000080000000
PC0x0000000000400000
console

Output prints here as your program runs.

Press step or run under the editor, or feed stdin from the box below.

not assembled

Open in playground