hangman 游戏,语法修复 x86 gcc assembly & C

hangman game, syntax fix x86 gcc assembly & C

我的最终项目是刽子手游戏。所选单词是从 database.The 用户通过 scanf 输入 char 中随机选取的,然后必须与通过 assembly.Since C 选择的单词进行比较没有字符串变量,字符串只是一个字符数组,所以输入的 charfor loop 中并且必须与数组中的每个索引 char 进行比较。

现在汇编函数是passed:inti(index#),char string1指针(数组字),char string2指针(用户输入)。

movb    8(%ebp), %ecx   /*store i -> cx reg*/
movb    12(%ebp),%ebx   /*store *string1 -> bh reg*/
movb    16(%ebp),%edx   /*store (userinput)*string2 ->bl reg*/
movb    (%ebx,%ecx,1),%al
movb    (%ebx,%ecx,1), %ah
movl    [=10=],     %eax
cmpl    %al,    %ah
jne     end
movl    ,     %eax

我知道这两行语法不正确,我需要知道如何正确偏移这些 mov 指令。另外,如果还有其他错误。这应该是在偏移后比较两个寄存器。我是组装新手。

movb    (%bh,%cx,1),%edx
movb    (%bl,%cx,1), %eax

编辑:所以现在比较 2 个字符时,它只给我一个 return 1,即使它们不同。

您不能在 32 位模式下使用 %bh%bl%cx 等 8 位或 16 位寄存器作为地址 and/or 索引寄存器。您应该使用 %ecx%ebx%edx 作为指针和索引寄存器,并使用 %al%ah 从字符串中加载字节:

movl    8(%ebp),%ecx    /* store 32 bit i -> ecx reg */
movl    12(%ebp),%ebx   /* store string1 -> ebx reg */
movl    16(%ebp),%edx   /* store (userinput) string2 -> edx */
movb    (%ebx,%ecx,1),%al
movb    (%edx,%ecx,1),%ah
cmpb    %al,%ah
jne     here
movl    [=10=],%eax
jmp     end

如果 i 在 C 端有类型 unsigned char,您必须以这种方式零扩展 8 位值:

movzbl  8(%ebp),%ecx    /* store 8 bit i -> ecx reg */