added exercises and more detailed answers

This commit is contained in:
Perry Kivolowitz 2022-05-19 10:46:39 -05:00
parent 68d49161cb
commit cbb9044442
2 changed files with 23 additions and 7 deletions

View file

@ -496,7 +496,8 @@ We do maintain that understanding assembly language principles will improve your
(T | F) It is the compiler's job to reduce a higher level language to assembly language.
Answer: True
Answer: True - The "compiler" is just one step in the "compilation" process. In fact it
is step 2. Invoking the "preprocessor" is step 1.
### 2
@ -508,7 +509,8 @@ Answer: False - a linker error will happen, not a syntax error.
\___ and ___ implement the braces in C and C++.
Answer: labels and branches.
Answer: labels and branches - the closing brace of a `while` loop for example,
is a branch instruction.
### 4
@ -519,7 +521,8 @@ if a_register has value 0
then goto label
```
Answer: True
Answer: True - `cbz` stands for "compare and branch if zero". There is also
a `cbnz` instruction. To test for other Boolean conditions, use `cmp`.
### 5

View file

@ -1,4 +1,4 @@
# The `if` statement
# Section 1 / Chapter 2 / The `if` Statement
We will begin with the `if` statement followed by a discussion of the `if / else`.
@ -175,9 +175,11 @@ T: .asciz "TRUE" // 24
In this case, the label `T` corresponds to the address to the first
letter of the C string "TRUE".
The occurrences of `.asciz` are invocations of an *assembler directive*
the creates a C string. Recall that C strings are NULL terminated. The
NULL termination is indicated by the `z` which ends `.asciz`.
The occurrences of `.asciz` on `line 23` and `line 24` are invocations of
an *assembler directive* the creates a C string. Recall that C strings are NULL
terminated. The NULL termination is indicated by the `z` which ends `.asciz`.
There is a similar directive `.ascii` that *does not NULL terminate* the
string.
## Summary
@ -197,8 +199,19 @@ allow a branch to that code block, such as the beginning of an `else`.
### 1
(T | F) If statements in assembly language always test for the opposite condition
as the equivalent `if` statement in a high level language.
Answer: False - it is a matter of style but you may be able to
save an instruction or two by doing so.
### 2
(T | F) `cmp` isn't a "real" instruction but rather is an alias for a subtraction.
Answer: True - `cmp` is an alias for `subs` which is a subtract that discards the
resulting value but does set the condition bits.
### 3
### 4