文章目录

  • 文件打开关闭
  • 文件输出
  • 文件读入
    • load memory
  • 格式化

文件打开关闭

integer file_descriptor = $("file_name", type);
$fclose(file_desriptor);

type 类型
“r” or “rb” - open for reading(读)
“w” or “wb” - truncate to zero length or create for writing (覆盖写)
“a” or “ab” - append, open for writing at the end of file, or create for writing(续写)
以上“b”用来区分二进制文件和其它文本文件,在Linux平台上,无需区分,windows需要区分。

文件输出

file_output_task_name(file_descriptor, list_of_arguments);
file_output_task_name includes
$fdisplay | $fdisplayb | $fdisplayh | $fdisplayo
| $fwrite | $fwriteb | $fwriteh | $fwriteo
| $fstrobe | $fstrobeb | $fstrobeh | $fstrobeo
| $fmonitor | $fmonitorb | $fmonitorh | $fmonitoro

list_arguments can be a quoted string, an expression that returns a value, or a null argument

$fdisplay 与 $fwrite 函数的区别在于 $display 函数会自动换行, $fwrite不会。

文件读入

integer code = $fscanf (file_descriptor, format, args);
integer code = $fread( myreg, fd);
integer code = $fread( mem, fd);
integer code = $fread( mem, fd, start);
integer code = $fread( mem, fd, start, count);
integer code = $fread( mem, fd, , count);

$fscanf是将文件按照某个模板格式进行扫描,并将扫描结果存放到args中。第一个参数是扫描对象,第二个参数是扫描格式,第三个参数是存放结果的变量。
扫描格式有
%b - matches a binary number
%o - matches a octal number
%d - matches a decimal number
%h -matches a hexadecimal number
%s - matches a string, which is a sequence of non white space characters

load memory

$readmemb ("file_name", memory_name, start_addr, end_addr);
eg.
initial $readmemh("mem.data", mem);
initial $readmemh("mem.data", mem, 16);
initial $readmemh("mem.data", mem, 128, 1);

格式化

$sformat (str, format, args)
integer code = $sformatf(format, args)

$sformat则是将参数args按format格式赋值给str。
$sformatf 和 $sformat 的不同在于 $sformat 没有返回值,而 $sformatf有返回值,返回值就相当于 $sformat的str参数。

Verilog之文件操作相关推荐

  1. Verilog中常见文件操作($readmemb,$fopen,$fwrite,$fclose)

    目录 一.$readmemb/$readmemh 二.$fopen,$fwrite,$fclose 三.仿真验证 四.参考 一.$readmemb/$readmemh $readmemb和$readm ...

  2. 7.2 Verilog 文件操作

    Verilog提供了很多可以对文件进行操作的系统任务.经常使用的系统任务主要包括: 文件开.闭:$fopen, $fclose, $ferror 文件写入:$fdisplay, $fwrite, $f ...

  3. C++核心编程(四)--文件操作

    5 文件操作 程序运行时产生的数据都属于临时数据,程序一点运行结束,就会被释放 通过文件可以将数据持久化 C++中对文件操作需要包含头文件:fstream 文件类型分为两种: 文本文件:文件以文本的A ...

  4. python codecs.open()及文件操作-文本处理 with open

    20210810 以二进制并追加的形式写入文件 20210731 f.write('\n') 换行写入 20210625 https://blog.csdn.net/a543402496/articl ...

  5. day07-字符编码、文件操作

    目录: 字符编码 文件处理 一.字符编码: #1. 什么是字符编码:将人识别的字符转换计算机能识别的01,转换的规则就是字符编码表 #2. 常用的编码表:ascii.unicode.GBK.Shift ...

  6. HTML5 本地文件操作之FileSystemAPI整理(二)

    一.文件目录操作 1.DirectoryEntry对象 属性: 1.isFile: 操作对象的是否为文件,DirectoryEntry对象固定其值为false 2.isDirectory: 操作对象是 ...

  7. python3 转码的函数_python基础3之文件操作、字符编码解码、函数介绍

    内容概要: 一.文件操作 二.字符编码解码 三.函数介绍 一.文件操作 文件操作流程: 打开文件,得到文件句柄并赋值给一个变量 通过句柄对文件进行操作 关闭文件 基本操作: 1 #/usr/bin/e ...

  8. linux文件编辑操作,Linux下文本编辑及其文件操作

    文本编辑及其文件操作 Vim 命令模式: dd 删除当前行 yy 2yy nyy 复制 从光标算起,复制n行 p 粘贴 默认粘贴在光标的下一行 u 撤销 末行模式: :wq 保存退出 :wq! 强制保 ...

  9. c++:文件操作1 文件的打开

    在程序中,要使用一个文件,先要打开文件后才能读写,读写完后要关闭.创建一个新文件也要先执行打开(open)操作,然后才能往文件中写入数据.C++ 文件流类有相应的成员函数来实现打开.读.写.关闭等文件 ...

最新文章

  1. 动态标题_动态打印区域和打印标题
  2. DEV—【GridControl添加按钮列】
  3. 微服务架构下,解决数据一致性问题的实践
  4. LiveVideoStackCon 2021上海站 倒数计时:2
  5. 基于SOUI开发的应用展示
  6. python3与MySQL交互
  7. Vue学习笔记--Vue双向绑定实现原理
  8. mysql查询有数据但返回null_Mybatis查不到数据查询返回Null问题
  9. python空集合_python空集合
  10. 继苏宁京东后 拼多多也宣布下调新款iPhone售价
  11. win11安装报错0xc1900101怎么办 Windows11安装报错0xc1900101的解决方法
  12. php7 返回静态类,PHP7 – 未捕获错误:访问未声明的静态属性
  13. 栈(后缀表达式的理想数据结构)
  14. 康蒂尼药业再次冲刺港股:9个月营收4.4亿 龙磐创投是股东
  15. Java 对一组时间进行处理 提出连续的时间段
  16. EasyNLP玩转文本摘要(新闻标题)生成
  17. 【inline、inline-block间的空隙】
  18. 武田以3.22亿美元剥离中国大陆非核心业务至海森
  19. 腾讯地图实时精准定位
  20. kali WiFi密码破解分享

热门文章

  1. Cygwin环境的搭建
  2. 虚表 http://www.cnblogs.com/dsky/archive/2012/02/07/2340984.html
  3. Vitamio 的导入与简单使用
  4. Ubuntu20.04 server 安装iSCSI
  5. 对固定资产折旧及其折旧方法的探讨
  6. 【文本挖掘】业绩预告原因·其一
  7. ZIP暴力破解脚本[多线程]
  8. jsp(html)页面中引入日历
  9. MySQL中存储过程使用详解
  10. 读-《c++设计新思维-泛型编程与设计模式之应用》经典记录(英文书名:《modern c++ design》)