如何将字符串参数从C传递到汇编代码?

时间:2016-11-28 09:18:14

标签: c assembly x86 parameter-passing nasm

我的小组正在尝试从 C 程序中获取字符串参数,并将其传递给以汇编语言编写的例程。我们正在使用带有 NASM 后端的 SASM IDE。我们如何编码?

这是我们的 C 代码:

 extern int valid(char * dna){

}

int main(){
int opt, error, temp;
char cDump;
char dna[41];

intro();
do{
    opt = menuList();
    scanf("%c", &cDump);
    system("cls");
    switch(opt){
        case 1:
            printf("\n\n\n\n");
            printf("                    ===================================");
            printf("\n                 Task to be performed: DNA Frequency Count");
            printf("\n                    ===================================");
            printf("\n\n                    Enter DNA string: ");
            scanf("%s", dna);

            error = valid(dna);
            printf("%d", error);
            if(error > 0){
                errors(error);
                break;
            }




            break;
        case 2:
            break;
        case 3:
            break;
        case 4:
            break;
        case 5:
            break;
        case 6:
            return 0;
    }
    getche();
    system("cls");
}while(opt != 6);

}

这是我们的汇编代码:

%include "io.inc"
extern _printf, _scanf, _puts, _system

section .data
length db 0

segment .text
global _valid
global CMAIN

CMAIN:
    mov ebp, esp; for correct debugging
    ;write your code here
    xor eax, eax
ret

_valid:
push ebp
mov ebp, esp
lea ebx, [ebp+8]

again:
cmp byte [ebx], 0
je done
cmp byte [ebx], "A"
je next
cmp byte [ebx], "G"
je next
cmp byte [ebx], "T"
je next
cmp byte [ebx], "C"
je next
cmp byte [ebx], "."
je done

mov eax, 00000002
leave
ret

next:
inc byte [length]
inc ebx

cmp byte [length], 20
jle again

mov eax, 00000003h
leave
ret

done:
cmp byte [length], 0
je zeroinput
cmp byte [ebx], "."
je valid

mov eax, 00000001h
leave
ret

zeroinput:    
mov eax, 00000004h
leave
ret

valid:
mov eax, 00000000h
leave
ret   

我们如何将字符串参数传递给valid函数?

0 个答案:

没有答案