USE QUARTUS TO WRITE THE CODE.
1- Objective
The objective is to use algorithmic state machine integrated (ASM) with a Datapath to
design circuit that outputs the maximum length of equal ones and zeros in a number.
2- circuit
It is circuit which counts the maximum length of equal zeros and ones.
2.1 C++ Code
NOTE: TEMP is not required. (Line 15)
2.2- Sample Output
3- Required Tasks
3.1- Datapath ASM
Design Algorithmic state machine (ASM) for Datapath.
3.2- Datapath circuit
Design circuit for Datapath based on the ASM you designed in 3.1.
3.3- Controller ASM
Design Algorithmic state machine (ASM) for Controller.
3.4- Coding
Implement using VHDL the controller and the Datapath.
Expert Answer
General guidance
The answer provided below has been developed in a clear step by step manner.
FIRST STEP | ALL STEPS | ANSWER ONLY
Step-by-step
Step 1 of 1
#include <iostream> #include <string.h> using namespace std; int main() { //cout<<"Hello World"; string s; cout << "enter string"; cin >> s; string temp,result; int max=0; for(int i=0;i<s.size();i++){ temp=s[i]; int fr[2]={ 0 }; if(s[i] == '0') fr[0]++; else fr[1]++; for(int j=i+1;j<s.size();j++){ temp+=s[j]; if(s[j] == '0') fr[0]++; else fr[1]++; if(fr[0] == fr[1]){ if(max < j- i + 1){ max=j-i+1; result=temp; } } } } cout<< "string s =" << s <<endl; cout<< "result where equal no. of ones and zeros " << result << endl; cout<<"max" << max << endl; return 0; }
output for the above program:
enter stringhelo102
string s =helo102
result where equal no. of ones and zeros 10
max2
Please refer to solution in this step.
ليست هناك تعليقات:
إرسال تعليق