首页
社区
课程
招聘
[求助][求助][求助]关于index的传值问题
2013-8-13 16:34 7428

[求助][求助][求助]关于index的传值问题

2013-8-13 16:34
7428
以下是汇编源码,偶只是弄不清楚传入宏的index参数是什么,是内存地址,还是数据类型的大小?

TITLE Row Sum Calculation               (RowSumMacro.asm)

INCLUDE Irvine32.inc

;------------------------------------------------------------
mCalc_row_sum MACRO index, arrayOffset, rowSize, eltType
; Calculates the sum of a row in a two-dimensional 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 registers
        mov eax,index
        mov ebx,arrayOffset
        mov ecx,rowSize

; calculate the row offset.
        mul ecx                ; row index * row size
        add ebx,eax        ; row offset

; prepare the loop counter.
        shr ecx,(TYPE eltType / 2) ; byte=0, word=1, dword=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        ; add to accumulator
        inc esi
        loop L1

        pop esi                ; restore changed regs
        pop ecx
        pop ebx
ENDM

.data
tableB BYTE 10h, 20h, 30h, 40h, 50h
RowSizeB = ($ - tableB)
        DWORD 60h, 70h, 80h, 90h, 0A0h
        DWORD 0B0h, 0C0h, 0D0h, 0E0h, 0F0h

tableW WORD 10h, 20h, 30h, 40h, 50h
RowSizeW = ($ - tableW)
        DWORD 60h, 70h, 80h, 90h, 0A0h
        DWORD 0B0h, 0C0h, 0D0h, 0E0h, 0F0h

tableD DWORD 10h, 20h, 30h, 40h, 50h
RowSizeD = ($ - tableD)
        DWORD 60h, 70h, 80h, 90h, 0A0h
        DWORD 0B0h, 0C0h, 0D0h, 0E0h, 0F0h

index DWORD ?

.code
main PROC

; Demonstrate Base-Index mode:

        mCalc_row_sum index, OFFSET tableB, RowSizeB, BYTE
        mCalc_row_sum index, OFFSET tableW, RowSizeW, WORD
        mCalc_row_sum index, OFFSET tableD, RowSizeD, DWORD

        exit
main ENDP
END main

请大神赐教,小弟在此拜谢了!

阿里云助力开发者!2核2G 3M带宽不限流量!6.18限时价,开 发者可享99元/年,续费同价!

收藏
点赞0
打赏
分享
最新回复 (0)
游客
登录 | 注册 方可回帖
返回