Vous pouvez copier (copy & paste) les algos en Language Machine et les faire fonctioner dans l'Applet Java du simulateur de LMC ================= Final IFT1215 H22 ================= Question_II.1 1-iere possibilité -------------------------------- BRA a-state a-init LDA sort0 OUT a-state INP STO entry BRZ a-init LDA entry SUB ent2 BRZ b-init BRA a-init b-init LDA sort0 OUT b-state INP STO entry BRZ b-init LDA entry SUB ent2 BRZ c-init LDA sort1 OUT BRA a-state c-init LDA sort0 OUT c-state INP STO entry BRZ c-init LDA entry SUB ent2 BRZ d-init LDA sort2 OUT BRA a-state d-init LDA sort0 OUT d-state INP STO entry BRZ d-init LDA entry SUB ent1 BRZ c-s001-a LDA sort4 OUT BRA a-state c-s001-a LDA sort3 OUT BRA a-state ent0 DAT 0 ent1 DAT 1 ent2 DAT 2 sort0 DAT 0 sort1 DAT 1 sort2 DAT 2 sort3 DAT 3 sort4 DAT 4 zero DAT 0 entry DAT 0 Question_II.1 2-ieme possibilité -------------------------------- entree INP BRZ out0 SUB one BRZ e1 SUB one BRZ e2 BRA entree see-out LDA sortie OUT LDA zero STO sortie BRA entree out0 LDA zero OUT BRA entree e1 LDA state BRZ out0 LDA zero STO state BRA see-out e2 LDA sortie ADD one STO sortie LDA state SUB three BRZ e2d LDA state ADD one STO state BRA out0 e2d LDA zero STO state LDA sortie ADD one BRA see-out state DAT 0 sortie DAT 0 zero DAT 0 one DAT 1 two DAT 2 three DAT 3 Question_III.1 1-iere possibilité --------------------------------- #!/bin/bash # FSMH22.sh script [Simulateur FSM Distributeur de consigne FinalH22] while [ : ] do FlagReturnInStateA=0 ; Input=0 ; Output=0 #-[A-State]------ while [ $Input -lt 2 ] do echo Etat A ; echo Entrees ? ; read Input echo Entrees:$Input / Sorties:$Output done #-End-A--- #-[B-State]------ while [ : ] do echo Etat B ; echo Entrees ? ; read Input if [ $Input -gt 0 ]; then break; fi echo Entrees:$Input / Sorties:$Output done if [ $Input -eq 1 ]; then Output=1 FlagReturnInStateA=1 ####-------B-->>Retour-En--A echo Entrees:$Input / Sorties:$Output fi if [ $Input -eq 2 ]; then Output=0 echo Entrees:$Input / Sorties:$Output FlagReturnInStateA=0 fi #-End-B------- #-[C-State]------ if [ $FlagReturnInStateA -eq 0 ]; then while [ : ] do echo Etat C ; echo Entrees ? ; read Input if [ $Input -gt 0 ]; then break; fi echo Entrees:$Input / Sorties:$Output done if [ $Input -eq 1 ]; then Output=2 FlagReturnInStateA=1 ####------C-->>Retour-En--A echo Entrees:$Input / Sorties:$Output fi fi #-End-C------- #-[D-State]- if [ $FlagReturnInStateA -eq 0 ]; then while [ : ] do echo Etat D ; echo Entrees ? ; read Input if [ $Input -gt 0 ]; then break; fi echo Entrees:$Input / Entrees:$Input done if [ $Input -eq 1 ]; then Output=3 echo Entrees:$Input / Sorties:$Output fi if [ $Input -eq 2 ]; then Output=4 echo Entrees:$Input / Sorties:$Output fi fi #-End-D------- done Question_III.1 2-ieme possibilité --------------------------------- #!/bin/bash # FSMH22_2.sh script [Simulateur FSM Dist. de consigne] state=0 while [ : ] do echo -n Etat ${state} :: Entrees ? ; read Input if [ $Input -eq 0 ]; then echo fi if [ $Input -eq 1 ]; then echo Etat ${state} et je rend ${state} piece(s) de 25 sous echo state=0 fi if [ $Input -eq 2 ]; then let state=state+1 if [ $state -eq 4 ]; then state=0 echo je reviens a Etat ${state} apres avoir rendu 1 dollar fi fi done Question_III.1 3-ieme possibilité --------------------------------- #!/bin/bash # FSMH22_3.sh script [Simulateur FSM Dist. de consigne] state=A while [ : ] do case $state in A) echo -n Etat ${state} :: Entrees ? ; read Input case $Input in 0) ;; 1) ;; 2) state=B ;; esac ;; B) echo -n Etat ${state} :: Entrees ? ; read Input case $Input in 0) ;; 1) state=A; echo -n je rend 1 piece de 25 sous " " ;; 2) state=C ;; esac ;; C) echo -n Etat ${state} :: Entrees ? ; read Input case $Input in 0) ;; 1) state=A; echo -n je rend 2 pieces de 25 sous " " ;; 2) state=D ;; esac ;; D) echo -n Etat ${state} :: Entrees ? ; read Input case $Input in 0) ;; 1) state=A; echo -n je rend 3 pieces de 25 sous " " ;; 2) state=A; echo -n je rend 1 piece de 1 dollar " " ;; esac ;; esac done Question_III.1 4-ieme possibilité --------------------------------- #!/bin/bash # FSMH22_4.sh script [Simulateur FSM Dist. de consigne] state=0 while [ : ] do echo -n Etat ${state} :: Entrees ? ; read Input if [ $Input -eq 2 ]; then let state=state+1 fi if [ $Input == 1 -o $state -eq 4 ]; then case $state in 0) echo "je retourne aucune piece" ;; 1) echo "je retourne 1 piece de 25 sous" ;; 2) echo "je retourne 2 pieces de 25 sous" ;; 3) echo "je retourne 3 pieces de 25 sous" ;; 4) echo "je retourne 1 pieces de 1 dollar" ;; esac let state=0 fi done Question_III.1 5-ieme possibilité --------------------------------- state=0; while [ : ]; do echo -n Etat ${state} :: Entrees ? ; read Input if [ $Input -eq 2 ]; then let state=state+1; fi if [ $Input == 1 -o $state -eq 4 ]; then echo "je retourne" $state "piece(s) de 25 sous"; let state=0; fi; done