Last active
August 29, 2016 19:08
-
-
Save KelviNosse/f0c03d67ffd5b299020c to your computer and use it in GitHub Desktop.
STRCPY Implemented on MIPS32 - Step by Step Example
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
#STRCPY - MIPS32 | |
#Author: Kelvin Nose :^) | |
#Date: 7/11/15 | |
# void strcpy(char x[], char y[]){ | |
#int i; | |
#i = 0; | |
#while((x[i] = y[i]) != '\0') /* copy and test byte */ | |
#i+=1; | |
#} | |
strcpy: | |
addi $sp, $sp, -4# allocate 4 bytes on stack | |
sw $s0, 0($sp) # store s0 at offset 0 on stack | |
add $s0, $zero, $zero # set i to 0, i = 0; | |
while: | |
add $t1, $a1, $s0 # load address of y[i], and sets to a temporal register | |
lbu $t2, ($t1) # load byte unsigned, puts the character into y[i] // $t2 = y[i] | |
add $t3, $s0, $a0 # load address of x[i], and sets to a temporal register | |
sb $t2, ($t3) # store byte of y[i] to x[i] // x[i] = y[i] | |
beq $t2, $zero, out_while # if x[i] == '\0' end while | |
addi $s0, $s0, 1 # i++; | |
j while # jumps to while | |
out_while: | |
lw $s0, 0($sp) # load contents of $s0 to its default value | |
addi $sp, $sp, 4 # pop 4 bytes off stack | |
jr $ra # return with register address value to whoever called this | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment