![]() |
|
|
|||||||
![]() |
VHDL - error about 'can not have such operands in this context' |
|
|
Thread Tools | Search this Thread |
|
|
#1 |
|
error:" HexImage can not have such operands in this context.
IN mode Formal VALUE of write with no default value must be associated with an actual value. DecImage can not have such operands in this context. IN mode Formal VALUE of write with no default value must be associated with an actual value." <HexImage> and <DecImage> are defined in the package "Image_Pkg." , can transfer 'signed' to 'string'. --=========================================== function HexImage(In_Image : Signed) return String is begin return HexImage(Image(In_Image)); end HexImage; -- function Image(In_Image : Signed) return String is begin return Image(Std_Logic_Vector(In_Image)); end Image; -- function Image(In_Image : Std_Logic_Vector) return String is variable L : Line; -- access type variable W : String(1 to In_Image'length) := (others => ' '); begin IEEE.Std_Logic_TextIO.WRITE(L, In_Image); W(L.all'range) := L.all; Deallocate(L); return W; end Image; --============================================ main program --================================== library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_arith.all; use ieee.std_logic_textio.all; use IEEE.Numeric_Std.all; use std.textio.all; library unisim; use unisim.vcomponents.all; --======================================= library work; use work.complex_pkg.all; use work.Image_Pkg.all; --======================================= entity Complex is end Complex; --======================================= architecture Complex_a of Complex is signal A_s : A2x2C32_Typ; signal B_s : A2x2C32_Typ; begin -- Complex_a Complex_Lbl : process variable A : A2x2C32_Typ := ( 1 => ( R => conv_signed(1,32), I => conv_signed(2,32)), 2 => ( R => conv_signed(3,32), I => conv_signed(4,32)), 3 => ( R => conv_signed(5,32), I => conv_signed(6,32)), 4 => ( R => conv_signed(7,32), I => conv_signed(8,32))); variable B : A2x2C32_Typ := ( 1 => ( R => conv_signed(10,32), I => conv_signed(11,32)), 2 => ( R => conv_signed(12,32), I => conv_signed(13,32)), 3 => ( R => conv_signed(14,32), I => conv_signed(15,32)), 4 => ( R => conv_signed(16,32), I => conv_signed(17,32))); variable L:line; file Result_f :text open write_mode is "result.txt"; --============================================ begin write(L, string'("Multiplication")); Writeline(Result_f, L); write(L, "A.r=" & HexImage(A(1).R) & "A.I=" & HexImage(A(1).I)); writeline(Result_f,L); write(L, "A.r ="& DecImage(A(1).R) & "A.I=" & DecImage(A(1).I)); writeline(Result_f,L); write(L, "B.r=" & HexImage(B(1).R) & "B.I=" & HexImage(B(1).I)); writeline(Result_f,L); write(L, "B.r=" & DecImage(B(1).R) & "B.I ="& DecImage(B(1).I)); writeline(Result_f,L); wait; end process; end Complex_a ; A(1).R/I actually is 'signed', why here has such an error information? pleas help. Zhi |
|
|
|
|
#2 |
|
Posts: n/a
|
Zhi wrote:
> error:" HexImage can not have such operands in this context. > IN mode Formal VALUE of write with no default value must be > associated with an actual value. > DecImage can not have such operands in this context. > IN mode Formal VALUE of write with no default value must be > associated with an actual value." .... > A(1).R/I actually is 'signed', why here has such an error information? > pleas help. Yikes. Here's how I do it. -- Mike Treseler ------------------------------- function uns2hexstr(arg : unsigned) return string is -- Hex table look up -- Note that we want one bit to be one hex digit, so we add 3 to -- the bit length before subtracting the excess -- A recursive function was used to eliminate messy loops ------------------------------------------------------------------------ constant hex_table : string := "0123456789abcdef"; constant max_len : natural := arg'length + 3; constant adj_len : natural := hex_len(arg'length); constant arg_pad_left : natural := abs(adj_len - 1); constant arg_first_rt : natural := abs(adj_len - 4); constant arg_rest_left : natural := abs(adj_len - 5); variable arg_pad : unsigned(arg_pad_left downto 0) := (others => '0'); variable first_digit : unsigned(arg_pad_left downto arg_first_rt); variable the_rest : unsigned(arg_rest_left downto 0); ------------------------------------------------------------------------- begin arg_pad(arg'length -1 downto 0) := arg; -- normalize -- for two or more hex digits we recurse if arg'length > 4 then -- 2 or more digits first_digit := arg_pad(first_digit'range); the_rest := arg_pad(the_rest'range); return hex_table(1 + to_integer(first_digit)) -- first char & uns2hexstr(the_rest); -- & rest of string later, same way -- until "the rest" is zero or one hex digit elsif arg'length = 0 then return ""; else -- one hex digit: returning a char would be a type error return "" & hex_table(1 + to_integer(arg)); -- note that (null string) & (table character) is a string end if; end uns2hexstr; Mike Treseler |
|
|
|
#3 |
|
Posts: n/a
|
Mike Treseler wrote:
> Yikes. Here's how I do it. Oops. You might need this also: function hex_len(arg : natural) return natural is constant max_len : natural := arg + 3; begin -- never need to round up more than 3 return max_len - max_len mod 4; -- trim excess end function hex_len; -- Mike Treseler > ------------------------------- > function uns2hexstr(arg : unsigned) return string is > -- Hex table look up > -- Note that we want one bit to be one hex digit, so we add 3 to > -- the bit length before subtracting the excess > -- A recursive function was used to eliminate messy loops > ------------------------------------------------------------------------ > constant hex_table : string := "0123456789abcdef"; > constant max_len : natural := arg'length + 3; > constant adj_len : natural := hex_len(arg'length); > constant arg_pad_left : natural := abs(adj_len - 1); > constant arg_first_rt : natural := abs(adj_len - 4); > constant arg_rest_left : natural := abs(adj_len - 5); > variable arg_pad : unsigned(arg_pad_left downto 0) := (others => '0'); > variable first_digit : unsigned(arg_pad_left downto arg_first_rt); > variable the_rest : unsigned(arg_rest_left downto 0); > ------------------------------------------------------------------------- > begin > arg_pad(arg'length -1 downto 0) := arg; -- normalize > -- for two or more hex digits we recurse > if arg'length > 4 then -- 2 or more digits > first_digit := arg_pad(first_digit'range); > the_rest := arg_pad(the_rest'range); > return hex_table(1 + to_integer(first_digit)) -- first char > & uns2hexstr(the_rest); -- & rest of string later, same way > -- until "the rest" is zero or one hex digit > elsif arg'length = 0 then return ""; > else > -- one hex digit: returning a char would be a type error > return "" & hex_table(1 + to_integer(arg)); > -- note that (null string) & (table character) is a string > end if; > end uns2hexstr; Mike Treseler |
|
|
|
#4 |
|
Posts: n/a
|
It might a little bit misunderstood.
--======================================-------- function HexImage(In_Image : Signed) return String is begin return HexImage(Image(In_Image)); end HexImage; -- function Image(In_Image : Signed) return String is begin return Image(Std_Logic_Vector(In_Image)); end Image; -- function Image(In_Image : Std_Logic_Vector) return String is variable L : Line; -- access type variable W : String(1 to In_Image'length) := (others => ' '); begin IEEE.Std_Logic_TextIO.WRITE(L, In_Image); W(L.all'range) := L.all; Deallocate(L); return W; end Image; Here is one: function HexImage(InStrg : String) return String is subtype Int03_Typ is Integer range 0 to 3; variable Result : string(1 to ((InStrg'length - 1)/4)+1) := (others => '0'); variable StrTo4 : string(1 to Result'length * 4) := (others => '0'); variable MTspace : Int03_Typ; -- Empty space to fill in variable Str4 : String(1 to 4); variable Group_v : Natural := 0; begin MTspace := Result'length * 4 - InStrg'length; StrTo4(MTspace + 1 to StrTo4'length) := InStrg; -- padded with '0' Cnvrt_Lbl : for I in Result'range loop Group_v := Group_v + 4; -- identifies end of bit # in a group of 4 Str4 := StrTo4(Group_v - 3 to Group_v); -- get next 4 characters case Str4 is when "0000" => Result(I) := '0'; when "0001" => Result(I) := '1'; when "0010" => Result(I) := '2'; when "0011" => Result(I) := '3'; when "0100" => Result(I) := '4'; when "0101" => Result(I) := '5'; when "0110" => Result(I) := '6'; when "0111" => Result(I) := '7'; when "1000" => Result(I) := '8'; when "1001" => Result(I) := '9'; when "1010" => Result(I) := 'A'; when "1011" => Result(I) := 'B'; when "1100" => Result(I) := 'C'; when "1101" => Result(I) := 'D'; when "1110" => Result(I) := 'E'; when "1111" => Result(I) := 'F'; when "ZZZZ" => Result(I) := 'Z'; when others => Result(I) := 'X'; end case; end loop Cnvrt_Lbl; --================================================== =============== Actually I want 32 signed bit->8 bits string. As in the main program: -================================================== ================== write(L, "A.r=" & HexImage(A(1).R) & "A.I=" & HexImage(A(1).I)); writeline(Result_f,L); -- ================================================== ===================== On 25 Feb, 15:30, Mike Treseler <mike_trese...@comcast.net> wrote: > Mike Treseler wrote: > > Yikes. Here's how I do it. > > Oops. You might need this also: > > * *function hex_len(arg : natural) > * * * return natural is > * * * constant max_len : natural := arg + 3; > * *begin * *-- never need to round up more than 3 > * * * return *max_len - max_len mod 4; *-- trim excess > * *end function hex_len; > > * * * * * * * -- Mike Treseler > > > > > ------------------------------- > > function uns2hexstr(arg : unsigned) return string is > > -- Hex table look up > > -- Note that we want one bit to be one hex digit, so we add 3 to > > -- the bit length before subtracting the excess > > -- A recursive function was used to eliminate messy loops > > ------------------------------------------------------------------------ > > * constant hex_table * * *: string *:= "0123456789abcdef"; > > * constant max_len * * * *: natural := arg'length + 3; > > * constant adj_len * * * *: natural := hex_len(arg'length); > > * constant arg_pad_left * : natural := abs(adj_len - 1); > > * constant arg_first_rt * : natural := abs(adj_len - 4); > > * constant arg_rest_left *: natural := abs(adj_len - 5); > > * variable arg_pad : unsigned(arg_pad_left downto 0) := (others => '0'); > > * variable first_digit : unsigned(arg_pad_left downto arg_first_rt); > > * variable the_rest * *: unsigned(arg_rest_left downto 0); > > ------------------------------------------------------------------------- > > * *begin > > * * * arg_pad(arg'length -1 downto 0) := arg; *-- normalize > > * * * -- for two or more hex digits we recurse > > * * * if arg'length > 4 then * * * * * *-- 2 or more digits > > * * * * *first_digit := arg_pad(first_digit'range); > > * * * * *the_rest * *:= arg_pad(the_rest'range); > > * * * * *return hex_table(1 + to_integer(first_digit)) *-- first char > > * * * * * * & uns2hexstr(the_rest); -- & rest of string later, same way > > * * * * *-- until "the rest" is zero or one hex digit > > * * * elsif arg'length = 0 then return ""; > > * * * else > > * * * * *-- one hex digit: returning a char would be a type error > > * * * * *return "" & hex_table(1 + to_integer(arg)); > > * * * * *-- note that (null string) & (table character) is a string > > * * * end if; > > * *end uns2hexstr;- Hide quoted text - > > - Show quoted text - Zhi |
|
![]() |
| Thread Tools | Search this Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| please help: simple java coding error 'cannot be referenced from a static context' | clm90 | General Help Related Topics | 0 | 10-17-2009 06:49 AM |
| example of Server.Transfer and Context Handler | hanusoft | Software | 0 | 09-22-2007 07:44 AM |