.data
ch: .string "aeiou" #ascii char
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 $ch,%rbx #rbx = character storage
mov 0(%rbx),%rdi #character argument
mov 8(%rbx),%rsi #string argument
loop:
mov $0, %rax #initialize count to 0
mov 0(%rdi),%rcx #move first char into %rcx
cmp $0,0(%rbx) #check for end of ch input
je done #jump to done if end of ch string
call FREQ #return the freq of ch in string and place in %rax
mov $msg, %rdi #1st argument for print function - format for print function
mov 0(%rbx), %rsp #3rd argument for print function - char
mov %rax, %rdx #2nd argument for print function - number of chars
call printf #print the frequency value of the ch in string
add $1, %rdi #increment vowel
jmp loop
FREQ:
#subprogram body
cmpb $0,0(%rsi) #check for end of the string
je donefreq
loopfreq:
cmpb (%rcx), 0(%rsi) #compare first string char with ch
je increment_string #if equal - jump to increment_string
add $1, %rsi #if not - increment string
jmp loop #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
done:
add $8, %rsp #reset stack alignment
ret
Hey,
Q: Count the number of vowels in the given string and print out the number and the vowel for each of the vowels "aeoiu".
I'm running into a cmp compile error.
main.s:41: Error: too many memory references for `cmp'
when trying to compare the two strings least significant bits.
Can someone explain how I could go about comparing the LSB of the vowel string to the LSB of the sentence string?