[英]Assembly language program (sum the differences of a number in an array)
I have been tasked, with a homework assignment (I'm not going to sugar-coat it), writing a 32-bit assembly program that uses a loop and indexed addressing to calculate the sum of the gaps between successive array elements, which are in non-decreasing order. 我的任务是进行家庭作业(我不会在上面涂糖),编写一个32位汇编程序,该程序使用循环和索引寻址来计算连续数组元素之间的间隙之和。以非降序排列。 (Ex: dwarray dword 0,2,5,9,10)
(例如:dwarray dword 0、2、5、9、10)
What I don't know how to do is subtract the nth element of an array from the nth-1 element in the array using a loop. 我不知道该怎么做是使用循环从数组的第n-1个元素中减去数组的第n个元素。 If I did, then I would store the result in a different register and keep adding the results into that register until the last element has been reached.
如果这样做了,那么我会将结果存储在另一个寄存器中,并继续将结果添加到该寄存器中,直到到达最后一个元素为止。 I'm only looking to be pointed in the right direction (I'm not looking for the answer).
我只是想指出正确的方向(我不在寻找答案)。 Does anyone have any suggestions?
有没有人有什么建议?
Since you will be using a loop you'll need a loop counter equal to the number of elements in the array minus 1. 由于将使用循环,因此需要一个循环计数器,该计数器等于数组中元素的数量减去1。
Convenient instructions would be add eax,[ebx+ecx*4]
and sub eax,[ebx+ecx*4-4]
方便的说明是
add eax,[ebx+ecx*4]
和sub eax,[ebx+ecx*4-4]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.