程式碼:
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 HW3_simple loop (h303.asm) | |
INCLUDE Irvine32.inc ;INCLUDE 指令會從位於組譯器的INCLUDE目錄內的Irvine32.inc文字檔中,複製必要的定義與初始資訊 | |
.data ;.data標記程式中含有變數的區域 | |
Startstring BYTE "y = ",0 | |
val1 DWORD 1t | |
val2 DWORD 2t | |
sum DD 0t | |
.code ;.code指引標記著程式碼區段起始的位置,所有可執行的敘述, | |
;都會放在程式碼區段內 | |
main PROC ;PROC指引標記著程序的起始位置 | |
mov ecx, 9 ;迴圈跑9次 | |
EatRedApple: ;迴圈開始 | |
mov eax,val1 ;register(eax) = val1 | |
mul val2 ;register(eax) *= val2 | |
add sum,eax ;sum += register(eax) | |
mov eax,1t ;register(eax) = 1 | |
add val1,eax ;val1++ | |
add val2,eax ;val2++ | |
loop EatRedApple ;ecx-=1,if(ecx>1)繼續跑回圈 | |
lea edx,offset startstring ;將字串移至edx暫存器中 | |
call WriteString ;顯示在edx暫存器中的字串 | |
mov eax,sum | |
call WriteInt | |
call crlf | |
exit ;將(非直接)呼叫一個預先定義的MS-Windows函式, | |
;此函式的作用是停止此程式的執行 | |
main ENDP ;ENDP標記main程序的結束位置 | |
END main ;標記此程式啟動的程序 | |
沒有留言:
張貼留言
注意:只有此網誌的成員可以留言。