【Win32汇编】数组求和函数
生活随笔
收集整理的這篇文章主要介紹了
【Win32汇编】数组求和函数
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
32位數(shù)組求和函數(shù),esi 保存數(shù)組偏移,ecx 保存數(shù)組長度,同時用于 loop 計數(shù), eax 返回和。
.386 .model flat, stdcall .stack 4096 ExitProcess proto, dwExitCode:DWORD.data array DWORD 10000h, 20000h, 30000h, 40000h, 50000h theSum DWORD ?.code main PROC mov esi, offset array ;// esi 作為參數(shù)保存數(shù)組地址 mov ecx, lengthof array ;// ecx 是數(shù)組長度參數(shù) call ArraySum mov theSum, eaxinvoke ExitProcess, 0 main ENDPArraySum PROC push esi ;// 如果不希望函數(shù)修改寄存器,則用棧保存,返回時恢復 push ecx mov eax, 0 ;// sum = 0L1: add eax, [esi] add esi, type dword loop l1pop ecx pop esi ret ArraySum ENDPend main函數(shù)中使用push pop 臨時保存寄存器的值,并在ret前恢復。也可以用uses偽指令代替,讓匯編器自動添加push pop。
總結
以上是生活随笔為你收集整理的【Win32汇编】数组求和函数的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【Win32汇编】字符串逆序
- 下一篇: 【Win32汇编】测试Irvine32库