I'm basically trying to convert the ascii values of a string ( -48 if number -55 if letter) and then multiply those values and add them up. I'm okay with the multiplying part but when I try to add them to a "sum" variable I get a seg fault. Here's the code
section.data
factor: dd 7,3,1,7,3,1,7,3,1
sum: dd 0
decNumFormat:
db '%d', 10, 0
section.text
main:
mov eax, [esp+4]
mov eax, [esp+8]
mov ebx, [eax+4] ; these 3 are to get the input from user
mov ecx,dword[factor] ; factor is the value i want to multiply with
push ebx
call checksum
checksum:
mov al,[ebx] ; to get 1 byte from the input
add ebx,1
sub al,55 ; just assume its a letter
movzx eax,al
mul ecx
mov ecx,1 ;change my factor variable
add [sum], eax ; here's where I'm getting the segmentation fault. I tried mov as well but that also gave me a seg fault.
push dword[sum]
push decNumFormat
call printf; I'm just calling print to see if I have a correct value but of course it's not printing because of the seg fault
mov al,[ebx]
add ebx,1
sub al,48 ;assume its a number
movzx eax,al
mul ecx
mov ecx,1
add [sum], eax
ret
There are many similar questions I know but I tried everything and I really can't understand the reason for the seg fault. My eax value up until that add is always correct, I already checked it. Its for linux 32-bit and my commands are:
nasm -f elf32 file.asm -o test.o
gcc test.o
./a.out A1 (input string)