mainの27行目でsegfaultを実行しています。サブプログラム呼び出し後に、%raxが値0になっていてはなりません。アセンブリx86 - 文字列segfault/countサブプログラムの頻度が戻り値を保存しない
私のサブプログラムが正しく実行していないことを理解しようとしています。私はバイト比較を前提としています。
メインプログラムの27行目でprintf呼び出しでsegfaultも取得しています。ここではprintf関数があらかじめ定義されていると仮定していますが、ここでprintfサブプログラムを作成する必要があるかもしれません。
サブ
.text
.globl FREQ
FREQ:
#subprogram body
cmpb $0,0(%rsi) #check for end of the string
je donefreq
loopfreq:
cmp %rcx, 0(%rsi) #compare first string char with vowel
je increment_string #if equal - jump to increment_string
add $1, %rsi #if not - increment string
jmp FREQ #jump to loop to check for end of string status/next char
increment_string:
add $1, %rsi #increment to next string character
add $1, %rax #add 1 to frequency of character
jmp loopfreq
donefreq:
ret
メイン
.data
string: .string "This course is about encoding numbers and instructions into binary sequences and designing digital systems to process them."
endofstring: .space 8
msg: .string "%c occurs %d times \n"
.text
.global main
main:
sub $8,%rsp #stack alignment
mov $string,%rsi #rsi = string storage
mov $0x61, %r8 #storage of a
mov $0x65, %r9 #storage of e
mov $0x69, %r10 #storage of i
mov $0x6F, %r11 #storage of o
mov $0x75, %r12 #storage of u
#Case A
mov %r8,%rcx
mov $0, %rax #initialize count to 0
call FREQ #Generate %rax value for count
mov %rax, %rdx #2nd argument for print function - number of
mov $msg, %rdi #1st argument for print function - format for print function
mov %r8, %rsp #3rd argument for print function - char
call printf #print the frequency value of the ch in string
#Case E
mov %r9,%rcx
mov $0, %rax #initialize count to 0
call FREQ
mov $msg, %rdi #1st argument for print function - format for print function
mov %r9, %rsp #3rd argument for print function - char
mov %rax, %rdx #2nd argument for print function - number of
call printf #print the frequency value of the ch in string
#Case O
mov %r10,%rcx
mov $0, %rax #initialize count to 0
call FREQ
mov $msg, %rdi #1st argument for print function - format for print function
mov %r10, %rsp #3rd argument for print function - char
mov %rax, %rdx #2nd argument for print function - number of
call printf #print the frequency value of the ch in string
#Case I
mov %r11,%rcx
mov $0, %rax #initialize count to 0
call FREQ
mov $msg, %rdi #1st argument for print function - format for print function
mov %r11, %rsp #3rd argument for print function - char
mov %rax, %rdx #2nd argument for print function - number of
call printf #print the frequency value of the ch in string
#Case U
mov %r12,%rcx
mov $0, %rax #initialize count to 0
call FREQ
mov $msg, %rdi #1st argument for print function - format for print function
mov %r12, %rsp #3rd argument for print function - char
mov %rax, %rdx #2nd argument for print function - number of
call printf #print the frequency value of the ch in string
jmp done
done:
add $8, %rsp #reset stack alignment
ret
プログラムは、文の中で、各母音の数をカウント - print文でその文字の数を出力します。
「mov%r9、%rsp」はおそらくタイプミスです。あなたは 'mov%r9、%rsi'をそこに、そして他の場所にしたいと思っています。あなたも他のエラーがありますが、これはあなたが尋ねたものです:) – Jester
これは間違いなくタイプミスです:(おお、ありがとう、うまくいけば、他のエラーは簡単に修正されるでしょう) –
@Jester Hey Jester、どのように私はGDBを使ってサブプログラムの値をチェックできましたか? 'gcc -g -o runtest main.s count.s'でコンパイルした後、コールラインの前後の行で' gdb runtest'をブレークしてコンパイルしますが、ありがとう! –