5.28 · exercise

argv arithmetic

Every number on the command line gets added into one total. The args box already holds four of them.

main receives argc in x0 and argv, an array of string pointers, in x1. Entry zero is the program's own name, so start at one. Each entry is eight bytes, which is what the scaled form ldr x0, [argv_r, i_r, lsl 3] is for; bl atoi turns the string into a number.

Change the args box and run again: the total should follow.

what is checked

  • the total of the arguments is printed on its own line
  • the program exits cleanly
  • the numbers really come from argv (atoi called, total not written in)

Specification

args12 7 30 4
stdoutprints the expected output
exitexits with the expected code
sourceuses atoi
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