So I'm running into a segfault on line 27 of main and after my subprogram call my %rax remains at the value 0 when it shouldn't be.
I'm trying to figure out what my subprogram isn't doing correctly - I'm assuming its with my byte comparisons as I'm not overly familiar with them yet.
I'm also getting a segfault on line 27 of the main program with the printf call. I'm assuming here that the printf function is predefined - though I think I might be needing to make a printf subprogram as well here.
Sub
.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
main
.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
The program counts the number of each vowel in the sentence - outputs the number of that character in a print statement.