diff --git a/tutorial/index.md b/tutorial/index.md index 2ec0af6a..95eec2bb 100644 --- a/tutorial/index.md +++ b/tutorial/index.md @@ -264,3 +264,19 @@ trying out the next one.) Runbooks are a handy tool for working with computers. In a runbook you write instructions to your future self or for others you're working with. They're instructions for programming people, not computers. + +## Task 7: variables in registers, variables in memory (again) + +Go back to your program in Task 5. Replace the first statement declaring +variable `x`: +``` +var x: int +``` + +so it looks like this: +``` +var x/edx: int <- copy 0 +``` + +Run `translate` (or `translate_emulated`) as usual. Use your runbook from Task +6 to address the errors that arise. diff --git a/tutorial/task7-solution.mu b/tutorial/task7-solution.mu new file mode 100644 index 00000000..9611e0a8 --- /dev/null +++ b/tutorial/task7-solution.mu @@ -0,0 +1,18 @@ +fn foo -> _/eax: int { + var x/edx: int <- copy 0 + # statement 1: store 3 in x + x <- copy 3 + # statement 2: define a new variable 'y' in register eax and store 4 in it + var y/eax: int <- copy 4 + # statement 3: add y to x, storing the result in x + x <- add y + return x +} + +fn test-foo { + var result/eax: int <- foo + check-ints-equal result, 7, "F - foo should return 7, but didn't" +} + +fn main { +} diff --git a/tutorial/task7.mu b/tutorial/task7.mu new file mode 100644 index 00000000..817b5825 --- /dev/null +++ b/tutorial/task7.mu @@ -0,0 +1,18 @@ +fn foo -> _/eax: int { + var x/edx: int <- copy 0 + # statement 1: store 3 in x + copy-to x, 3 + # statement 2: define a new variable 'y' in register eax and store 4 in it + var y/eax: int <- copy 4 + # statement 3: add y to x, storing the result in x + add-to x, y + return x +} + +fn test-foo { + var result/eax: int <- foo + check-ints-equal result, 7, "F - foo should return 7, but didn't" +} + +fn main { +}