当前位置: 代码迷 >> 汇编语言 >> 简单数组求和,请问
  详细解决方案

简单数组求和,请问

热度:9631   发布时间:2013-02-26 00:00:00.0
简单数组求和,请教!
Assembly code
;数组求和include io32.inc.data    array byte 1,2,3,6    msg1 byte 'The factors of the array are: ',0ah,0dh,0    msg2 byte 'The sum of the factors is:',0.codebegin:    mov ecx,lengthof array    mov eax,offset msg1    call dispmsg    mov eax,offset array    call dispuid    xor eax,eaxagain:    add eax,array[ecx]        ;不能用变量名直接给eax做加法吗?    loop again    mov ebx,eax    mov eax,offset msg2    call dispmsg    mov eax,ebx    call dispuidexit 0end begin


如上,存储单元与寄存器之间可以add运算的吗?数组是存在主存中,为何不能直接用数组名和ecx寻址与寄存器做加法?请教!

------解决方案--------------------------------------------------------
可以做add运算,但是感觉你的ecx里面的值不对,另外你这个循环的次数怎么进行的呢
------解决方案--------------------------------------------------------
mem + reg 是可以的,你的代码还可以重构一下.

问题是你的array数组大小是byte类型的,你不可以直接与DWORD类型的eax相加.

你可以转换长度后再相加.
------解决方案--------------------------------------------------------
2楼的意思是array 是byte,eax是dword,类型不匹配不是说ecx
  相关解决方案