有许多有限状态机问的问题,但都与我的问题无关 .
我需要5种方法
S0 S1 S2 S3 and read the input
我们开始吧
S0
我们要打印状态→0和输出0→
读输入首先是ebx,第二个是eax
. If (ebx ==0&&eax==0)
Call S0
.elseif (ebx==1)&&(eax==1)
Call S1
.else
Call S2
.endif
完成整个计划
这是我的代码:这里的问题是输入不起作用 . 如果我输入00,01,11 - >这一切都给了我相同的输出,这是不对的 . 我想输入00并拨打S0,输入11呼叫S1 . 这不是我没有做到的原因 . 任何人都可以搞清楚 .
TITLE finite state machine
INCLUDE Irvine32.inc
E = 13
.data
invalidMsg BYTE 'Ivalid input',0
a DWORD ?
b DWORD ?
count dword ?
prompt1 byte 'Enter 0 or 1: ',0
prompt2 byte 'Enter 0 or 1: ',0
num1 byte 'The output is now 1 ',0
num2 byte 'The ouput is now 0',0
num3 byte 'The state is now 0 ',0
num4 byte 'The state is now 1 ',0
num5 byte 'The state is now 2 ',0
num6 byte 'The state is now 3 ',0
.code
main PROC
call clrscr
mov edx,offset prompt1
call writestring
call readint
mov a,ebx
mov edx,offset prompt2
call writestring
call readint
mov b,eax
.if(ebx ==0 && eax == 0)
call S0
.elseif(ebx == 1 && eax == 1)
call S1
.elseif(ebx == 0 && eax == 1)
call S2
.else
call S3
.endif
exit
main ENDP
S0 proc
mov edx,offset num3
call writestring
call crlf
mov edx,offset num2
call writestring
call readint
ret
S0 endp
S1 proc
mov edx,offset num4
call writestring
call crlf
mov edx,offset num2
call writestring
ret
S1 endp
S2 proc
mov edx,offset num5
call writestring
call crlf
mov edx,offset num1
call writestring
call crlf
ret
S2 endp
S3 proc
mov edx,offset num6
call writestring
call crlf
mov edx,offset num1
call writestring
ret
S3 endp
END main
2 回答
我假设
a
和b
是你的州?所以你在那里存储状态,但是你在中间调用函数,所以我会假设ebx
在你检查之前被删除了 .所以在这里你需要至少恢复
ebx
才能进行检查(eax已经包含了值) .不确定
a
是否应该在eax
中,所以你可能也必须交换它们 .另外我有点惊讶你拨打
readint
并将ebx
移动到a
并且再次调用readint
之后,但这次将eax
移动到b
. 我认为readint
会返回eax
中的值,对(你没有提供代码)?那么在第一次通话中ebx
会有什么 Value 呢?它可能也应该是update