查看單個文章
舊 2006-12-07, 02:09 AM   #1
kinco
註冊會員
榮譽勳章
UID - 248756
在線等級: 級別:8 | 在線時長:113小時 | 升級還需:4小時級別:8 | 在線時長:113小時 | 升級還需:4小時級別:8 | 在線時長:113小時 | 升級還需:4小時
註冊日期: 2003-02-06
VIP期限: 2007-04
住址: 台北.中和
文章: 507
精華: 0
現金: 0 金幣
資產: 670 金幣
預設 組合語言的問題~如何防呆

想要做出只能輸入數字~不能輸入字母的防呆~但是我完全把語法忘了~請會的大哥大姊~幫幫小弟吧~萬分感激

引用:
;Add individual digits of a number ADDIGITS.ASM
;
; Objective: To find the sum of individual digits of
; a given number. Shows character to binary
; conversion of digits.
; Input: Requests a number from keyboard.
; Output: Prints the sum of the individual digits.
.MODEL SMALL
.STACK 100H
.DATA
number_prompt db "Please type a number (<11 digits): ",0
out_msg db "The sum of individual digits is: ",0
number db 11 DUP (?)

.486
.CODE
INCLUDE io.mac
.STARTUP
PutStr number_prompt ; request an input number
GetStr number,11 ; read input number as a string
nwln
mov EBX,OFFSET number ; EBX = address of number
sub DX,DX ; DX = 0 -- DL keeps the sum
repeat_add:
mov AL,[EBX] ; move the digit to AL
cmp AL,0 ; if it is the NULL character
je done ; sum is done
and AL,0FH ; mask off the upper 4 bits
add DL,AL ; add the digit to sum
inc EBX ; update EBX to point to next digit
jmp repeat_add
done:
PutStr out_msg
PutInt DX ; write sum
nwln
.EXIT
END
kinco 目前離線  
送花文章: 23, 收花文章: 5 篇, 收花: 9 次
回覆時引用此帖