So, most of the code works for me, but I can’t figure out exactly how to deal with the fact that the input sentence has an unknown length. I am new to assembly and all this is a bit confusing.
(Now I set it up as if the length was known as three characters, but obviously I need to change it).
.data
input_msg: .ascii "Enter a random sentence: "
input_msg_len: .long 25
input_str: .ascii "???"
count: .long 0
newline: .long 10
.text
.global _start
_start:
mov $4, %eax
mov $1, %ebx
mov $input_msg, %ecx
mov input_msg_len, %edx
int $0x80
mov $3, %eax
mov $0, %ebx
mov $input_str, %ecx
mov $3, %edx
int $0x80
again1:
mov $input_str, %ecx
add count, %ecx
mov $4, %eax
mov $1, %ebx
mov $1, %edx
int $0x80
push %ecx
incl count
cmp $3, count
jnz again1
mov $0, %edi
mov $4, %eax
mov $1, %ebx
mov $1, %edx
int $0x80
again2:
pop %ecx
mov $4, %eax
mov $1, %ebx
mov $1, %edx
int $0x80
inc %edi
cmp count, %edi
jnz again2
mov $4, %eax
mov $1, %ebx
mov $newline, %ecx
mov $1, %edx
int $0x80
mov $1, %eax
int $0x80
Basically, I want to know how to make the code work for any sentence, not just three characters?
source
share