-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1077eff
commit 0c25837
Showing
11 changed files
with
3,770 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# Instructions | ||
|
||
Recite the lyrics to that popular children's repetitive song: Ten Green Bottles. | ||
|
||
Note that not all verses are identical. | ||
|
||
```text | ||
Ten green bottles hanging on the wall, | ||
Ten green bottles hanging on the wall, | ||
And if one green bottle should accidentally fall, | ||
There'll be nine green bottles hanging on the wall. | ||
Nine green bottles hanging on the wall, | ||
Nine green bottles hanging on the wall, | ||
And if one green bottle should accidentally fall, | ||
There'll be eight green bottles hanging on the wall. | ||
Eight green bottles hanging on the wall, | ||
Eight green bottles hanging on the wall, | ||
And if one green bottle should accidentally fall, | ||
There'll be seven green bottles hanging on the wall. | ||
Seven green bottles hanging on the wall, | ||
Seven green bottles hanging on the wall, | ||
And if one green bottle should accidentally fall, | ||
There'll be six green bottles hanging on the wall. | ||
Six green bottles hanging on the wall, | ||
Six green bottles hanging on the wall, | ||
And if one green bottle should accidentally fall, | ||
There'll be five green bottles hanging on the wall. | ||
Five green bottles hanging on the wall, | ||
Five green bottles hanging on the wall, | ||
And if one green bottle should accidentally fall, | ||
There'll be four green bottles hanging on the wall. | ||
Four green bottles hanging on the wall, | ||
Four green bottles hanging on the wall, | ||
And if one green bottle should accidentally fall, | ||
There'll be three green bottles hanging on the wall. | ||
Three green bottles hanging on the wall, | ||
Three green bottles hanging on the wall, | ||
And if one green bottle should accidentally fall, | ||
There'll be two green bottles hanging on the wall. | ||
Two green bottles hanging on the wall, | ||
Two green bottles hanging on the wall, | ||
And if one green bottle should accidentally fall, | ||
There'll be one green bottle hanging on the wall. | ||
One green bottle hanging on the wall, | ||
One green bottle hanging on the wall, | ||
And if one green bottle should accidentally fall, | ||
There'll be no green bottles hanging on the wall. | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"authors": [ | ||
"keiravillekode" | ||
], | ||
"files": { | ||
"solution": [ | ||
"bottle_song.asm" | ||
], | ||
"test": [ | ||
"bottle_song_test.c" | ||
], | ||
"example": [ | ||
".meta/example.asm" | ||
] | ||
}, | ||
"blurb": "Produce the lyrics to the popular children's repetitive song: Ten Green Bottles.", | ||
"source": "Wikipedia", | ||
"source_url": "https://en.wikipedia.org/wiki/Ten_Green_Bottles" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
default rel | ||
|
||
section .rodata | ||
|
||
green_bottle: | ||
db " green bottle", 0 | ||
green_bottles: | ||
db " green bottles", 0 | ||
hanging_on: | ||
db " hanging on the wall", 0 | ||
and_if: | ||
db "And if one green bottle should accidentally fall,", 10, "There'll be ", 0 | ||
comma: db ",", 10, 0 | ||
stop: db ".", 10, 10, 0 | ||
|
||
no: db "No", 0 | ||
one: db "One", 0 | ||
two: db "Two", 0 | ||
three: db "Three", 0 | ||
four: db "Four", 0 | ||
five: db "Five", 0 | ||
six: db "Six", 0 | ||
seven: db "Seven", 0 | ||
eight: db "Eight", 0 | ||
nine: db "Nine", 0 | ||
ten: db "Ten", 0 | ||
|
||
section .data | ||
|
||
number_array: | ||
dq no | ||
dq one | ||
dq two | ||
dq three | ||
dq four | ||
dq five | ||
dq six | ||
dq seven | ||
dq eight | ||
dq nine | ||
dq ten | ||
|
||
section .text | ||
global recite | ||
|
||
append: | ||
lodsb | ||
test al, al | ||
jz .return | ||
|
||
stosb | ||
jmp append | ||
|
||
.return: | ||
ret | ||
|
||
; extern void recite(char *buffer, int start_bottles, int take_down); | ||
recite: | ||
cld | ||
mov rcx, 2 | ||
lea r8, [number_array] | ||
lea r9, [green_bottle] | ||
mov r10, rsi | ||
mov r11, rsi | ||
sub r11, rdx | ||
shl r10, 3 ; offset into number_array for start_bottles | ||
shl r11, 3 ; final offset into number_array | ||
|
||
.verse: | ||
mov rsi, [r8 + r10] | ||
call append | ||
|
||
lea rsi, [green_bottles] | ||
cmp r10, 8 | ||
cmove rsi, r9 ; conditionally green_bottle instead of green_bottles | ||
call append | ||
|
||
lea rsi, [hanging_on] | ||
call append | ||
|
||
lea rsi, [comma] | ||
call append | ||
|
||
loop .verse | ||
|
||
mov rcx, 2 | ||
sub r10, 8 | ||
|
||
lea rsi, [and_if] | ||
call append | ||
|
||
mov rsi, [r8 + r10] | ||
|
||
lodsb | ||
or al, 32 ; force lower case | ||
stosb | ||
|
||
call append | ||
|
||
lea rsi, [green_bottles] | ||
cmp r10, 8 | ||
cmove rsi, r9 | ||
call append | ||
|
||
lea rsi, [hanging_on] | ||
call append | ||
|
||
lea rsi, [stop] | ||
call append | ||
|
||
cmp r10, r11 | ||
jg .verse | ||
|
||
xor al, al | ||
mov [rdi - 1], al ; overwrite second newline | ||
ret | ||
|
||
%ifidn __OUTPUT_FORMAT__,elf64 | ||
section .note.GNU-stack noalloc noexec nowrite progbits | ||
%endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# This is an auto-generated file. | ||
# | ||
# Regenerating this file via `configlet sync` will: | ||
# - Recreate every `description` key/value pair | ||
# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications | ||
# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion) | ||
# - Preserve any other key/value pair | ||
# | ||
# As user-added comments (using the # character) will be removed when this file | ||
# is regenerated, comments can be added via a `comment` key. | ||
|
||
[d4ccf8fc-01dc-48c0-a201-4fbeb30f2d03] | ||
description = "verse -> single verse -> first generic verse" | ||
|
||
[0f0aded3-472a-4c64-b842-18d4f1f5f030] | ||
description = "verse -> single verse -> last generic verse" | ||
|
||
[f61f3c97-131f-459e-b40a-7428f3ed99d9] | ||
description = "verse -> single verse -> verse with 2 bottles" | ||
|
||
[05eadba9-5dbd-401e-a7e8-d17cc9baa8e0] | ||
description = "verse -> single verse -> verse with 1 bottle" | ||
|
||
[a4a28170-83d6-4dc1-bd8b-319b6abb6a80] | ||
description = "lyrics -> multiple verses -> first two verses" | ||
|
||
[3185d438-c5ac-4ce6-bcd3-02c9ff1ed8db] | ||
description = "lyrics -> multiple verses -> last three verses" | ||
|
||
[28c1584a-0e51-4b65-9ae2-fbc0bf4bbb28] | ||
description = "lyrics -> multiple verses -> all verses" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
AS = nasm | ||
|
||
CFLAGS = -g -Wall -Wextra -pedantic -Werror | ||
LDFLAGS = | ||
ASFLAGS = -g -F dwarf -Werror | ||
|
||
ifeq ($(shell uname -s),Darwin) | ||
ifeq ($(shell sysctl -n hw.optional.arm64 2>/dev/null),1) | ||
ALL_CFLAGS = -target x86_64-apple-darwin | ||
endif | ||
ALL_LDFLAGS = -Wl,-pie | ||
ALL_ASFLAGS = -f macho64 --prefix _ | ||
else | ||
ALL_LDFLAGS = -pie -Wl,--fatal-warnings | ||
ALL_ASFLAGS = -f elf64 | ||
endif | ||
|
||
ALL_CFLAGS += -std=c99 -fPIE -m64 $(CFLAGS) | ||
ALL_LDFLAGS += $(LDFLAGS) | ||
ALL_ASFLAGS += $(ASFLAGS) | ||
|
||
C_OBJS = $(patsubst %.c,%.o,$(wildcard *.c)) | ||
AS_OBJS = $(patsubst %.asm,%.o,$(wildcard *.asm)) | ||
ALL_OBJS = $(filter-out example.o,$(C_OBJS) $(AS_OBJS) vendor/unity.o) | ||
|
||
CC_CMD = $(CC) $(ALL_CFLAGS) -c -o $@ $< | ||
|
||
all: tests | ||
@./$< | ||
|
||
tests: $(ALL_OBJS) | ||
@$(CC) $(ALL_CFLAGS) $(ALL_LDFLAGS) -o $@ $(ALL_OBJS) | ||
|
||
%.o: %.asm | ||
@$(AS) $(ALL_ASFLAGS) -o $@ $< | ||
|
||
%.o: %.c | ||
@$(CC_CMD) | ||
|
||
vendor/unity.o: vendor/unity.c vendor/unity.h vendor/unity_internals.h | ||
@$(CC_CMD) | ||
|
||
clean: | ||
@rm -f *.o vendor/*.o tests | ||
|
||
.PHONY: all clean |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
default rel | ||
|
||
section .data | ||
|
||
section .text | ||
global recite | ||
recite: | ||
; Provide your implementation here | ||
ret | ||
|
||
%ifidn __OUTPUT_FORMAT__,elf64 | ||
section .note.GNU-stack noalloc noexec nowrite progbits | ||
%endif |
Oops, something went wrong.