したがって、ほとんどのコードは機能していますが、入力文の長さが不明であるという事実をどのように正確に処理するかを理解することはできません。私はアセンブリに不慣れで、これはすべて少し混乱しています。
(現在、長さが3文字であることがわかっているかのように設定していますが、明らかにそれを変更する必要があります。)
.data
input_msg: .ascii "Enter a random sentence: "
input_msg_len: .long 25
input_str: .ascii "???" # 3rd should get newline
count: .long 0
newline: .long 10
.text
.global _start
_start:
# prompt for input
mov $4, %eax # prompt for input
mov $1, %ebx
mov $input_msg, %ecx
mov input_msg_len, %edx
int $0x80
# get input
mov $3, %eax # 3 to request "read"
mov $0, %ebx # 0 is "console" (keyboard)
mov $input_str, %ecx # input buffer addr
mov $3, %edx # number of symbols typed in
int $0x80 # Go do the service!
again1:
mov $input_str, %ecx
add count, %ecx # count is offset from input_str beginning
mov $4, %eax # to write
mov $1, %ebx # to console display
mov $1, %edx # 1 byte to write
int $0x80 # Do it!
push %ecx # push onto stack
incl count # increment count
cmp $3, count # compare lengths
jnz again1 # jmp again if not 0 (no difference)
mov $0, %edi # use edi as loop counter
mov $4, %eax # print out msg
mov $1, %ebx # etc.
mov $1, %edx # length
int $0x80 # OS, serve!
again2:
pop %ecx
mov $4, %eax # print out msg
mov $1, %ebx # etc.
mov $1, %edx # length
int $0x80 # OS, serve!
inc %edi # increment edi
cmp count, %edi # compare lengths
jnz again2 # jmp again if not 0 (no difference)
# print newline
mov $4, %eax # print out msg
mov $1, %ebx # etc.
mov $newline, %ecx # addr
mov $1, %edx # length
int $0x80 # OS, serve!
# exit
mov $1, %eax # exit
int $0x80 # OS, serve!
基本的に、私が知りたいのは、3文字の長さだけでなく、どの文に対してもコードを機能させる方法です。