5.20 · exercise

sum a global array

A global array of eight scores lives in .data, and its length sits beside it. Add every element and print the total.

This is the course's array idiom in one loop: a base address in an x register, a word index in a w register, and the scaled-index load ldr wX, [base, wI, sxtw 2], which sign-extends the index and shifts it left two bits to turn a word count into a byte offset.

what is checked

  • the total is printed on its own line
  • the program exits cleanly
  • elements are loaded with the scaled-index form (sxtw present, total not written in)

Specification

args
stdoutprints the expected output
exitexits with the expected code
sourceuses sxtw
sourcecomputes the result (does not hardcode it)

Checked by running your program against expected behavior, never by matching a stored solution.

loading editor...
Open in playground