在汇编中,我如何从调用函数中获取值?

问题描述

这是我的MSP430的C代码。我正在尝试用汇编语言编写str = word_start(str);,但不确定是否正确。

char** tokenize(char* str){
    int totalWords = count_words(str);
    printf("%d\n",totalWords);
    char **array;
    array = (char **)malloc(sizeof(char*) * (++totalWords));

    //filling the array with individual words
    int diff = 0;
    int i;
    for(i = 0; i < totalWords-1; i++){
        str = word_start(str);
        // find difference in length
        diff = word_terminator(str) - str;
        // add new allocated string to array
        array[i] = copy_str(str,diff);
        // update pointer p to next word
        str = word_terminator(str);
        
    }
    array[i] = '\0';
    return array;
}

这是我的汇编代码,我想将上述方法从C转换为MSP430汇编。

 tokenize:
    mov r12,0(r1) ;    put str in str
    
    call #count_words
    mov r12 2(r1) ;     
    mov 2(r1),r12 ;    get totalWords
    
    
    add #1,r12 totalword
    add r12,r12
    call #malloc
    mov r12 4(r1)

    mov #0 6(r1) ;      int i = 0;
    mov #0 8(r1) ;      int diff = 0;

top: cmp 0(r1),6(r1)
    JL end
    mov 0(r1),r12
    call #word_start    ; calling word start
    mov r12,0(r1)      ; getting the value returned 
    mov 0(r1),r12    

    call #word_terminator
    mov r12,8(r1)
    mov 0(r1),r12
    mov 8(r1),r13
    sub r12,r13
    
    call #copy_str
    mov r12,10(r1) ;   what we get from cpoy_str put in r12
    mov 6(r1),r12 ;    put I in r12
    add r12,r12 ;       add r12
    add 4(r1),r12 ;    add 4(r1) to whats in r12
    mov 10(r1),@r12 ;  put what we r12 is in 10(r1) 

    mov 0(r1),r12
    call #word_terminator
    move r12,0(r1)
    mov 0(r1),r12
    add #1,6(r1) ;     increment i

end:
    mov 6(r1),r12
    add r12,r12
    add 4(r1),r12
    mov #0,@r12,add #12,r1
    ret

在汇编中调用word_start时,我传递值str并正确返回值的方式是吗?如果不能,那么可以告诉我如何将汇编中的变量传递给函数并从该函数获取返回值吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...