Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/assembly/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Assembly 如何在mips assemply语言中将字符串复制到另一个字符串_Assembly_Mips_Strcpy_Mars Simulator_Mips64 - Fatal编程技术网

Assembly 如何在mips assemply语言中将字符串复制到另一个字符串

Assembly 如何在mips assemply语言中将字符串复制到另一个字符串,assembly,mips,strcpy,mars-simulator,mips64,Assembly,Mips,Strcpy,Mars Simulator,Mips64,我一直在尝试将一个字符串复制到另一个字符串,但找不到方法,有人能帮我吗? 问题是: 编写一个程序,使用过程调用将字符串S复制到T。假设字符串以null结尾 这是有人在stacks overflow中编写的代码,正如我的导师告诉我的,它很好,但只需要修改为过程调用 .data str1: .asciiz "My Name is Suliman." # Store initial string str2: .space 128 # Allocate mem

我一直在尝试将一个字符串复制到另一个字符串,但找不到方法,有人能帮我吗? 问题是: 编写一个程序,使用过程调用将字符串S复制到T。假设字符串以null结尾

这是有人在stacks overflow中编写的代码,正如我的导师告诉我的,它很好,但只需要修改为过程调用

.data

str1: .asciiz "My Name is Suliman." # Store initial string
str2: .space 128            # Allocate memory space for the new string

.text

main:
la $s0, str1            # Load address of first character
la $s1, str2            # Load the address of second string

loop:
    lbu  $t2, 0($s0)        # Load the first byte of $s0 (str1) into $t2

sb   $t2, 0($s1)        # Save the value in $t2 at the same byte in $s1 (str2)

addi $s0, $s0, 1        # Increment both memory locations by 1 byte
addi $s1, $s1, 1
bne  $t2, $zero, loop   # Check if at the zero delimiter character, if so jump to 

j done
done:
li $v0, 4
la $a0, str2
syscall                 # Print the copied string to the console

li $v0, 10              # Program end syscall
syscall

我在这里也有一些注释来解释我在做什么,我只是为了有一些空间而使用了128字节,我还打印了复制的字符串

.data

    str1: .asciiz "My Name is Suliman." # Store initial string
    str2: .space 128            # Allocate memory space for the new string

.text

main:
    la $t0, str1            # Load address of first character
    la $t1, str2            # Load the address of second string

loop:                      # do {
    lbu  $t2, 0($t0)        # Load the first byte of $t0 (str1) into $t2

    sb   $t2, 0($t1)        # Save the value in $t2 at the same byte in $t1 (str2)

    addi $t0, $t0, 1        # Increment both pointers by 1 byte
    addi $t1, $t1, 1
    bne  $t2, $zero, loop  # }while(c != 0)

#    j done        # execution falls through to the next instruction by itself
#done:
    li $v0, 4
    la $a0, str2
    syscall                 # Print the copied string to the console

    li $v0, 10              # Program end syscall
    syscall

搜索MIPS strcpy,你会发现很多例子。C样式字符串逐字节复制,直到nul字符终止符被复制。你需要为目标保留足够的空间:试试.space 80或类似的。你只保留了1个字节。asciiz。非常感谢你,我的朋友。感谢您为编写此代码所做的努力,但不幸的是,我刚刚发现我需要使用persecute调用来编写此代码,我将用额外的信息编辑问题rn。如果你能帮我,我会非常感激的!