Giter Club home page Giter Club logo

test's Introduction

结构化数字设计文件操作

题目要求

随机产生一组数值(十个),将该组数写入一个文本文件(命名为file1.txt),同时将本人的学号和姓名也写进生成的该文件中。写出代码和调试过程,并截图生成的文件界面。

题目实现

  1. 实现思路:

    首先使用系统任务 $random() 产生随机数。使用整型变量 seed 来确保每次运行测试时生成同样的随机数序列。使用参数 MAXMIN 来限定随机数的范围。然后在工程目录创建空白文件 file1.txt,然后打开该文件,循环写入生成的随机数到文件中,最后写入姓名和学号。最后关闭文件。

  2. 源代码:

    module file_write;
    
       parameter    MAX = 100;
       parameter    MIN = 0;
       reg [31:0]   num_range;
       integer      seed = 4;
       integer      i = 0;
       integer      file_handle;
    
       initial
       begin
    
        file_handle = $fopen("file1.txt");
    
        for (i = 0; i <= 10; i = i+1) 
        begin
            num_range = MIN + {$random(seed)} % (MAX-MIN+1);
            $fdisplay(file_handle,"%d",$signed(num_range));
        end
    
        
        $fclose(file_handle);
       end
    
    
    
    endmodule
  3. 实验结果:

    编译上述代码,然后在 modelsim 仿真界面使用 run -all 指令,然后打开工程目录下提前建立好的 file1.txt 文件,观察文件内容。

test's People

Watchers

Y006 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.