程式碼:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
TITLE 等待輸入數字,會自動計算它的階層,例如輸入5時,則1*2*3*4*5=120,會顯示計算結果 (h501.asm) | |
INCLUDE Irvine32.inc ;INCLUDE 指令會從位於組譯器的INCLUDE目錄內的Irvine32.inc文字檔中,複製必要的定義與初始資訊 | |
.data ;.data標記程式中含有變數的區域 | |
Equal BYTE "=",0 | |
MulString BYTE "*",0 | |
val DD ? | |
sum DD 1 | |
.code ;.code指引標記著程式碼區段起始的位置,所有可執行的敘述,都會放在程式碼區段內 | |
Compute PROC USES ecx edx eax esi | |
mov ecx ,val | |
mov eax ,1t ;store the answer | |
mov esi ,1t ;the timer | |
mov sum,1 | |
L1: | |
.IF esi>1 | |
mov edx,OFFSET MulString | |
call WriteString | |
.ENDIF | |
mov eax,esi | |
call WriteInt | |
mov eax,sum | |
mul esi | |
mov sum,eax | |
inc esi | |
loop L1 | |
ret | |
Compute ENDP | |
main PROC ;PROC指引標記著程序的起始位置 | |
L1: ;迴圈開始 | |
call ReadInt | |
mov val,eax | |
call Compute | |
mov edx,OFFSET Equal | |
call WriteString | |
mov eax,sum | |
call WriteInt | |
call crlf | |
jmp L1 ;ecx-=1,if(ecx>1)繼續跑回圈 | |
exit ;將(非直接)呼叫一個預先定義的MS-Windows函式,此函式的作用是停止此程式的執行 | |
main ENDP ;ENDP標記main程序的結束位置 | |
END main ;標記此程式啟動的程序 | |
沒有留言:
張貼留言
注意:只有此網誌的成員可以留言。