Skip to content

Commit 596b93d

Browse files
Add house exercise
1 parent a25cf0d commit 596b93d

File tree

9 files changed

+457
-0
lines changed

9 files changed

+457
-0
lines changed

config.json

+8
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,14 @@
481481
"prerequisites": [],
482482
"difficulty": 6
483483
},
484+
{
485+
"slug": "house",
486+
"name": "House",
487+
"uuid": "914f654d-2d0c-4d4b-8c42-bff8ebdac21c",
488+
"practices": [],
489+
"prerequisites": [],
490+
"difficulty": 6
491+
},
484492
{
485493
"slug": "knapsack",
486494
"name": "Knapsack",
+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Hints
2+
3+
## General
4+
5+
- The `$t0-9` registers can be used to temporarily store values
6+
- The instructions specify which registers are used as input and output

exercises/practice/house/.docs/instructions.append.md

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
# Instructions
2+
3+
Recite the nursery rhyme 'This is the House that Jack Built'.
4+
5+
> [The] process of placing a phrase of clause within another phrase of clause is called embedding.
6+
> It is through the processes of recursion and embedding that we are able to take a finite number of forms (words and phrases) and construct an infinite number of expressions.
7+
> Furthermore, embedding also allows us to construct an infinitely long structure, in theory anyway.
8+
9+
- [papyr.com][papyr]
10+
11+
The nursery rhyme reads as follows:
12+
13+
```text
14+
This is the house that Jack built.
15+
16+
This is the malt
17+
that lay in the house that Jack built.
18+
19+
This is the rat
20+
that ate the malt
21+
that lay in the house that Jack built.
22+
23+
This is the cat
24+
that killed the rat
25+
that ate the malt
26+
that lay in the house that Jack built.
27+
28+
This is the dog
29+
that worried the cat
30+
that killed the rat
31+
that ate the malt
32+
that lay in the house that Jack built.
33+
34+
This is the cow with the crumpled horn
35+
that tossed the dog
36+
that worried the cat
37+
that killed the rat
38+
that ate the malt
39+
that lay in the house that Jack built.
40+
41+
This is the maiden all forlorn
42+
that milked the cow with the crumpled horn
43+
that tossed the dog
44+
that worried the cat
45+
that killed the rat
46+
that ate the malt
47+
that lay in the house that Jack built.
48+
49+
This is the man all tattered and torn
50+
that kissed the maiden all forlorn
51+
that milked the cow with the crumpled horn
52+
that tossed the dog
53+
that worried the cat
54+
that killed the rat
55+
that ate the malt
56+
that lay in the house that Jack built.
57+
58+
This is the priest all shaven and shorn
59+
that married the man all tattered and torn
60+
that kissed the maiden all forlorn
61+
that milked the cow with the crumpled horn
62+
that tossed the dog
63+
that worried the cat
64+
that killed the rat
65+
that ate the malt
66+
that lay in the house that Jack built.
67+
68+
This is the rooster that crowed in the morn
69+
that woke the priest all shaven and shorn
70+
that married the man all tattered and torn
71+
that kissed the maiden all forlorn
72+
that milked the cow with the crumpled horn
73+
that tossed the dog
74+
that worried the cat
75+
that killed the rat
76+
that ate the malt
77+
that lay in the house that Jack built.
78+
79+
This is the farmer sowing his corn
80+
that kept the rooster that crowed in the morn
81+
that woke the priest all shaven and shorn
82+
that married the man all tattered and torn
83+
that kissed the maiden all forlorn
84+
that milked the cow with the crumpled horn
85+
that tossed the dog
86+
that worried the cat
87+
that killed the rat
88+
that ate the malt
89+
that lay in the house that Jack built.
90+
91+
This is the horse and the hound and the horn
92+
that belonged to the farmer sowing his corn
93+
that kept the rooster that crowed in the morn
94+
that woke the priest all shaven and shorn
95+
that married the man all tattered and torn
96+
that kissed the maiden all forlorn
97+
that milked the cow with the crumpled horn
98+
that tossed the dog
99+
that worried the cat
100+
that killed the rat
101+
that ate the malt
102+
that lay in the house that Jack built.
103+
```
104+
105+
[papyr]: https://papyr.com/hypertextbooks/grammar/ph_noun.htm
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"authors": [
3+
"keiravillekode"
4+
],
5+
"files": {
6+
"solution": [
7+
"impl.mips"
8+
],
9+
"test": [
10+
"runner.mips"
11+
],
12+
"example": [
13+
".meta/example.mips"
14+
]
15+
},
16+
"blurb": "Output the nursery rhyme 'This is the House that Jack Built'.",
17+
"source": "British nursery rhyme",
18+
"source_url": "https://en.wikipedia.org/wiki/This_Is_The_House_That_Jack_Built"
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# | Register | Usage | Type | Description |
2+
# | -------- | ------------ | ------- | ----------------------------- |
3+
# | `$a0` | input | integer | start verse |
4+
# | `$a1` | input | integer | end verse |
5+
# | `$a2` | input/output | address | null-terminated output string |
6+
# | `$t0` | temporary | byte | character being copied |
7+
# | `$t3` | temporary | address | pointer into lyrics |
8+
# | `$t5` | temporary | address | lyrics |
9+
# | `$t6` | temporary | address | table |
10+
# | `$t7` | temporary | word | "THIS" (4 ASCII bytes) |
11+
# | `$t8` | temporary | word | " IS " (4 ASCII bytes) |
12+
13+
.eqv THIS 0x73696854 # "This"
14+
.eqv IS 0x20736920 # " is "
15+
16+
.globl recite
17+
18+
.data
19+
20+
lyrics: .asciiz "This is the horse and the hound and the horn that belonged to the farmer sowing his corn that kept the rooster that crowed in the morn that woke the priest all shaven and shorn that married the man all tattered and torn that kissed the maiden all forlorn that milked the cow with the crumpled horn that tossed the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built.\n"
21+
22+
table:
23+
.word -1, 389, 368, 351, 331, 310, 267, 232, 190, 145, 99, 62, 8
24+
25+
26+
.text
27+
28+
recite:
29+
la $t5, lyrics
30+
la $t6, table
31+
li $t7, THIS
32+
li $t8, IS
33+
34+
sll $a0, $a0, 2
35+
sll $a1, $a1, 2
36+
add $a0, $t6, $a0 # pointer into table for current verse
37+
add $a1, $t6, $a1 # pointer into table for end verse
38+
39+
line:
40+
usw $t7, 0($a2) # unaligned store word "This"
41+
usw $t8, 4($a2) # unaligned store word " is "
42+
add $a2, $a2, 8
43+
44+
lw $t3, 0($a0)
45+
add $t3, $t5, $t3
46+
47+
copy_string:
48+
# copy string from source $t3 to destination $a2
49+
lb $t0, 0($t3) # load source byte
50+
sb $t0, 0($a2) # write byte to destination
51+
addi $t3, $t3, 1 # increment souce pointer
52+
addi $a2, $a2, 1 # increment destination pointer
53+
bne $t0, $zero, copy_string # repeat until we have reached null terminator
54+
55+
subi $a2, $a2, 1 # decrement destination pointer,
56+
# ready to append other strings
57+
58+
move $t1, $a0
59+
add $a0, $a0, 4
60+
bne $t1, $a1, line
61+
62+
jr $ra
+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# This is an auto-generated file.
2+
#
3+
# Regenerating this file via `configlet sync` will:
4+
# - Recreate every `description` key/value pair
5+
# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications
6+
# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion)
7+
# - Preserve any other key/value pair
8+
#
9+
# As user-added comments (using the # character) will be removed when this file
10+
# is regenerated, comments can be added via a `comment` key.
11+
12+
[28a540ff-f765-4348-9d57-ae33f25f41f2]
13+
description = "verse one - the house that jack built"
14+
15+
[ebc825ac-6e2b-4a5e-9afd-95732191c8da]
16+
description = "verse two - the malt that lay"
17+
18+
[1ed8bb0f-edb8-4bd1-b6d4-b64754fe4a60]
19+
description = "verse three - the rat that ate"
20+
21+
[64b0954e-8b7d-4d14-aad0-d3f6ce297a30]
22+
description = "verse four - the cat that killed"
23+
24+
[1e8d56bc-fe31-424d-9084-61e6111d2c82]
25+
description = "verse five - the dog that worried"
26+
27+
[6312dc6f-ab0a-40c9-8a55-8d4e582beac4]
28+
description = "verse six - the cow with the crumpled horn"
29+
30+
[68f76d18-6e19-4692-819c-5ff6a7f92feb]
31+
description = "verse seven - the maiden all forlorn"
32+
33+
[73872564-2004-4071-b51d-2e4326096747]
34+
description = "verse eight - the man all tattered and torn"
35+
36+
[0d53d743-66cb-4351-a173-82702f3338c9]
37+
description = "verse nine - the priest all shaven and shorn"
38+
39+
[452f24dc-8fd7-4a82-be1a-3b4839cfeb41]
40+
description = "verse 10 - the rooster that crowed in the morn"
41+
42+
[97176f20-2dd3-4646-ac72-cffced91ea26]
43+
description = "verse 11 - the farmer sowing his corn"
44+
45+
[09824c29-6aad-4dcd-ac98-f61374a6a8b7]
46+
description = "verse 12 - the horse and the hound and the horn"
47+
48+
[d2b980d3-7851-49e1-97ab-1524515ec200]
49+
description = "multiple verses"
50+
51+
[0311d1d0-e085-4f23-8ae7-92406fb3e803]
52+
description = "full rhyme"

exercises/practice/house/impl.mips

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# | Register | Usage | Type | Description |
2+
# | -------- | ------------ | ------- | ----------------------------- |
3+
# | `$a0` | input | integer | start verse |
4+
# | `$a1` | input | integer | end verse |
5+
# | `$a2` | input/output | address | null-terminated output string |
6+
# | `$t0-9` | temporary | any | for temporary storage |
7+
8+
.globl recite
9+
10+
recite:
11+
jr $ra

0 commit comments

Comments
 (0)