汇编语⾔-015(PROC伪指令定义参数⽅式、EXTERNDEF、INCLUDE、
EXTE。。。
1:使⽤PROC伪指令定义参数⽅式不通过寄存器传参,计算数组之和
.386
.model flat,stdcall
.stack 4096
ExitProcess PROTO,dwExitCode:DWORD
.data
array DWORD 10000h,20000h,30000h,40000h,50000h
theSum DWORD ?
.code
ArraySum PROC USES esi ecx,
ptrArray:PTR DWORD,
szArray:DWORD
mov esi,ptrArray
mov ecx,szArray
mov eax,0
cmp ecx,0
je L2
L1:
add eax,[esi]
add esi,4
loop L1
L2:
ret
ArraySum ENDP
main PROC
INVOKE ArraySum,
ADDR array,;数组地址
LENGTHOF array;元素个数
mov theSum,eax;保存和数
INVOKE ExitProcess,0
main ENDP
END main
2:使⽤PROC伪指令定义参数⽅式不通过寄存器传参,交换两个值
include Irvine32.inc
Swap PROTO,pValx:PTR DWORD ,pValy:PTR DWORD
.data
Array DWORD 10000h,20000h
.code
main PROC
;显⽰交换前的数组
mov esi,OFFSET Array
mov ecx ,2
mov ebx,TYPE Array
call DumpMem
INVOKE Swap,ADDR Array,ADDR[Array +4]
call DumpMem
exit
main ENDP
Swap PROC USES eax esi edi,
pValx:PTR DWORD,
pValy:PTR DWORD
mov esi,pValx
mov edi,pValy
mov eax,[esi]
xchg eax,[edi]
mov [esi],eax
ret
Swap ENDP
END main
3:EXTERNDEF_INCLUDE : EXTERNDEF和INCLUDE伪指令,跨模块使⽤变量和标号vars.inc
EXTERNDEF count:DWORD , SYM1:ABS
sub1.asm
.386
.model flat,stdcall
include vars.inc
SYM1 =10
.data
count DWORD 0
END
main.asm
.386
.model flat,stdcall
.stack 4096
ExitProcess PROTO,dwExitCode:DWORD
include vars.inc
.
code
汇编指令有多少个main PROC
mov count,2000h
mov eax,SYM1
INVOKE ExitProcess,0
main ENDP
END main
4:EXTERN : ⽤EXTERN伪指令,多模块编写过程调⽤,传统的使⽤ArraySum.asm
;ArraySum过程
include Irvine32.inc
.code
计算32位整数数组之和
;接收:
;    ptrArray ;数组指针
;    arraySize;数组⼤⼩(DWORD)
;返回:EAX =和数
ArraySum PROC
ptrArray EQU [ebp+8]
arraySize EQU [ebp+12]
enter 0,0
push ecx
push esi
mov eax,0
mov esi,ptrArray
mov ecx,arraySize
cmp ecx,0
jle L2
L1:
add eax,[esi]
add esi,4
loop L1
L2:
pop esi
pop ecx
leave
ret 8
ArraySum ENDP
END
DisplaySum.asm
;在控制台显⽰和数
;接收:
;    ptrPrompt  ;提⽰字符串的偏移量;    theSum    ;数组和数(DWORD) ;返回:⽆
DisplaySum PROC
theSum EQU [ebp+12]
ptrPrompt EQU [ebp+8]
enter 0,0
push eax
push edx
mov edx,ptrPrompt
call WriteString
mov eax,theSum
call WriteInt
call Crlf
pop edx
pop eax
leave
ret 8
DisplaySum ENDP
END
PromptForIntegers.asm
;提⽰⽤户为数组输⼊整数,并⽤⽤户输⼊填充数组;接收:
;    ptrPrompt:PTR BYTE ;提⽰信息字符串
;    ptrArray:PTR DWORD ;数组指针
;    arraySize:DWORD    ;数组⼤⼩
;返回:⽆
PromptForIntegers PROC
arraySize EQU [ebp+16]
ptrArray EQU [ebp+12]
ptrPrompt EQU [ebp+8]
enter 0,0
pushad
mov ecx,arraySize
cmp ecx,0
jle L2
mov edx,ptrPrompt
mov esi,ptrArray
L1:
call WriteString
call ReadInt
call Crlf
mov [esi],eax
add esi,4
loop L1
L2:
popad
leave
ret 12
PromptForIntegers ENDP
END
Startup.asm

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。