简体   繁体   English

汇编语言程序(求和一个数组中数字的差)

[英]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.

相关问题 汇编语言,用于检查数字是否可被 2 整除并循环打印数字的程序 - Assembly language, program to check if a number is divideable by 2 and print numbers in a loop 数组 Codewars 中的差异总和 (Javascript) - Sum of Differences in an Array Codewars (Javascript) 将 C 程序转换为 MIPS 汇编语言程序 - Converting a C program into MIPS assembly language program 使用循环计算 10 个 32 位整数数组的总和的汇编程序 - Assembly Program to calculate the sum of an array of 10 32-bit integers using loop(s) C语言的三角数程序? - Triangle number program in C language? 破解汇编语言 - 找到 RAM 中的最大数字 - Hack assembly language - finding the maximum number in RAM 在C中,我的程序输出的数字不在用户输入数组内或数组中任何数字之和不输出任何内容 - In C, my program to output a number not inside a user input array or not sum of any numbers in the array is not printing anything 如何用Irvine汇编语言反转数组? - How to reverse an array in Irvine Assembly Language? 我想用汇编语言计算前 n 个整数的总和 - I would like to calculate the sum of the first n integers in assembly language 这个汇编语言程序需要什么改变才能工作? - What change does this assembly language program need to work?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM