史萊姆論壇

史萊姆論壇 (http://forum.slime.com.tw/)
-   程式語言討論區 (http://forum.slime.com.tw/f76.html)
-   -   組合語言的問題~如何防呆 (http://forum.slime.com.tw/thread193068.html)

kinco 2006-12-07 02:09 AM

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

引用:

;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


mini 2006-12-07 12:21 PM

這一行
GetStr number,11 ; read input number as a string
要改成11迴圈 並 判斷鍵入值是否落在 數字字元碼範圍內
(不是的話 不以顯示,並迴圈數不減;當迴圈數減為0 時跳脫迴圈)
mov ah,**H
int 21h

其中 **H 根據不同數值有不同輸入功能
這要翻書
因為很久沒碰 ASM 也沒組譯器所以只能將這麼多


所有時間均為台北時間。現在的時間是 10:07 PM

Powered by vBulletin® 版本 3.6.8
版權所有 ©2000 - 2025, Jelsoft Enterprises Ltd.

『服務條款』

* 有問題不知道該怎麼解決嗎?請聯絡本站的系統管理員 *


SEO by vBSEO 3.6.1