[問題] 有限狀態機FSM的問題

看板Programming作者 (56好棒)時間14年前 (2010/05/17 22:05), 編輯推噓0(002)
留言2則, 1人參與, 最新討論串1/1
TITLE Finite State Machine (Finite.asm) ; This program implements a finite state machine that ; accepts an integer with an optional leading sign. ; Last update: 06/01/2006 INCLUDE Irvine32.inc ENTER_KEY = 13 .data InvalidInputMsg BYTE "Invalid input",13,10,0 .code main PROC call Clrscr StateA: call Getnext ; read next char into AL cmp al,'+' ; leading + sign? je StateB ; go to State B cmp al,'-' ; leading - sign? je StateB ; go to State B call IsDigit ; ZF = 1 if AL contains a digit jz StateC ; go to State C call DisplayErrorMsg ; invalid input found jmp Quit StateB: call Getnext ; read next char into AL call IsDigit ; ZF = 1 if AL contains a digit jz StateC call DisplayErrorMsg ; invalid input found jmp Quit StateC: call Getnext ; read next char into AL call IsDigit ; ZF = 1 if AL contains a digit jz StateC cmp al,ENTER_KEY ; Enter key pressed? je Quit ; yes: quit call DisplayErrorMsg ; no: invalid input found jmp Quit Quit: call Crlf exit main ENDP ;----------------------------------------------- Getnext PROC ; ; Reads a character from standard input. ; Receives: nothing ; Returns: AL contains the character ;----------------------------------------------- call ReadChar ; input from keyboard call WriteChar ; echo on screen ret Getnext ENDP ;----------------------------------------------- DisplayErrorMsg PROC ; ; Displays an error message indicating that ; the input stream contains illegal input. ; Receives: nothing. ; Returns: nothing ;----------------------------------------------- push edx mov edx,OFFSET InvalidInputMsg call WriteString pop edx ret DisplayErrorMsg ENDP END main 以上的程式碼執行結果: 輸入+,-,或數字 然後再輸入數字最後按Enter鍵會正常結束 如果輸入其他的字原則會顯示"Invalid input"錯誤訊息 如果現在希望輸入小數點也不會產生錯誤訊息,可以正常結束 那需要在StateC的 cmp al,ENTER_KEY 之前加入什麼指令呢? -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 220.143.27.20

05/17 22:47, , 1F
請認真讀懂抄來的程式, 自然就會寫了
05/17 22:47, 1F

05/17 22:52, , 2F
你需要加入的指令上面的程式裡都有範例
05/17 22:52, 2F
文章代碼(AID): #1ByKr7Gw (Programming)