Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

Commit

Permalink
Adding README updates and sifter exercise
Browse files Browse the repository at this point in the history
  • Loading branch information
dluman committed Oct 13, 2023
1 parent 4a06159 commit 329a29a
Show file tree
Hide file tree
Showing 6 changed files with 228 additions and 1 deletion.
74 changes: 73 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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_.
Expand Down
31 changes: 31 additions & 0 deletions sifter/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
23 changes: 23 additions & 0 deletions sifter/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -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
}
27 changes: 27 additions & 0 deletions sifter/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
25 changes: 25 additions & 0 deletions sifter/program.S
Original file line number Diff line number Diff line change
@@ -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
49 changes: 49 additions & 0 deletions sifter/sifter.S
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit 329a29a

Please sign in to comment.