As there isn't too much information I could find on mixing C++ and Assembly, I wanted some clarification on some issues I am having with assembly.
I am working on a project where we have to pass an array to a separate .asm document in order to reverse the string. Please see the code of the .cpp file I started with (not including header below):
extern"C" int swap(char*, int);
int main()
{
const int SIZE = 20;
char str1[20] = { '\0' };
cout << "Please enter a string: ";
cin >> str1;
swap(str1,SIZE);
return 0;
}
From here, I would start the following in my .asm document (not including the header in the code below):
_swap PROC
push ebp
mov ebp,esp ;stack pointer to ebp
mov ebx,[ebp+8] ; address of first array element
mov ecx,[ebp+12]
The asm code above is what was shown in class to access the array. At this point, does the pointer iterate to the next index if I add 4 to ebx register?
Let say the first index (0) in my array is 'a'. Does performing mov ebx,[ebp+8] set ebx to the address of where 'a' is? If so, incrementing ebx 4 bytes should move it to the next index, correct?
Since I am still learning and this is very new to me, I apologize for any syntax mistakes. I believe I am just trying to get more clarifications rather than answers.
At this point, does the pointer iterate to the next index if I add 4 to ebx register?
Your declaration of swap
is extern"C" int swap(char*, int);
Since the pointer is a pointer to char
, you should add 1 to ebx
to make it point to the next element.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.