Skip to content

Instantly share code, notes, and snippets.

@simias
Created June 18, 2016 22:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save simias/8929e113ce7f295ebb8030f09a8eea06 to your computer and use it in GitHub Desktop.
Save simias/8929e113ce7f295ebb8030f09a8eea06 to your computer and use it in GitHub Desktop.
/* void load_blob(unsigned *load_addr, unsigned *blob, unsigned len_words)
*
* Load `len_words` 32bit words from `blob` and store them at `load_addr`
*/
.type load_blob, function
load_blob:
addiu $sp, -24
sw $ra, 20($sp)
sw $fp, 16($sp)
move $fp, $sp
/* Early exit if theres nothing to load */
beqz $a2, 2f
/* Compute end address */
addiu $t0, $a1, $a2
1: /* Blob copy loop */
lw $t1, 0($a1)
addiu $a1, 4
sw $t1, 0($a0)
bne $a1, $t0, 1b
addiu $a0, 4
2: /* Setup return stub right after the code */
la $t0, return_stub
la $t1, return_stub_end
3: /* Stub copy loop */
lw $t2, 0($t0)
addiu $t0, 4
sw $t2, 0($a0)
bne $t0, $t1, 3b
addiu $a0, 4
move $sp, $fp
lw $ra, 20($sp)
lw $fp, 16($sp)
jr $ra
addiu $sp, 24
/* Stub code to return to main once the test has run. Copied at the
* end of the test. */
return_stub:
j post_test
nop
return_stub_end: .
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment