Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
35
Task/Reverse-a-string/MIPS-Assembly/reverse-a-string.mips
Normal file
35
Task/Reverse-a-string/MIPS-Assembly/reverse-a-string.mips
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
# 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"
|
||||
Loading…
Add table
Add a link
Reference in a new issue