From 329a29ac42687a17a4fd7855fcc118bd4ae8e719 Mon Sep 17 00:00:00 2001 From: dluman Date: Thu, 12 Oct 2023 22:28:30 -0400 Subject: [PATCH] Adding README updates and sifter exercise --- README.md | 74 +++++++++++++++++++++++++++++++++++- sifter/.vscode/launch.json | 31 +++++++++++++++ sifter/.vscode/settings.json | 23 +++++++++++ sifter/CMakeLists.txt | 27 +++++++++++++ sifter/program.S | 25 ++++++++++++ sifter/sifter.S | 49 ++++++++++++++++++++++++ 6 files changed, 228 insertions(+), 1 deletion(-) create mode 100644 sifter/.vscode/launch.json create mode 100644 sifter/.vscode/settings.json create mode 100644 sifter/CMakeLists.txt create mode 100644 sifter/program.S create mode 100644 sifter/sifter.S diff --git a/README.md b/README.md index c2312ca..0134f02 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ print(s) Complete this work in [dynamo/program.S](dynamo/program.S). -Our automated station can sense really big space rocks. Like, _sufficiently big_. In this case that means ones measuring `20`-bits. On each rock signal we encounter that is _`20` bits or greater_, we should send out a dynamo to have a look and possibly take some samples so that we can characterize the type and quality of the rocks. (Don't worry: that work is up _next_.) +Our automated station can sense really big space rocks. Like, _sufficiently big_. In this case that means ones measuring `20 -bits. On each rock signal we encounter that is _`20` bits or greater_, we should send out a dynamo to have a look and possibly take some samples so that we can characterize the type and quality of the rocks. (Don't worry: that work is up _next_.) However, it's inefficient to do all of this in a long string of instructions. We've got to use what we've learned about the `link register` (`LR`) and stack to make this process as smooth as possible. @@ -54,6 +54,78 @@ An example outcome should look like: ... ``` +### Lab: The Sifter + +Once we get the rocks, we have to classify them. In our current operation, we collect `LUNAR` and `MARTIAN` rocks; then, we sort them into `HI` and `LOW` quality. Here're the rules: + +|Number start (base 16)| Type | +|:---------------------|:-----| +|`00` |`LUNAR`| +|`55` |`MARTIAN`| + +|Number end (base 16)| Quality | +|:---------------------|:-----| +|`FF` |`HIGH`| +|`00` |`LOW`| + +> Hints: +> * what are these numbers' decimal equivalents? +> * how can we get only the first `2` bytes and last `2` bytes alone? + +### Assignment "Hacks" + +See the `Suggestion` below to challenge yourself to implement a Hack. As always, you are allowed to develop +your own Hack to satisfy this stretch goal. Place the code for the Hack inline with the code in the corresponding +file. + +In order to recieve credit for the Hack, you must fill out the [hack.md](docs/hack.md) file located in the +`docs` folder. + +#### `dynamo` + +Negative values denote _very dangerous_ space junk. We have a blaster to demolish it, but it needs some work. However, we're really only concerned +about negative values above _20 bits_. Anything else will just bounce off our station's force field. + +**Note: you will need to use a new _signed number opcode_: `LDRSW`, which loads a _signed word_.** + +``` + +``` + +Implement the blaster by replacing the `signals` array in `program.S` with the above and print that we've `blasted` the junk +using a similar format to our dynamo's dispatch message. + +> Hint: you may need to engage with the `NEG` or other instruction; shifting may have unpredictable results! + +#### `sifter` + +Sometimes, as the saying (and reality) goes, sometimes junk gets lodged in a perfectly good space rock. Here, these scraps are denoted by negative numbers. However, sometimes, they contain technology that we might want to salvage -- especially if the most significant bits are `33`. If we encounter +a negative-signed sample, and it meets our criteria, we need to print the format string: + +```assembly + salvaged: .asciz "0x%08x\tSALVAGED." +``` + +Add the above to the `.data` section of the appropriate file. + +**Note: you will need to use a new _signed number opcode_: `LDRSW`, which loads a _signed word_.** + +##### New files + +For any `Hack`, you may choose to create a new file to do this; if you do, make sure you add the new file name to the [CMakeLists.txt](CMakeLists.txt) file in the `add_executable` directive: + +```cmake +add_executable(${PROJECT_NAME} + program.S + sifter.S + your_file_here.S +) +``` + +#### Make it your own + +You are free to develop your own "Hack" for this assignment. However, you'll need to be sure to justify the value of your hack clearly! + ### Changes to files in `.vscode` Based on your system setup (refer to your `hello-blinky` assignment), you will need switch out the `.vscode` folder in each exercise with the _last working copy_. diff --git a/sifter/.vscode/launch.json b/sifter/.vscode/launch.json new file mode 100644 index 0000000..78856c6 --- /dev/null +++ b/sifter/.vscode/launch.json @@ -0,0 +1,31 @@ +{ + "version": "0.2.0", + "configurations": [ + { "name": "Pico Debug", + "device": "RP2040", + "gdbPath": "${env:GDB_PATH}", + "cwd": "${workspaceRoot}", + "executable": "${command:cmake.launchTargetPath}", + "request": "launch", + "type": "cortex-debug", + "servertype": "openocd", + "configFiles": [ + "interface/cmsis-dap.cfg", + "target/rp2040.cfg" + ], + "searchDir": [ + "${env:OPENOCD_PATH}/tcl" + ], + "openOCDLaunchCommands": [ + "adapter speed 5000" + ], + "runToEntryPoint": "main", + "svdFile": "${env:PICO_SDK_PATH}/src/rp2040/hardware_regs/rp2040.svd", + "postRestartCommands": [ + "break main", + "continue" + ], + "showDevDebugOutput": "parsed" + } + ] +} diff --git a/sifter/.vscode/settings.json b/sifter/.vscode/settings.json new file mode 100644 index 0000000..02d0960 --- /dev/null +++ b/sifter/.vscode/settings.json @@ -0,0 +1,23 @@ +{ + // These settings tweaks to the cmake plugin will ensure + // that you debug using cortex-debug instead of trying to launch + // a Pico binary on the host + "cmake.statusbar.advanced": { + "debug": { + "visibility": "hidden" + }, + "launch": { + "visibility": "hidden" + }, + "build": { + "visibility": "hidden" + }, + "buildTarget": { + "visibility": "hidden" + } + }, + "cmake.buildBeforeRun": true, + "C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools", + "cortex-debug.openocdPath": "${env:OPENOCD_PATH}/src/openocd", + "cortex-debug.variableUseNaturalFormat": false +} diff --git a/sifter/CMakeLists.txt b/sifter/CMakeLists.txt new file mode 100644 index 0000000..31f0274 --- /dev/null +++ b/sifter/CMakeLists.txt @@ -0,0 +1,27 @@ +cmake_minimum_required(VERSION 3.18) +include($ENV{PICO_SDK_PATH}\\external\\pico_sdk_import.cmake) + +project(program C CXX ASM) + +set(CMAKE_C_STANDARD 11) +set(CMAKE_CXX_STANDARD 17) + +include_directories(${CMAKE_SOURCE_DIR}) + +add_executable(${PROJECT_NAME} + program.S + sifter.S +) + +set(PICO_BOARD pico_w) + +pico_sdk_init() + +target_link_libraries(${PROJECT_NAME} + pico_stdlib +) + +pico_add_extra_outputs(${PROJECT_NAME}) + +pico_enable_stdio_usb(${PROJECT_NAME} 1) +pico_enable_stdio_uart(${PROJECT_NAME} 1) diff --git a/sifter/program.S b/sifter/program.S new file mode 100644 index 0000000..f42b997 --- /dev/null +++ b/sifter/program.S @@ -0,0 +1,25 @@ +.thumb_func @ Necessary because sdk uses BLX +.global main @ Provide program starting address + +main: + BL stdio_init_all + MOV R4, #0 + LDR R5, =numbers + LDR R6, =size + +load: + @ TODO: Set up stack frame for load function + LDR R7, [R5, R4] + ADD R4, #4 + @ TODO: Branch and link to the sifter + CMP R4, R6 + BNE load + +rest: + NOP + B rest + +.data + numbers: .word 255, 1426063615, 855638271, 0, 1140850943 + end: + .set size, end - numbers \ No newline at end of file diff --git a/sifter/sifter.S b/sifter/sifter.S new file mode 100644 index 0000000..b526946 --- /dev/null +++ b/sifter/sifter.S @@ -0,0 +1,49 @@ +.thumb_func +.global sifter + +sifter: + @ TODO: Prepare stack frame for sifter + LDR R0, =format + MOV R1, R7 + @ TODO: Branch and Link to determine_type + @ TODO: Branch and Link to determine_quality + BL printf + @ TODO: Pop appropriate registers to... + @ TODO: Branch and eXecute back to subroutine calling this one (caller) + +determine_type: + @ TODO: Prepare stack frame for determine_type + @ TODO: Shift appropriate direction(s) to get the type bits + @ TODO: Compare and branch to appropriate typing branches + +is_lunar_type: + LDR R2, =lunar + @ TODO: Pop from stack to get address of caller + @ TODO: Branch and eXecute to caller + +is_martian_type: + LDR R2, =martian + @ TODO: Pop from stack to get address of caller + @ TODO: Branch and eXecute to caller + +determine_quality: + @ TODO: Set up stack frame for determine_quality + @ TODO: Shift appropriate places and direction(s) to get quality bits + @ TODO: Compare and branch to correct quality branch + +hi_quality: + LDR R3, =hi_qual + @ TODO: Pop from stack to get address of caller + @ TODO: Branch and eXecute to caller + +lo_quality: + LDR R3, =lo_qual + @ TODO: Pop from stack to get address of caller + @ TODO: Branch and eXecute to caller + +.data + format: .asciz "0x%08x\tTYPE: %s\tQUALITY: %s\n" + lunar: .asciz "LUNAR" + martian: .asciz "MARTIAN" + hi_qual: .asciz "HI" + lo_qual: .asciz "LO" \ No newline at end of file