资源描述:
《verilog中文件输入与输出任务实例解析》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、Ver订og中文件输入与输出任务实例解析1.fileopenandclose:firstdefinetheintegerpointer,thencallthe$fopen(filename,mode)task,andcall$fopen(file_name)whenthefileisnotneededCommonlyusedmodeincludeopenthefileandstartwritingfromthefileheader,andcreateafileifitdoesn'talreadyexist・〃W+〃openthefileandstartreadingan
2、dwritingfromthefileheader・Createafileifitdoesn,talreadyexistopensthefileandstartswritingfromtheendofthefile.Ifitdoesnotexist,createthefile〃A+〃openthefileandstartreadingandwritingfromtheendofthefile・Createafileifitdoesn'talreadyexist2.outputtothefile:displaytaskbeforeaddingF,callformat:$f
3、display(filepointer,displaycontent,displayvariables),again$fmonitor.・・)Inadditiontomorethanonefilepointer,othertasksthatareoutputintheconsoleareconsistentwiththemethod・3.readfromfile:3tasks$readmemb(filename),storagecell,thestartingaddressofthestoragecellinthefile,theendaddressofthememor
4、ycellwillbestoredinthefileThetextfilecancontainspaces,linebreaks,tabs,annotations,andbinary.Inthefollowingexample,thereisameomoryb.txttextfileintheprojectfolderdirectory,whichreadsasfollows:1010110100011101,01101111011000010000000111111110,1111111111101110Thisfilemeetstherequirementsandc
5、anbereadthroughthe$readmemb・10101101thefirstdataaddressis0,backwards,andsoon.Anothersystemtask,thedifferencebetweenSreadmemhandSreadmemb,istoidentifythesixteenhexadecima1.Inthefollowingexample,thereisameomoryh・txttextfileintheprojectfolderdirectory,whichreadsasfollows:EFAB3E4FGiveanexamp
6、le:Modulereadmem;Reg[7:0]mem[7:0]:Reg[2:0]i;Integerfile;InitialBeginFile二$fopen("memory.txt〃,〃W〃);Sreadmemb(memoryb・txt,MEM,4,0);//towritetexttoreaddatafromthemem[4],untilmem[0]wroteFor(I=0;i<7;i+1;i二)BeginSdisplay(^mem[%d]=%b〃,〃);Sfdisplay(file,mem[%d]=%b,I,mem[i]);End$readmemh(memoryh・
7、txt,MEM);//ifnoaddressrestrictionsondefaultfrom//mem[0]toaddressthedefinitionofmem・For(I=0;i<7;i+1;i二)BeginSdisplay(〃meni[%d]=%h〃,T:〃meni[i]〃);Sfdisplay(file,mem[%d]=%h,I,mem[i]);EndSfclose(file);EndEndmoduleTheconsoleoutputisconsistentwiththecontentinthegeneratedmemory.t