创建一个 For 循环以填充装配中充满破折号的空缓冲区

creating a For Loop to fill an empty buffer full of dashes in assembly

这就是我到目前为止所拥有的,每次我到达代码的循环部分时,我都会得到 Segmentation fault (core dumped)。这是因为我的某些寄存器中存放的东西大小不正确吗?

 .data
   Welcome:
        .ascii "Welcome to League of Legends!!.\n[=10=]"
  Instruction:
        .ascii "Player 1, enter a Champion's name: [=10=]"
  Text:
        .space 12
  Text2:
        .space 12

  Guess:
        .ascii "Guess a letter: [=10=]"
  Letter:
        .space 1
  SecretCharacter:
        .ascii "Your Champion is: [=10=]"

  .text

  .global _start

  _start:
         mov $Welcome, %rax
        call PrintCString

        mov $Instruction, %rax
        call PrintCString
        mov $Text, %rax
        mov , %rbx
        call ScanCString
        mov %rax, %rbx
        mov %rax, %rbp
        call LengthCString
        mov %rax, %rcx


        mov [=10=], %rdi
        mov , %ch

Loop:
        cmp %rcx, %rdi
        jge End

        mov $Text2, %eax
        movb %ch, (%rax, %rdi)
        add , %rdi
        jmp Loop

End:
        call PrintCString
        call EndProgram

您同时使用了 rcx 和 ch,但 ch 是 rcx 的一部分。尝试使用 dh 而不是 ch.