Intel® Quartus® Prime Software
Intel® Quartus® Prime Design Software, Design Entry, Synthesis, Simulation, Verification, Timing Analysis, System Design (Platform Designer, formerly Qsys)
17250 Discussions

VHDL code for register, to use in a binary multiplication circuit

Altera_Forum
Honored Contributor II
2,801 Views

I wrote a piece a VHDL code for a register (to make a shift register circuit) in a binary multiplication circuit. Once I analyzed it in Quartus II several syntax errors were displayed. 

This is my code: 

 

ENTITY memory ISPORT (can_load, can_shift, can_ad, sb_input, ab_input, UserInput : IN BIT;  

Out_Bit, Z : OUT BIT); 

END memory;  

 

ARCHITECTURE logic OF memory IS SIGNAL State: BIT := '0';  

BEGIN  

 

IF (can_load = '1') THEN  

State <= UserInput;  

ELSE  

IF (can_ad = '1') 

THEN Z <= State; --Z is the output that goes to the 4 bit adder  

State <= ab_input;  

END IF;  

IF (can_shift = '1') THEN  

Out_Bit <= State;  

State <= sb_input;  

END IF;  

END IF; 

END logic; 

 

This are the error messages: 

 

Info: ******************************************************************* 

Info: Running Quartus II 64-Bit Analysis & Synthesis Info: Version 14.0.0 Build 200 06/17/2014 SJ Web Edition Info: Processing started: Sun Oct 19 16:28:22 2014 Info: Version 14.0.0 Build 200 06/17/2014 SJ Web Edition Info: Processing started: Sun Oct 19 16:28:22 2014 

Info: Command: quartus_map --read_settings_files=on --write_settings_files=off memory -c memory 

Warning (20028): Parallel compilation is not licensed and has been disabled 

Error (10500): VHDL syntax error at memory.vhd(9) near text "IF"; expecting "end", or "(", or an identifier ("if" is a reserved keyword), or a concurrent statement 

Error (10500): VHDL syntax error at memory.vhd(9) near text "THEN"; expecting "<=" 

Error (10500): VHDL syntax error at memory.vhd(11) near text "ELSE"; expecting "end", or "(", or an identifier ("else" is a reserved keyword), or a concurrent statement 

Error (10500): VHDL syntax error at memory.vhd(12) near text "THEN"; expecting "<=" 

Error (10500): VHDL syntax error at memory.vhd(15) near text "IF"; expecting ";", or an identifier ("if" is a reserved keyword), or "architecture" 

Error (10500): VHDL syntax error at memory.vhd(16) near text "THEN"; expecting "<=" 

Error (10500): VHDL syntax error at memory.vhd(19) near text "IF"; expecting ";", or an identifier ("if" is a reserved keyword), or "architecture" 

Info (12021): Found 0 design units, including 0 entities, in source file memory.vhd 

I have already checked several books for the correct syntax, and code examples and yet I cannot find where's my mistake. 

I also tried to take away the parentheses in sections like this: 

 

IF (can_load = '1') THEN 

 

having something like this: 

 

IF can_load = '1' THEN 

 

but I ended up with most of the same syntax errors. 

 

I'd appreciate any help to solve this issue. Thank you very much.
0 Kudos
6 Replies
Altera_Forum
Honored Contributor II
1,766 Views

conditional assigment with "if" are only valid inside a process: 

 

process( here write the sensitivity list 

begin 

if( .... 

 

Anyway, your code doesn't look good. You are using vhdl like a C program.
0 Kudos
Altera_Forum
Honored Contributor II
1,766 Views

When you put the code in a process, the code you have does not actually describe a register - you need a clock input. and then all the code needs to be wrapped inside: 

 

if rising_edge(clk) then
0 Kudos
Altera_Forum
Honored Contributor II
1,766 Views

 

--- Quote Start ---  

When you put the code in a process, the code you have does not actually describe a register - you need a clock input. and then all the code needs to be wrapped inside: 

 

if rising_edge(clk) then 

--- Quote End ---  

 

 

Thank you, I just did it and it did work :)
0 Kudos
Altera_Forum
Honored Contributor II
1,766 Views

Thank you, I put it inside a clock process and it did work.  

 

I am new to VHDL, so I would really appreciate if you could share some link to an example of a well written VHDL code. I know I do write as if I were making a C program, because I've only coded microcontrollers in C.
0 Kudos
Altera_Forum
Honored Contributor II
1,766 Views

This book is highly recommended: http://www.amazon.co.uk/designers-guide-vhdl-systems-silicon/dp/0120887851/ref=sr_1_1?ie=utf8&qid=1413965590&sr=8-1&keywords=designers+guide+to+vhdl 

 

but any good tutorial you can find on google should tell you how to code the basics.
0 Kudos
Altera_Forum
Honored Contributor II
1,766 Views

 

--- Quote Start ---  

This book is highly recommended: http://www.amazon.co.uk/designers-guide-vhdl-systems-silicon/dp/0120887851/ref=sr_1_1?ie=utf8&qid=1413965590&sr=8-1&keywords=designers+guide+to+vhdl 

 

but any good tutorial you can find on google should tell you how to code the basics. 

--- Quote End ---  

 

 

Thank you so much :)
0 Kudos
Reply