gqchynaboy
MIS
I need help converting a hex to. I'm getting core dumps while compiling under Linux. Any help would be greatly appreciated!
This is the C code
This is what I have so far for my Assembly language
This is the C code
Code:
unsigned int HexToInt(char *theString)
{
unsigned int value = 0;
char temp;
while(*theString != '\0')
{
value *= 16; /* peel off right digit */
if (*theString <= '9')
temp = *theString & 0x0f;
else /* convert ascii to int */
{
temp = *theString & 0x0f;
temp = temp + 9;
}
value += (int) temp;
theString++;
}
return value;
}
This is what I have so far for my Assembly language
Code:
ptr =-8
value =-4
strPtr =8
.text
.globl hexToInt
hexToInt:
pushl %esp
movl %esp, %ebp
addl $ptr, %esp
movl $0, value(%ebp)
movl strPtr(%ebp), %eax
movl %eax, ptr(%ebp)
loop:
movl ptr(%ebp), %eax
cmpb $0, (%eax)
je allDone
cmpb $'9', (%eax)
jle temp1
addl $0x0f, %eax
addl $0x9, %eax
shll $4, value(%ebp)
addl %eax, value(%ebp)
incl ptr(%ebp)
jmp loop
temp1:
addl $0x0f, %eax
addl %eax, value(%ebp)
incl ptr(%ebp)
jmp loop
allDone:
movl value(%ebp), %eax
movl %ebp, %esp
popl %ebp
ret