From 9ec7bbcb17c20c1260cc6d9d7f3d7d7544056902 Mon Sep 17 00:00:00 2001 From: Perry Kivolowitz Date: Thu, 16 Jun 2022 08:57:39 -0500 Subject: [PATCH] modifications to pi project --- README.md | 7 +++-- projects/PI/README.md | 68 +++++++++++++++++++++++++++++++++++++++---- 2 files changed, 68 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index f0b3c22..fb1d77d 100644 --- a/README.md +++ b/README.md @@ -61,8 +61,11 @@ the 64 bit ARM Instruction Set Architecture (ISA). | .... a | [.... Alignment](./section_1/structs/alignment.md) | | .... b | [.... Defining](./section_1/structs/defining.md) | | .... c | [.... Using](./section_1/structs/using.md) | -| 8 | [`const`](./section_1/const/README.md) -| 9 | [Casting](./section_1/casting/README.md) | +| 8 | [`const`](./section_1/const/README.md) +| 9 | [Casting](./section_1/casting/README.md) | +| 10 | Floating Point | +| .... a | [ .... What Are Floating Point Numbers? ](./section1/float/what.md) + ## Section 2 - Stuff diff --git a/projects/PI/README.md b/projects/PI/README.md index 8c9a792..5f382e9 100644 --- a/projects/PI/README.md +++ b/projects/PI/README.md @@ -24,11 +24,11 @@ must multiply by 4 at the end. This will come from the command line as in: ```text -user@comporg:~/pi $ ./a.out 100000 +~/pi $ ./a.out 100000 Executing: 100000 iterations. Hits: 78443 Approximation: 3.137720 -user@comporg:~/pi $ +~/pi $ ``` If the command line argument is *not* given, use a default of 100000. @@ -39,7 +39,8 @@ Remember that all AARCH64 instructions are 32 bits long. An implication of this mov x0, 1000000 ``` -Since the constant cannot fit along with op codes into four bytes. A way to get around this that comes readily to mind +Since the constant cannot fit along with op codes into four bytes. +A way to get around this that comes readily to mind is to put the constant in RAM and `ldr` it into a register. ## Vetting the command line argument @@ -69,12 +70,12 @@ You must seed the RNG in this way. But in assembly language. C and C++ you would do: ```c++ -// Produces result between 0 and very very close to 1. +// Produces result between 0 and 1. float v = float(rand()) / float(RAND_MAX); ``` You must do this in your program. What value is RAND_MAX? Write a tiny C++ program on the ARM and print out the value. Or, put -`RANDMAX` into an IDE and ask the IDE to locate the definition. +`RANDMAX` into an IDE and ask the IDE to locate its definition. You must write a subroutine (function) which returns a random number in the right range. Call it `randf` so I can find it easily. @@ -97,6 +98,63 @@ restored in functions. You'll use instructions like `fmul`, `fdiv`, `fsqrt`, `fmov` and `fcmp`. +## Aliases For Registers + +We have previously advised you to create a "bible" documenting +which registers are used for what. Here is another way of aiding +you to: + +* better understand your code, and + +* avoid using the wrong register in an instruction. + +The idea is to give specific registers aliases, symbolic names +that mean something to your code rather than just a letter and +number. Here is an example: + +```asm +LOOP_MX .req x19 +LOOP_CT .req x20 +HITS .req x21 + +RND_MF .req d20 +DTMP .req d21 +``` + ## Printing FP `printf` will be your friend. Like always, the format string address goes in `x0`. A `%f` found in the format string tells `printf` to look in the FP registers starting with `d0` as the first value. + +## Added Challenge + +The program as specified above will print its result only at +the end of its computation. If you specify a very large number +of loops, this can take a long time. The shell prompt will +just sit and you won't know if your program is working or +not. + +As an added challenge, add functionality that tests the +loop counter and from time to time, such as every 2048 +loops, prints the results so far. + +Note that this can produce a lot of lines of output. To +deal with this, create a single line format string (for +`printf()`) that also prints some *old school* cursor +control sequences. + +Add this to your single line intermediate results: + +```text +\033[1;1H\033[2J +``` + +These characters will be interpreted by the terminal +(console) as meaning: + +* Move the cursor to line 1 column 1, and + +* Erase everything below this position. + +`\033` is the ESCAPE character represented by its +value in *octal*. *Octal* is indicated by the leading +bash (back slash) and the leading 0.