/*
NAME DANIEL PACHECO
COURSE ECE 2730
DATE 11/6/23
FILE dpachec_273_001_4.s
PURPOSE: THE PURPOSE OF PROGRAM IS TO CONVERT STRINGS OF NUMs TO INTS
*/
/*
FUNCTION AtoI
ARGUMENT No argument
RETURN VALUE No return value
DESCRIPTION: This function converts a string nums to an ints
*/
.globl AtoI
.type AtoI,@function
AtoI:
/* prolog */
pushl %ebp
movl %esp, %ebp
pushl %ebx
pushl %esi
pushl %edi
movl 8(%ebp), %edx /* edx = string */
goover_the_s:
movl (%edx), %ecx /* ecx = *edx */
cmp $' ', %ecx /* if*edx == '' */
je increment_p /* edx++*/
cmp $'\t', %ecx /* if edx == '\t'*/
je increment_p /* edx++*/
movl $1, %eax /*eax = 1 */
check_the_sign:
cmp $'+', %ecx /* if *edx =='+'*/
je increment_p /*edx++*/
cmp $'-', %ecx /* if *edx== '-'*/
jne sss /* gotosss */
movl $-1, %eax /*ex =-1 */
increment_p: 
addl $1, %edx /* edx++ */
jmp goover_the_s /* goto goover_the_s*/
sss:
xorl %ebx, %ebx /* ebx = 0 */
check_digit:
movl (%edx,%ebx,1), %ecx /* ecx=*(edx+ebx) */
cmp $'0', %ecx /* if *(edx+ebx) =='0' */
jb done /* goto done */
cmp $'9', %ecx /* if *(edx+ebx) =='9' */
ja done /* goto done */
incl %ebx /* ebx++ */
jmp check_digit /* goto check_digit*/
done:
decl %ebx /* ebx-- */
movl $0, %esi /*si = 0 */
convert_toint:
movl (%edx,%ebx,1), %ecx /* ecx= *(edx+ebx) */
subl $'0', %ecx /* ecx = *(edx+ebx) -'0' */
imull $10, %esi /* si = si * 10*/
addl %ecx, %esi /* si = si+ecx */
decl %ebx /* ebx-- */
jns convert_toint /* goto convert_toint*/
imull %eax, %esi /*si = si * eax */
return:
/* epilog */
popl %edi 
popl %esi
popl %ebx
movl %ebp, %esp
popl %ebp
movl %esi, %eax
ret

/* end assembly stub */