⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ambatest.vhd

📁 free hardware ip core about sparcv8,a soc cpu in vhdl
💻 VHD
📖 第 1 页 / 共 2 页
字号:
    end loop;  when others => stmp := (others => ' ');  end case;  str2(1 to 8) := stmp(8 downto 1);  for i in 1 to 8 loop    str1(i) := str2(9-i);  end loop;  return(str1);end printhex;function to_char( x : INTEGER range 0 to 15) return character is begin  case x is    when 0 => return('0');    when 1 => return('1');    when 2 => return('2');    when 3 => return('3');    when 4 => return('4');    when 5 => return('5');    when 6 => return('6');    when 7 => return('7');    when 8 => return('8');    when 9 => return('9');    when 10 => return('A');    when 11 => return('B');    when 12 => return('C');    when 13 => return('D');    when 14 => return('E');    when 15 => return('F');  end case;end to_char;function conv_std_logic_vector(value : string; len : integer) return std_logic_vector is  variable tmpvect : std_logic_vector(31 downto 0);  variable str1,str2 : string(1 to 8);  begin    str1 := value;    for i in 1 to (len/4) loop      str2(i) := str1(((len/4)+1)-i);    end loop;    case len is    when 4 | 8 | 12 | 16 | 20 | 24 | 28 | 32 =>      for i in 0 to 7 loop        case str2(i+1) is        when '0' => tmpvect(((i*4)+3) downto (i*4)) := "0000";        when '1' => tmpvect(((i*4)+3) downto (i*4)) := "0001";        when '2' => tmpvect(((i*4)+3) downto (i*4)) := "0010";        when '3' => tmpvect(((i*4)+3) downto (i*4)) := "0011";        when '4' => tmpvect(((i*4)+3) downto (i*4)) := "0100";        when '5' => tmpvect(((i*4)+3) downto (i*4)) := "0101";        when '6' => tmpvect(((i*4)+3) downto (i*4)) := "0110";        when '7' => tmpvect(((i*4)+3) downto (i*4)) := "0111";        when '8' => tmpvect(((i*4)+3) downto (i*4)) := "1000";        when '9' => tmpvect(((i*4)+3) downto (i*4)) := "1001";        when 'A' => tmpvect(((i*4)+3) downto (i*4)) := "1010";        when 'B' => tmpvect(((i*4)+3) downto (i*4)) := "1011";        when 'C' => tmpvect(((i*4)+3) downto (i*4)) := "1100";        when 'D' => tmpvect(((i*4)+3) downto (i*4)) := "1101";        when 'E' => tmpvect(((i*4)+3) downto (i*4)) := "1110";        when 'F' => tmpvect(((i*4)+3) downto (i*4)) := "1111";        when others => tmpvect(((i*4)+3) downto (i*4)) := "0000";        end case;      end loop;    when others => tmpvect := (others => '0');    end case;    return(tmpvect(len-1 downto 0));end conv_std_logic_vector;procedure printf(  str : string) is  variable lenstr,offset,i : integer;  variable rstr : string(1 to 128);  variable L : line;  begin    lenstr := str'length; offset := 1; i := 1;    while i <= lenstr loop      rstr(offset) := str(i); offset := offset+1; i := i+1;    end loop;    rstr(offset+1) := NUL;    write(L,rstr);    writeline(output,L);end procedure;procedure printf(  str : string;  vari : integer) is  variable lenstr,offset,i,j,x,y,z : integer;  variable rstr : string(1 to 128);  variable tmpstr : string(1 to 8);  variable remzer : boolean;  variable L : line;  begin    lenstr := str'length; offset := 1; i := 1; x := vari;    while i <= lenstr loop      if str(i) = '%' then        if vari = 0 then          rstr(offset) := '0'; offset := offset+1;        else          if vari = 0 then tmpstr := (others => '0');          else            j := 8;            l2: while true loop              j := j-1;              exit l2 when j = 0;              y := x/10;              z := x - y*10;              x := y;              tmpstr(j) := to_char(z);            end loop;            if x>0 then printf("Value is out of range"); end if;          end if;--          tmpstr := printhex(conv_std_logic_vector(vari,32),32);          remzer := false;          for k in 1 to 8 loop            if (tmpstr(k) /= '0' or remzer = true) then              rstr(offset) := tmpstr(k); remzer := true; offset := offset+1;            end if;          end loop;        end if;        i := i+2;      else        rstr(offset) := str(i); offset := offset+1; i := i+1;      end if;    end loop;    rstr(offset+1) := NUL;    write(L,rstr);    writeline(output,L);end procedure;procedure printf(  str : string;  vari : std_logic_vector) is  constant zero32 : std_logic_vector(31 downto 0) := (others => '0');  variable lenstr,lenvct,offset,i : integer;  variable rstr : string(1 to 128);  variable tmpstr : string(1 to 8);  variable L : line;  begin    lenstr := str'length; offset := 1;    lenvct := vari'length; i := 1;    while i <= lenstr loop      if str(i) = '%' then        if vari = zero32(lenvct-1 downto 0) then          rstr(offset) := '0'; offset := offset+1;        else          tmpstr := printhex(vari,lenvct);          for j in 1 to 8 loop              rstr(offset) := tmpstr(j); offset := offset+1;          end loop;        end if;        i := i+2;      else        rstr(offset) := str(i); offset := offset+1; i := i+1;      end if;    end loop;    rstr(offset+1) := NUL;    write(L,rstr);    writeline(output,L);end procedure;function trimlen(str : string) return integer is  variable lenstr,i : integer;  begin    lenstr := str'length; i := 1;    while str(lenstr) /= ' ' loop      i := i+1 ; lenstr := lenstr-1;    end loop;    return(lenstr+1);end function;procedure printf(  str : string;  vari : string) is  variable lenstr,lenvct,offset,i : integer;  variable rstr : string(1 to 128);  variable L : line;  begin    lenstr := str'length; offset := 1;    lenvct := vari'length; i := 1;    while i <= lenstr loop      if str(i) = '%' then        for j in 1 to lenvct loop            rstr(offset) := vari(j); offset := offset+1;        end loop;        i := i+2;      else        rstr(offset) := str(i); offset := offset+1; i := i+1;      end if;    end loop;    rstr(offset+1) := NUL;    write(L,rstr);    writeline(output,L);end procedure;procedure compfiles(  file1 : string(18 downto 1);  file2 : string(18 downto 1);  format : integer) is  file comp1, comp2 : text;  variable L1, L2 : line;  variable datahex1, datahex2 : string(1 to 8);  variable dataint1, dataint2, pos, errs : integer;  begin    pos := 0; errs := 0;    file_open(comp1, external_name => file1(18 downto trimlen(file1)), open_kind => read_mode);    file_open(comp2, external_name => file2(18 downto trimlen(file2)), open_kind => read_mode);    readline(comp1,L1);    readline(comp2,L2);    pos := pos+1;    if format = 0 then      read(L1,dataint1);      read(L2,dataint2);      if dataint1 /= dataint2 then        errs := errs+1;        printf("Comparision error at pos. %d",pos);        printf("Expected data: %d",dataint1);        printf("Compared data: %d",dataint2);      end if;    elsif format = 1 then      read(L1,datahex1);      read(L2,datahex2);      if conv_std_logic_vector(datahex1,32) /= conv_std_logic_vector(datahex2,32) then        errs := errs+1;        printf("Comparision error at pos. %d",pos);        printf("Expected data: %x",datahex1);        printf("Compared data: %x",datahex2);      end if;    end if;    while not (endfile(comp1) or endfile(comp2)) loop      readline(comp1,L1);      readline(comp2,L2);      pos := pos+1;      if format = 0 then        read(L1,dataint1);        read(L2,dataint2);        if dataint1 /= dataint2 then          errs := errs+1;          printf("Comparision error at pos. %d",pos);          printf("Expected data: %d",dataint1);          printf("Compared data: %d",dataint2);        end if;      elsif format = 1 then        read(L1,datahex1);        read(L2,datahex2);        if conv_std_logic_vector(datahex1,32) /= conv_std_logic_vector(datahex2,32) then          errs := errs+1;          printf("Comparision error at pos. %d",pos);          printf("Expected data: %x",datahex1);          printf("Compared data: %x",datahex2);        end if;      end if;    end loop;    if endfile(comp1) /= endfile(comp2) then      printf("Compared files have different size!"); errs := errs+1;    end if;    file_close(comp1); file_close(comp2);    if errs = 0 then      printf("Comparision complete. No failure.");    elsif errs = 1 then      printf("Comparision complete. 1 failure.");    else      printf("Comparision complete. %d failures.",errs);    end if;end procedure;end ambatest;-- pragma translate_on

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -