我有一个代码我试图添加到visual studio c ++给我一个输出,我迷失了 [英] I have a code im trying to add to visual studio c++ to give me an output and im lost
问题描述
.data
array1 DWORD 10d,20d,30d,40d,50d,60d,70d,80d,90d
.code
主要PROC
mov ESI,OFFSET array1; ESI现在指向array1的第一项
mov EDI,SIZEOF array1
添加EDI,OFFSET array1
sub EDI,TYPE array1; EDI现在指向array1的最后一项
mov ECX,LENGTHOF array1
shr ECX,1;现在ecx是array1长度的一半
L1:mov EAX,[ESI];在这个循环中我们反转数组的项目
mov EBX,[EDI]
mov [EDI],EAX
mov [ESI],EBX
添加ESI,TYPE array1
子EDI,类型数组1
LOOP L1
mov ECX,LENGTHOF array1;这里我们只打印数组
mov ESI,OFFSET array1
L2:MOV EAX,[ESI]
致电WriteInt
致电Crlf
添加ESI,类型数组1
LOOP L2
退出
主要ENDP
END main
这个是我必须添加到我的项目的代码,但我不知道如何将其转换为c ++工作。
.data
array1 DWORD 10d,20d,30d,40d,50d,60d,70d,80d,90d
.code
main PROC
mov ESI, OFFSET array1 ;ESI now points to the first item of array1
mov EDI, SIZEOF array1
add EDI, OFFSET array1
sub EDI, TYPE array1 ;EDI now points to the last item of array1
mov ECX, LENGTHOF array1
shr ECX, 1 ;now ecx is half the length of the array1
L1: mov EAX, [ESI] ;in this loop we reverse the items of the array
mov EBX, [EDI]
mov [EDI],EAX
mov [ESI],EBX
add ESI, TYPE array1
sub EDI, TYPE array1
LOOP L1
mov ECX, LENGTHOF array1;here we just print the array
mov ESI, OFFSET array1
L2: MOV EAX, [ESI]
call WriteInt
call Crlf
add ESI, TYPE array1
LOOP L2
exit
main ENDP
END main
This is the code i have to add to my project but im not sure how i convert it into c++ to work.
推荐答案
此代码假定您已定义_countof宏。
https://msdn.microsoft。 com / en-us / library / ms175773.aspx [ ^ ]
This code assumes you have the _countof macro defined.
https://msdn.microsoft.com/en-us/library/ms175773.aspx[^]
#include <stdio.h>
// array1 DWORD 10d,20d,30d,40d,50d,60d,70d,80d,90d
static long words[] = {10, 20, 30, 40, 50, 60, 70, 80, 90};
int main(int argc, char *argv[])
{
// swap the array.
unsigned count = _countof(words);
unsigned half = _count / 2;
for (unsigned i = 0; i < half; i++)
{
long swap = words[i];
words[i] = words[count - i - 1];
words[count - i - 1] = swap;
}
// print the array.
for (unsigned i = 0; i < half; i++)
{
printf(" %ld", words[i]);
}
return 0;
}
</stdio.h>
你知道,打印出来会更简单数字的顺序相反。
You know, it would be simpler to just print the numbers in reverse order.
#include <stdio.h>
static long words[] = {10, 20, 30, 40, 50, 60, 70, 80, 90};
int main(int argc, char *argv[])
{
// print the array.
unsigned i = _countof(words);
while (i > 0)
{
printf(" %ld", words[--i]);
}
return 0;
}
</stdio.h>
这篇关于我有一个代码我试图添加到visual studio c ++给我一个输出,我迷失了的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!