My teacher gave us this small assignment to do and i just have no clue where to start,
We have this C code
extern "C" {
bool isStringEqual(const char *s1, const char *s2);
}
static char *testStrings[] = {
"",
"Test String 1",
"Test String 2",
};
#define NUM_TEST_CASES (sizeof (testStrings) / sizeof (char *))
int main()
{
printf("CSIS-165 ICE#8 Bochsler\n\n");
for (int i = 0; i < NUM_TEST_CASES; i++) {
printf("Input string [%s] [%s] yields: %s\n ", testStrings[i], testStrings[i],
isStringEqual(testStrings[i], testStrings[i]) ? "true" : "false");
}
printf("Input string [%s] [%s] yields: %s\n ", testStrings[1], testStrings[2],
isStringEqual(testStrings[1], testStrings[2]) ? "true" : "false");
system("PAUSE");
return 0;
}
And have to write the asm that does this
- take two char * arguments via the stack
- implements a C calling interface and follows the C calling conventions
- implements the following logic:
bool isStringEqual(const char *s1, const char * s2)
{
while (*s1 != 0 && *s2 != 0) {
if (*s1 != *s2)
return false;
}
return true
}
Weve done things with C and asm before but compared numbers together and figured out which is the longest. I understand how to do the while loops but i have no fucking clue what is going on in that C code, I dont understand how to get the strings and compare them. If i could get some help figuring out how to compare the strings i am sure i could do the while loop.
I tried something like this:
PUSH ebp ; save caller base pointer
MOV ebp, esp ; set our base pointer
PUSH edi
PUSH esi
MOV eax, [ebp + 8]
MOV ebx, [ebp + 12]
top:
CMP eax,0
CMP eax, ebx ; check loop condition
JAE next ; false? exit loop
; loop body
INC eax ; adjust condition
JMP top ; repeat the loop
next:
PUSH OFFSET fmt ; push the string format
ADD esp, (2 * 4) ; clear the stack
then deallocate and restore pointers but nothing is working,