Created
November 14, 2016 11:36
-
-
Save ManDeJan/823bd6619cbf6df6560e96affb99ce68 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
.cpu cortex-m3 | |
.data | |
decompressed: | |
.asciz "" | |
.skip 4096 // reserve 4k of room for us <3 | |
.text | |
.align 1 | |
.global decompress | |
// r0 = value of compressed string head | |
// r1 = read head of compressed string | |
// r2 = write head of decompressed string | |
// r3 = offset of match | |
// r4 = length of match | |
// r5 = alternate read head on match | |
decompress: | |
push {r4, r5, lr} // push registers | |
ldr r1, =compressed_string // adress of the compressed string | |
ldr r2, =decompressed // adress of the reserved space for the decompressed string | |
loop: | |
ldrb r0, [r1] // get char from string | |
cmp r0, #'@' // if the char is an '@' then readfrombuffer | |
beq readfrombuffer | |
cbz r0, final // if we get a null byte then get out of here | |
strb r0, [r2] // put ze byte in ze decompressed string | |
push {r1 - r3} // put ze byte in ze terminal so we can see the this works | |
bl put_char | |
pop {r1 - r3} | |
add r1, #1 // get to the next char | |
add r2, #1 // make room for ze next char | |
b loop // do it agaaain | |
readfrombuffer: | |
ldrb r3, [r1, #1] // read char after '@' | |
ldrb r4, [r1, #2] // store the amount of characters in r4 | |
add r1, r1, #3 | |
sub r3, r3, #31 // subtract a space because Wouter | |
sub r5, r2, r3 // r5 is now our read head back in the buffer | |
writefrombuffer: // read for the length given | |
cmp r4, #' ' // gave we done enough reading back yet? | |
beq loop | |
ldrb r0, [r5] // get byte from alt read head | |
strb r0, [r2] // put the damn thing in our decompressed string | |
push {r1 - r3} // put ze char in the terminal yet again because I NEED CONFURMATION | |
bl put_char | |
pop {r1 - r3} | |
add r5, #1 // we need to make progression so lets just inc some values | |
add r2, #1 | |
sub r4, #1 // subtract one of the characters we still have to read total | |
b writefrombuffer | |
final: | |
pop {r4, r5, pc} // restore the registers because we are nice people |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment