aarch64-pgaarch64 playgroundsheet 05 · practice
05 · practice
Exercises
Coding exercises on the left, checked by running your program against expected behavior rather than a stored solution. Theory sets on the right, graded on the page. Both follow the course from the first week to the last.
code
Coding exercises
Write the program. The emulator runs it and checks the result, never a stored solution.
27 exercises
armv8 basics· 1
branching· 2
loops· 9
- 5.4Fix the loop boundThis program should compute `n` factorial, the product `1 * 2 * ... * n`, and print it. With `n` set to 5 it runs and prints a number, but t...core
- 5.5The overeager counterThis countdown should print `5` through `1` and stop. Run it and look closely at the output: it goes one line too far.intro
- 5.6Sum from one to nWrite a loop that adds up every integer from 1 to `n` and prints the total.core
- 5.7Count by sevensPrint every multiple of seven from 7 up to and including 70, one per line.intro
- 5.8The multiplication tablePrint the four-by-four multiplication table, rows of `row * col` padded into neat columns.core
- 5.9Fizzbuzz, by handThe classic interview question, on a machine with no remainder instruction: print the numbers 1 through 15, except say `fizz` for multiples ...core
- 5.10gcd, the Euclid wayEuclid noticed around 300 BC that the greatest common divisor of two numbers does not change when you replace the larger with the remainder ...core
- 5.11Reverse the digitsTake `9317` and print `7139`: the same digits, reversed, as a number.core
- 5.12Fibonacci goes largeCompute the fiftieth Fibonacci number. It is 12,586,269,025, which does not fit in 32 bits, so the loop has to run in `x` registers.core
bitwise· 3
- 5.13Binary broadcastPrint `99` the way the machine sees it: eight binary digits, `01100011`.core
- 5.14Bit population censusHow many bits of `0xb7a5` are set? Count them with a loop.core
- 5.15Double, double, doubleMultiplying by a power of two never needs a multiply: shifting left by one bit doubles a value, and doing it three times multiplies by eight...intro
arrays· 3
- 5.16Min-max tournamentFind the smallest and the largest element of the eight-entry array in one pass, and print both.core
- 5.17Sum a global arrayA global array of eight scores lives in `.data`, and its length sits beside it. Add every element and print the total.core
- 5.18Bubble up the orderSix values sit in a tangle in `.data`. Bubble sort them in place, smallest first; the print loop at the bottom will show whatever order the ...challenge
strings· 2
- 5.19Count the vowelsA sentence lives in `.data` (a famous one: it uses every letter of the alphabet). Count its vowels.core
- 5.20Caesar's little secretThe string in `.data` was encrypted the way Julius Caesar liked it: every letter shifted three places forward, wrapping around the end of th...challenge
memory and the stack· 3
- 5.21Stack of platesFour plates go into the frame, and they come back out top-first: store `21`, `34`, `55`, `89` into the four named stack slots, then load and...core
- 5.22The leaky frameThis program stashes a lucky number in its stack frame and prints it back. It should print one line. Run it: the program dies before printin...challenge
- 5.23The vanishing valueThis program swaps two registers, then prints them in their new order. Run it: one of the values has vanished, and the other now appears twi...core
functions· 2
- 5.24The forgetful helper`main` keeps a running total of 100 in `x19`, asks a helper to double a bonus of 20, and adds the result. The total should be 140. Run it: i...challenge
- 5.25Call yourselfWrite `fact`, a subroutine that computes a factorial by calling itself, and use it to print `10!`.challenge
input and output· 1
command-line arguments· 1
theory
Theory sets
Quizzes, fill-in-the-blank drills, and mental traces, graded on the page.
44 exercises
system architecture· 4
- 5.28Quiz: system architectureCovers the parts of a CPU, volatile and non-volatile memory, what RISC means, the fetch-execute cycle, and comment syntax in AArch64 source.intro
- 5.29Quiz: system architectureThe machine model behind AArch64 assembly: where code and data live, which instructions are allowed to touch memory, what the system bus car...core
- 5.30Quiz: system architectureRISC versus CISC machine code, where `m4` expansion fits into the build, and how a load/store machine moves data between memory and the regi...challenge
- 5.31Fill in the blank: system architectureFill in the missing terms: the parts of a CPU, the clock that paces it, the register that tracks execution, and the marker that starts a com...core
binary logic· 5
- 5.32Quiz: binary logicTwo's complement negation, the sign bit, how many bits one hexadecimal digit carries, what a logical shift left does to a value, and the ins...intro
- 5.33Quiz: binary logicLogical instructions and their aliases, shifts and sign extension, and the integer widths and number bases behind them.core
- 5.34Quiz: binary logicBitfield insert and extract, arithmetic versus logical shifts, and two's complement negation.challenge
- 5.35Fill in the blank: binary logicFill in the missing mnemonic on each line so it performs the bitwise or shift operation described.core
- 5.36Predict: binary logicFor each shift, mask, and sign-extension snippet, give the exact value left in the destination register.challenge
binary arithmetic· 5
- 5.37Quiz: binary arithmeticHow a CPU does integer arithmetic in fixed-size registers: modulus wraparound, subtraction through negation, the meaning of a carry out, `ad...intro
- 5.38Quiz: binary arithmeticHow fixed-width arithmetic wraps, what a carry out of the most significant bit means, which flags the signed and unsigned branch conditions ...core
- 5.39Quiz: binary arithmeticExtended-precision carry chains, the shift-and-add multiplication algorithm, and the flag rules behind signed comparison.challenge
- 5.40Fill in the blank: binary arithmeticFill in the missing mnemonics and condition codes so each instruction performs the arithmetic or the unsigned branch described.core
- 5.41Predict: binary arithmeticTrace fixed-width wraparound, carry propagation across a pair of adds, and a signed widening multiply.challenge
armv8 basics· 5
- 5.42Quiz: ARMv8 assemblyHow AArch64 splits privilege across exception levels, which registers a call may clobber, what integer division by zero produces, how gdb st...intro
- 5.43Quiz: ARMv8 assemblyArgument registers, instruction aliases, the frame record, integer division, condition flags, and stepping in gdb.core
- 5.44Quiz: ARMv8 assemblyConvert a loop by hand, then account for exception levels, the program counter, multiply-accumulate, and integer division by zero.challenge
- 5.45Fill in the blank: ARMv8 assemblyFill in the missing mnemonics, suffixes, and symbols across stack frames, flag setting, branching, and gdb stepping.core
- 5.46Predict: ARMv8 assemblyPredict the register values and flags these AArch64 snippets leave behind.challenge
arrays· 5
- 5.47Quiz: arrays and structuresHow arrays and structures are laid out in memory, and how AArch64 code computes the address of a single element or field.intro
- 5.48Quiz: arrays and structuresAddress arithmetic for one- and two-dimensional arrays, scaled register offsets, and the constant offsets that reach struct fields.core
- 5.49Quiz: arrays and structuresOffset arithmetic for multi-dimensional arrays and padded structures, scaled register addressing, and the constant that allocates an aligned...challenge
- 5.50Fill in the blank: arrays and structuresFill in the missing mnemonics, extend options, and offsets that reach array elements and struct fields.core
- 5.51Predict: arrays and structuresBlock sizes and byte offsets: how a C array declaration maps onto an AArch64 memory operand.challenge
memory and the stack· 5
- 5.52Quiz: memory and the stackCheck the basics: address size, which way the stack grows, the 16-byte alignment rule for `sp`, the job of the frame pointer, and how a byte...intro
- 5.53Quiz: memory and the stackAddressing modes, locals reached by frame-pointer offset, and the 16-byte alignment sp has to keep.core
- 5.54Quiz: memory and the stackRegister-offset addressing with sign extension and shifts, plus the pre-indexed and post-indexed forms that build and tear down a frame reco...challenge
- 5.55Fill in the blank: memory and the stackFill in the missing mnemonics, registers, directives, and symbols that complete these AArch64 instructions.core
- 5.56Predict: memory and the stackTrace the memory addresses and register values through these snippets. Write hex answers as 0x followed by the digits, and decimal answers a...challenge
subroutines· 5
- 5.57Quiz: subroutinesOpen and closed subroutines, the argument and result registers, and how `bl` and `ret` carry the return address.intro
- 5.58Quiz: subroutinesFollow a call through the AArch64 procedure call convention: the link register, the frame record chain, saved registers, argument passing, a...core
- 5.59Quiz: subroutinesThe procedure call standard: when a leaf routine can skip its frame, what 16-byte alignment actually demands, who prepares stack-passed argu...challenge
- 5.60Fill in the blank: subroutinesFill in the missing mnemonics and registers that let an AArch64 subroutine be called, build a frame, return a result, and hand back the regi...core
- 5.61Predict: subroutinesTrace the register states and stack allocations a subroutine call sets up.challenge
external data· 5
- 5.62Quiz: external dataWhere a program's data lives in `.data`, `.bss`, and `.text`, how character constants are written, and how `argc` and `argv` reach `main`.intro
- 5.63Quiz: external dataWhere a program's data lives: the `.text`, `.data`, and `.bss` sections, the string pseudo-ops, and how `adrp` forms an address.core
- 5.64Quiz: external dataSymbol scope, PC-relative address formation with `adrp` and `add`, section permissions, and indexing an array of pointers.challenge
- 5.65Fill in the blank: external dataFill in the missing pieces of data declared outside a function: a `.bss` reservation, `.data` values and string literals, cross-file symbol ...core
- 5.66Predict: external dataHow bytes land in `.data`: the size of each directive, what a string literal costs, how a table of addresses is indexed, and what happens to...core
floating point· 5
- 5.67Quiz: floating pointHow the single and double precision views of one register differ, which directives place floating-point values in memory, what operands the ...intro
- 5.68Quiz: floating pointSingle and double precision registers, which ones a subroutine has to preserve, conversions between the two formats, and the rules for arith...core
- 5.69Quiz: floating pointThe callee-saved `d` registers, the `fmov` immediate range, conversions between integers and floats, and the fused multiply-add family.challenge
- 5.70Fill in the blank: floating pointFill in the missing directive, mnemonics, and gdb command used to declare floating-point values in memory, convert an integer to single prec...core
- 5.71Predict: floating pointTrace single and double precision arithmetic by hand: add, fused multiply-add, multiply-negate, and the two sign-only instructions. Every an...core
progress: