題目要求:使用者輸入一字串,輸入第一個數字代表要移走字串的開頭,輸入另一個數字代表要移走字串的數目,運用INVOKE。
EX:
input: I am ha*****ppy.
input:7
input:5
output: I am happy.
關鍵:
INVOKE 與CALL最大的不同在於是否可傳值,
例:
call Str_remove
INVOKE Str_remove,ADDR target,rmStart,rmNumber
要注意的是要丟什麼值,就必須在data section裡寫好:
Str_remove PROTO,
tarStr:PTR BYTE,
rmS:DWORD,
rmN:DWORD
PROTO主要應用於multiprogram,也可採多分頁來呼叫。
ADDR 是傳記憶體位置,與OFFSET相似。
執行畫面:
SOURCE CODE
TITLE String remove(Str_remove.asm)
INCLUDE Irvine32.inc
.data
Str_remove PROTO,
tarStr:PTR BYTE,
rmS:DWORD,
rmN:DWORD
myMessage BYTE "Please input a string:",0
askF BYTE "Please input first number:",0
askL BYTE "Please input second number:",0
resultMsg BYTE "result:",0
target BYTE 200 DUP(0)
rmStart DWORD ?
rmNumber DWORD ?
.code
main PROC
mov edx,OFFSET myMessage
call writeString
mov edx,OFFSET target
mov ecx,SIZEOF target
call readString
mov edx,OFFSET askF
call writeString
call readInt
mov rmStart,eax
mov edx,OFFSET askL
call writeString
call readInt
mov rmNumber,eax
mov edx,OFFSET resultMsg
call writeString
INVOKE Str_remove,ADDR target,rmStart,rmNumber
call crlf
call main
exit
main ENDP
Str_remove PROC,
tarStr:PTR BYTE,
rmS:DWORD,
rmN:DWORD
mov esi,tarStr
mov ecx,rmS
L1:
mov al,[esi]
call writeChar
add esi,1
loop L1
add esi,rmN
mov edx,esi
call WriteString
ret
Str_remove ENDP
END main