int¡¡¡¡¡¡¡¡ num[3]={0x10,0x20,0x30};¡¡¡¡
extern¡¡ arrayadd();¡¡¡¡
main()¡¡¡¡
{¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡ printf("sum of num array = %x \n", arrayadd(num));¡¡¡¡
}
¡¡
ÇÁ·Î±×·¥À» array.c ·Î ÀúÀå
assembly ·Î ÇÁ·Î±×·¥ ÀÛ¼º¡¡
¡¡
.MODEL¡¡ SMALL¡¡¡¡
.CODE¡¡¡¡
PUBLIC _arrayadd¡¡¡¡
_arrayadd PROC NEAR¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡ PUSH BP¡¡¡¡¡¡¡¡ ; store BP to stack¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡ MOV¡¡ BP,SP¡¡¡¡ ; BP points to stack top¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡ PUSH SI¡¡¡¡¡¡¡¡¡¡; store SI to stack¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡ XOR¡¡ AX, AX¡¡¡¡ ; clear AX¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡ MOV¡¡ CX, 3¡¡¡¡¡¡¡¡ ; number of elements of array¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡ MOV¡¡ SI, [BP+4] ; near call, then [BP+4] points to
address of array¡¡¡¡
LOOP1:¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡ ADD¡¡ AX, [SI]¡¡¡¡; add the array element¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡ ADD¡¡ SI, 2¡¡¡¡¡¡¡¡; 16bit data¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡ LOOP LOOP1¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡ POP¡¡ SI¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡ POP¡¡ BP¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡ RET¡¡¡¡
_arrayadd ENDP¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡ END