From cbb9044442f907bd1209736c0fcdd6aa9fa8f1ec Mon Sep 17 00:00:00 2001 From: Perry Kivolowitz Date: Thu, 19 May 2022 10:46:39 -0500 Subject: [PATCH] added exercises and more detailed answers --- section_1/hello_world/README.md | 9 ++++++--- section_1/if/README.md | 21 +++++++++++++++++---- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/section_1/hello_world/README.md b/section_1/hello_world/README.md index 939d44d..d5a8057 100644 --- a/section_1/hello_world/README.md +++ b/section_1/hello_world/README.md @@ -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 diff --git a/section_1/if/README.md b/section_1/if/README.md index 1a30d52..482a25c 100644 --- a/section_1/if/README.md +++ b/section_1/if/README.md @@ -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