ข้อสอบ CT215 ปี 2551 เขียน code assembly ยาว
แสดงความเห็นโดย จั่น บน ธันวาคม 8, 2008
เป็นส่วนของการเขียน program ยาว ซึ่งเป็นตัวอย่างหนึ่งเท่านั้น อาจารย์สามารถออกโจทย์ได้เยอะมากครับ
โจทย์ หาค่า Factorial
Program Calculate Factorial
Insert N Factorial: 6
Result: +720
Run Again (y/n):
————–
TITLE (.asm)
; This program
; Last update:
Include Irvine32.inc
Include Macros.inc
.data
Total DWORD ?
.code
main PROC
Start:
call Clrscr
mGotoxy 20,10
mWrite <”Program Calculate Factorial”,0dh,0ah>
mGotoxy 20,11
mWrite “Insert N Factorial: “
call ReadInt
cmp eax,0
; if less than 0
;go to start again
;-1!, -2! cannot find value
jl Start
;else if eax=0
je L0
;else eax>0
jmp Entry
L0:
mov eax, 1
Entry:
mov ecx, eax
mov eax, 1
L1:
MUL ecx
LOOP L1
mGotoxy 20,12
mWrite “Result: “
call WriteInt
mGotoxy 20,13
mWrite “Run Again (y/n): “
L2:
call ReadChar
call WriteChar
cmp al,’y’
je Start
exit
main ENDP
END main
