title Row Sum Calculation (RowSumMacro.asm)
Comment!
Tests the mCal_row_sum macro.!
include irvine32.inc
;-------------------------------------------------------
mCalc_row_sum MACRO index,arrayOffset,rowSize,eltType
;Calculates the sum of a row in a 2-dim array
;Receives:row index,offset of the array,number of bytes
;in each table row ,and the array type(byte word or dword);returns:EAX=sum
;--------------------------------------------------------
local L1
push ebx ;save changed regs
push ecx
push esi
;set up the required register
mov eax, index
mov ebx, arrayOffset
mov ecx, rowSize
;calculate the row offset
mul ecx
add ebx, eax
;prepare the loop counter
;byte=0 word=1 dword=2
shr ecx,(TYPE eltType/2);initialize the accumulator and column indexes
mov eax,0;accumulator
mov esi,0;column index
L1:
IFIDNI <eltType>,<DWORD>
mov edx, eltType PTR[ebx+esi*(TYPE eltType)]
ELSE
movzx edx, eltType PTR[ebx+esi*(TYPE eltType)]
ENDIF
add eax, edx ;累加操作
inc esi
loop L1
pop esi
pop ecx
pop ebx
ENDM
.data
tableB BYTE 10h,20h,30h,40h,50h
RowSizeB =($ - tableB)
tableW WORD 10h,20h,30h,40h,50h
RowSizeW =($ - tableW)
tableD DWORD 10h,20h,30h,40h,50h
RowSizeD =($ - tableD)
index DWORD ?.code
main PROC
;Demostrate Base-Index mode:
mCalc_row_sum index,OFFSET tableB,RowSizeB,BYTE
call WriteHex
call Crlf
mCalc_row_sum index,OFFSET tableW,RowSizeW,WORD
call WriteHex
call Crlf
mCalc_row_sum index,OFFSET tableD,RowSizeD,DWORD
call WriteHex
call Crlf
call WaitMsg
exit
main ENDP
End main