在MIPS程序集中不能打印多个字符串

时间:2018-09-27 00:42:56

标签: c assembly

我必须将以下代码转换为汇编代码。该代码旨在查找字符串中的第一个字符,也查找第二个字符串。

char* firstmatch (char *s1, char *s2) /* find the first character in string s1 that is also in s2 */
{
    char *temp;
    temp = s1;
    do {
        if (strchr(s2, *temp) != 0) /* if this character is there */
            return temp; /* return where we found it */
        temp++; /* else look again */
    } while (*temp != 0);
    return 0; /* found none of these chars */
}

char* strchr (register const char *s, int c)
{
    do {
        if (*s == c)
        {
            return (char*)s;
        }
    } while (*s++);
    return (0);
}

这是我到目前为止所拥有的。我想先将string1加载到$ a0寄存器中,然后将string2加载到$ a1寄存器中。当我尝试打印它们以使它们确认它们在那里时,它仅打印了第一个:

.data
str1:  .asciiz "dog"
str2:  .asciiz "framed"

.text
main:
    # Load first two strings 
    la $a0, str1
    la $a1, str2
    jal firstmatch  

    # Print and exit subroutine 
    li $v0, 10 
    syscall 

.data 

.text
firstmatch:
    la $t0, 0($a0)
    la $t1, 0($a1)
    li $v0, 4
    li $v1, 4
    syscall

0 个答案:

没有答案