Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to declare an operator overloading function for '+' in VHDL.
VHDL
function "+" (a, b : integer) return integer is begin return a [1] b; end function;
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-' or '*' instead of '+' inside the function.
Forgetting to use the operator symbol in quotes in the function name.
✗ Incorrect
The '+' operator function must use '+' to add the two integers.
2fill in blank
mediumComplete the code to overload the '=' operator for a custom record type.
VHDL
function "=" (left, right : My_Record) return boolean is begin return (left.field1 [1] right.field1) and (left.field2 = right.field2); end function;
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<>' which means not equal.
Using '>' or '<' which are comparison operators but not equality.
✗ Incorrect
The '=' operator checks if the fields are equal, so use '=' to compare field1.
3fill in blank
hardFix the error in the operator overloading function for '-' by completing the code.
VHDL
function "-" (a, b : integer) return integer is begin return a [1] b; end function;
Attempts:
3 left
💡 Hint
Common Mistakes
Using '+' instead of '-' inside the function.
Using '*' or '/' which are multiplication or division.
✗ Incorrect
The '-' operator function must subtract b from a using '-'.
4fill in blank
hardComplete the code to complete the operator overloading for '*' with custom type Vector.
VHDL
function "*" (v1, v2 : Vector) return Vector is variable result : Vector; begin for i in v1'range loop result(i) := v1(i) [1] v2(i); end loop; return result ;; end function;
Attempts:
3 left
💡 Hint
Common Mistakes
Using '+' or '-' instead of '*' for multiplication.
Missing the semicolon ';' after return statement.
✗ Incorrect
Inside the loop, multiply elements with '*'. The function ends with a semicolon ';'.
5fill in blank
hardFill both blanks to complete the operator overloading for '<' comparing two records.
VHDL
function "<" (a, b : My_Record) return boolean is begin if a.field1 [1] b.field1 then return true ; elsif a.field2 [2] b.field2 then return true; else return false; end if; end function;
Attempts:
3 left
💡 Hint
Common Mistakes
Using '=' instead of comparison operators.
Mixing up '<' and '>' in conditions.
Missing semicolon after return statement.
✗ Incorrect
Use '<' to compare field1, ';' after 'return true', and '>' for field2 comparison.
