36 lines
735 B
Plaintext
36 lines
735 B
Plaintext
# First, it gets the length of the original string
|
|
# Then, it allocates memory from the copy
|
|
# Then it copies the pointer to the original string, and adds the strlen
|
|
# subtract 1, then that new pointer is at the last char.
|
|
# while(strlen)
|
|
# copy char
|
|
# decrement strlen
|
|
# decrement source pointer
|
|
# increment target pointer
|
|
|
|
.text
|
|
|
|
strcpy:
|
|
addi $sp, $sp, -4
|
|
sw $s0, 0($sp)
|
|
add $s0, $zero, $zero
|
|
|
|
L1:
|
|
add $t1, $s0, $a1
|
|
lb $t2, 0($t1)
|
|
add $t3, $s0, $a0
|
|
sb $t2, 0($t3)
|
|
beq $t2, $zero, L2
|
|
addi $s0, $s0, 1
|
|
j L1
|
|
|
|
L2:
|
|
lw $s0, 0($sp)
|
|
addi $sp, $sp, 4
|
|
jr $ra
|
|
|
|
.data
|
|
ex_msg_og: .asciiz "Original string:\n"
|
|
ex_msg_cpy: .asciiz "\nCopied string:\n"
|
|
string: .asciiz "Nice string you got there!\n"
|