I'm working on a function that picks a string, for example "input db '5', 0" and turns it into "input '53', 0" (an int). I have the following code. But everytime I run it outputs Segmentation Fault (core dumped).
stoi:
push ebx
mov ebx, eax
stoiLoop:
; if is null: end
cmp byte[ebx], 0
call stlEnd
; if < 48: continue
cmp byte[ebx], 48
jl stlContinue
; if > 57: continue
cmp byte[ebx], 57
jg stlContinue
; add 48 so it matches the ascii code of number
mov al, [ebx]
add al, 48
call stlContinue
stlContinue:
inc ebx
call stoiLoop
stlEnd:
mov eax, ebx
pop ebx
ret
I tried with other addresses and even tried concatenating results, everything outputs the same issue.