SlideShare une entreprise Scribd logo
1  sur  10
--------------------------------------------------------------------------<br />-- Download and rename the file to auxiliary.vhd<br />-- AUB<br />-- EECE 321 - Computer Organization, Spring 2009<br />-- Author: M. M.<br />--------------------------------------------------------------------------<br />-- Description: Auxiliary package including user-defined functions<br />--------------------------------------------------------------------------<br />library ieee;<br />use ieee.std_logic_1164.all;<br />use ieee.std_logic_unsigned.all;<br />use ieee.std_logic_arith.all;<br />use ieee.std_logic_misc.all;<br />USE ieee.std_logic_textio.all;<br />USE std.textio.all;<br />-- ---------------------------------------------------------------------------------<br />-- NOTES:<br />-- ---------------------------------------------------------------------------------<br />-- To convert STD_LOGIC_VECTOR to INTEGER, use the built-in function quot;
conv_integerquot;
<br />-- CONV_INTEGER(ARG: STD_LOGIC_VECTOR) return INTEGER;<br />-- Ex: if x is a STD_LOGIC_VECTOR, then<br />--     y := conv_integer(x) converts x to unsigned integer<br />-- ---------------------------------------------------------------------------------<br />--<br />-- To convert from INTEGER to STD_LOGIC_VECTOR, use the built-in function quot;
conv_std_logic_vectorquot;
<br />-- CONV_STD_LOGIC_VECTOR(ARG: INTEGER; SIZE: INTEGER) return STD_LOGIC_VECTOR;<br />-- Ex: if y is an integer, then<br />--     x := conv_std_logic_vector(y,4) converts the integer y into a std_logic_vector of width 4<br />-- ---------------------------------------------------------------------------------<br />--<br />-- declare functions and data types here<br />package auxiliary is<br />----------------------------------------------------------------------------------<br />  --  CONSTANTS<br />  ----------------------------------------------------------------------------------<br />CONSTANT MIPS_WORD_SIZE_IN_BYTES : NATURAL := 4;<br />----------------------------------------------------------------------------------<br />  --  DATA TYPES<br />  ----------------------------------------------------------------------------------<br />SUBTYPE MIPS_WORD is STD_LOGIC_VECTOR(MIPS_WORD_SIZE_IN_BYTES * 8 - 1 DOWNTO 0);<br />TYPE MEM_ARRAY is array (INTEGER range <>) of MIPS_WORD;<br />----------------------------------------------------------------------------------<br />  --  USER-DEFINED FUNCTIONS AND PROCEDURES<br />  ----------------------------------------------------------------------------------<br />PROCEDURE read_hex_2_natural(L: INOUT LINE; width: IN NATURAL; natnum : OUT NATURAL);<br />PROCEDURE read_hex_2_word(L: INOUT LINE; width: IN NATURAL; WORD : OUT STD_LOGIC_VECTOR);<br />PROCEDURE init_mem(fname : IN STRING; mem : OUT MEM_ARRAY);<br />PROCEDURE copy_mem_2_file(fname : IN STRING; mem : IN MEM_ARRAY);<br />FUNCTION load_word(mem : IN MEM_ARRAY; byte_addr : IN NATURAL) RETURN MIPS_WORD;<br />PROCEDURE store_word(mem : OUT MEM_ARRAY; word : MIPS_WORD;  byte_addr : IN NATURAL);<br />-- add your functions below ...<br />end auxiliary;<br />package body auxiliary is<br />----------------------------------------------------------------<br />-- Read a hexadecimal string and converts it to a natural number<br />----------------------------------------------------------------<br />PROCEDURE read_hex_2_natural(L: INOUT LINE; width: IN NATURAL; natnum : OUT NATURAL) IS<br />VARIABLE result : NATURAL := 0;<br />VARIABLE ch : CHARACTER;<br />BEGIN<br />FOR i in 1 to width LOOP<br />read(L,ch);<br />IF '0' <= ch AND ch <= '9' THEN<br />result := result*16 + character'pos(ch) - character'pos('0');<br />ELSIF 'A' <= ch AND ch <= 'F' THEN<br />result := result*16 + character'pos(ch) - character'pos('A') + 10;<br />ELSIF 'a' <= ch AND ch <= 'f' THEN<br />result := result*16 + character'pos(ch) - character'pos('a') + 10;<br />ELSE<br />report quot;
Format error in input file. Line quot;
 & integer'image(i) & quot;
. quot;
 severity failure;<br />END IF; <br />END LOOP;<br />natnum := result;<br />END read_hex_2_natural;<br />----------------------------------------------------------------<br />-- Read a hexadecimal string and converts it to a STD_LOGIC_VECTOR<br />----------------------------------------------------------------<br />PROCEDURE read_hex_2_word(L: INOUT LINE; width: IN NATURAL; WORD : OUT STD_LOGIC_VECTOR) IS<br />VARIABLE digit : NATURAL;<br />VARIABLE r : NATURAL := 0;<br />VARIABLE ch : CHARACTER;<br />BEGIN<br />-- first check if width of 'word' is equal to width<br />IF width /= (WORD'length)/4 THEN<br />report quot;
Input argument width in function 'read_hex_2_vector' incompatible with output width.quot;
 severity failure;<br />END IF; <br />FOR i in 1 to width LOOP<br />read(L,ch);<br />IF '0' <= ch AND ch <= '9' THEN<br />digit := character'pos(ch) - character'pos('0');<br />ELSIF 'A' <= ch AND ch <= 'F' THEN<br />digit := character'pos(ch) - character'pos('A') + 10;<br />ELSIF 'a' <= ch AND ch <= 'f' THEN<br />digit := character'pos(ch) - character'pos('a') + 10;<br />ELSE<br />report quot;
Format error in input file.quot;
 severity failure;<br />END IF; <br />WORD(31-r DOWNTO 28-r) := conv_std_logic_vector(digit,4);<br />r := r + 4;<br />END LOOP;<br />END read_hex_2_word;<br />----------------------------------------------------------------<br />-- Initializes memory from a file<br />----------------------------------------------------------------<br />PROCEDURE init_mem(fname : IN STRING; mem : OUT MEM_ARRAY) IS<br />FILE binary_file: text;<br />VARIABLE open_status : file_open_status;<br />VARIABLE L: LINE;<br />VARIABLE ch : CHARACTER;<br />VARIABLE  line_number   : NATURAL := 0;<br />VARIABLE  addr   : NATURAL;<br />VARIABLE  word          : MIPS_WORD;<br />BEGIN<br />-- open file<br />file_open(open_status, binary_file, fname, read_mode);<br />-- check status, report error in case something is wrong with input simulation file<br />IF open_status /= open_ok then<br />report file_open_status'image(open_status) & quot;
 WHILE opening file quot;
 & fname<br />      severity failure;   <br />    END IF;<br />-- First, write zeros in all entries<br />FOR i in mem'RANGE LOOP     <br />mem(i) := (OTHERS => '0');<br />END LOOP;<br />-- Fill entries of memory from the input file<br />WHILE NOT endfile(binary_file) LOOP<br />readline(binary_file, L);<br />line_number := line_number + 1;<br />read_hex_2_natural(L,8,addr);<br />read(L,ch); -- space between address and data<br />read_hex_2_word(L,8,word);<br />mem(addr/4) := word;<br />END LOOP;<br />    <br />END init_mem;<br />----------------------------------------------------------------<br />-- Copies the contents of memory into a file<br />----------------------------------------------------------------<br />PROCEDURE copy_mem_2_file(fname : IN STRING; mem : IN MEM_ARRAY) IS<br />FILE binary_file: text;<br />VARIABLE open_status : file_open_status;<br />VARIABLE L: LINE;<br />VARIABLE  line_number   : NATURAL := 0;<br />VARIABLE  addr   : MIPS_WORD;<br />VARIABLE  word          : MIPS_WORD;<br />VARIABLE  nibble        : STD_LOGIC_VECTOR(3 DOWNTO 0);<br />BEGIN<br />-- open file<br />file_open(open_status, binary_file, fname, write_mode);<br />-- check status, report error in case something is wrong with input simulation file<br />IF open_status /= open_ok then<br />report file_open_status'image(open_status) & quot;
 WHILE opening file quot;
 & fname<br />      severity failure;   <br />    END IF;<br />-- Fill entries of memory from the input file<br />FOR j in mem'range LOOP<br />-- assemble address field in hexadecimal<br />addr := conv_std_logic_vector(4*line_number,addr'length);<br />for i in 0 to 7 loop<br />nibble := addr(31-4*i downto 28-4*i); <br />hwrite(L,nibble,FIELD=>1,JUSTIFIED=>left);<br />end loop;<br />-- fill space<br />write(L,STRING'(quot;
 quot;
));<br />-- assemble data field in hexadecimal<br />word := mem(line_number);<br />for i in 0 to 7 loop<br />nibble := word(31-4*i downto 28-4*i);<br />hwrite(L,nibble,FIELD=>1,JUSTIFIED=>left);<br />end loop;<br />-- advance line number<br />line_number := line_number + 1;<br />-- print line to output file<br />writeline(binary_file,L);<br />END LOOP;<br />    <br />END copy_mem_2_file;<br />----------------------------------------------------------------<br />-- Loads a word from memory (address is byte address)<br />----------------------------------------------------------------<br />FUNCTION load_word(mem : IN MEM_ARRAY; byte_addr : IN NATURAL) RETURN MIPS_WORD IS<br />VARIABLE  word  : MIPS_WORD;<br />BEGIN<br />-- check byte address falls in memory range or is a multiple of the number of bytes within a word<br />IF (byte_addr < 0) OR <br />(byte_addr >= MIPS_WORD_SIZE_IN_BYTES * mem'length) OR<br />(byte_addr mod MIPS_WORD_SIZE_IN_BYTES /= 0)THEN<br />report quot;
 Invalid byte address in function 'load_word': quot;
 & integer'image(byte_addr)<br />      severity failure;   <br />    END IF; <br />word := mem(byte_addr/4);  <br />return word;<br />    <br />END load_word;<br />----------------------------------------------------------------<br />-- Stores a word into memory (address is byte address)<br />----------------------------------------------------------------<br />PROCEDURE store_word(mem : OUT MEM_ARRAY; word : MIPS_WORD;  byte_addr : IN NATURAL) IS<br />BEGIN<br />-- check byte address falls in memory range or is a multiple of the number of bytes within a word<br />IF (byte_addr < 0) OR <br />(byte_addr >= MIPS_WORD_SIZE_IN_BYTES * mem'length) OR<br />(byte_addr mod MIPS_WORD_SIZE_IN_BYTES /= 0)THEN<br />report quot;
 Invalid byte address in function 'store_word': quot;
 & integer'image(byte_addr)<br />      severity failure;   <br />    END IF; <br />mem(byte_addr/4) := word;  <br />END store_word;<br />END auxiliary;<br />
Auxiliary package for MIPS memory functions
Auxiliary package for MIPS memory functions
Auxiliary package for MIPS memory functions
Auxiliary package for MIPS memory functions
Auxiliary package for MIPS memory functions
Auxiliary package for MIPS memory functions
Auxiliary package for MIPS memory functions
Auxiliary package for MIPS memory functions
Auxiliary package for MIPS memory functions

Contenu connexe

Tendances

Learning sed and awk
Learning sed and awkLearning sed and awk
Learning sed and awkYogesh Sawant
 
Advanced perl finer points ,pack&amp;unpack,eval,files
Advanced perl   finer points ,pack&amp;unpack,eval,filesAdvanced perl   finer points ,pack&amp;unpack,eval,files
Advanced perl finer points ,pack&amp;unpack,eval,filesShankar D
 
Raspberry pi Part 25
Raspberry pi Part 25Raspberry pi Part 25
Raspberry pi Part 25Techvilla
 
Perl6 for-beginners
Perl6 for-beginnersPerl6 for-beginners
Perl6 for-beginnersJens Rehsack
 
CyberLink LabelPrint 2.5 Exploitation Process
CyberLink LabelPrint 2.5 Exploitation ProcessCyberLink LabelPrint 2.5 Exploitation Process
CyberLink LabelPrint 2.5 Exploitation ProcessThomas Gregory
 
Implementing Software Machines in Go and C
Implementing Software Machines in Go and CImplementing Software Machines in Go and C
Implementing Software Machines in Go and CEleanor McHugh
 
Python and sysadmin I
Python and sysadmin IPython and sysadmin I
Python and sysadmin IGuixing Bai
 
Argparse: Python command line parser
Argparse: Python command line parserArgparse: Python command line parser
Argparse: Python command line parserTimo Stollenwerk
 
Exploit Development: EzServer Buffer Overflow oleh Tom Gregory
Exploit Development: EzServer Buffer Overflow oleh Tom GregoryExploit Development: EzServer Buffer Overflow oleh Tom Gregory
Exploit Development: EzServer Buffer Overflow oleh Tom Gregoryzakiakhmad
 
32 shell-programming
32 shell-programming32 shell-programming
32 shell-programmingkayalkarnan
 
101 3.1 gnu and unix commands v4
101 3.1 gnu and unix commands v4101 3.1 gnu and unix commands v4
101 3.1 gnu and unix commands v4Acácio Oliveira
 
3.1 gnu and unix commands v4
3.1 gnu and unix commands v43.1 gnu and unix commands v4
3.1 gnu and unix commands v4Acácio Oliveira
 

Tendances (20)

Learning sed and awk
Learning sed and awkLearning sed and awk
Learning sed and awk
 
Advanced perl finer points ,pack&amp;unpack,eval,files
Advanced perl   finer points ,pack&amp;unpack,eval,filesAdvanced perl   finer points ,pack&amp;unpack,eval,files
Advanced perl finer points ,pack&amp;unpack,eval,files
 
Unit v
Unit vUnit v
Unit v
 
Raspberry pi Part 25
Raspberry pi Part 25Raspberry pi Part 25
Raspberry pi Part 25
 
Perl6 for-beginners
Perl6 for-beginnersPerl6 for-beginners
Perl6 for-beginners
 
Sp ch05
Sp ch05Sp ch05
Sp ch05
 
CyberLink LabelPrint 2.5 Exploitation Process
CyberLink LabelPrint 2.5 Exploitation ProcessCyberLink LabelPrint 2.5 Exploitation Process
CyberLink LabelPrint 2.5 Exploitation Process
 
Mysql
MysqlMysql
Mysql
 
Implementing Software Machines in Go and C
Implementing Software Machines in Go and CImplementing Software Machines in Go and C
Implementing Software Machines in Go and C
 
Python and sysadmin I
Python and sysadmin IPython and sysadmin I
Python and sysadmin I
 
Foxpro (1)
Foxpro (1)Foxpro (1)
Foxpro (1)
 
Argparse: Python command line parser
Argparse: Python command line parserArgparse: Python command line parser
Argparse: Python command line parser
 
Mips1
Mips1Mips1
Mips1
 
Exploit Development: EzServer Buffer Overflow oleh Tom Gregory
Exploit Development: EzServer Buffer Overflow oleh Tom GregoryExploit Development: EzServer Buffer Overflow oleh Tom Gregory
Exploit Development: EzServer Buffer Overflow oleh Tom Gregory
 
32 shell-programming
32 shell-programming32 shell-programming
32 shell-programming
 
101 3.1 gnu and unix commands v4
101 3.1 gnu and unix commands v4101 3.1 gnu and unix commands v4
101 3.1 gnu and unix commands v4
 
Newdoc maxis
Newdoc maxisNewdoc maxis
Newdoc maxis
 
3.1 gnu and unix commands v4
3.1 gnu and unix commands v43.1 gnu and unix commands v4
3.1 gnu and unix commands v4
 
Unit5
Unit5Unit5
Unit5
 
C Homework Help
C Homework HelpC Homework Help
C Homework Help
 

Similaire à Auxiliary package for MIPS memory functions

Python - Getting to the Essence - Points.com - Dave Park
Python - Getting to the Essence - Points.com - Dave ParkPython - Getting to the Essence - Points.com - Dave Park
Python - Getting to the Essence - Points.com - Dave Parkpointstechgeeks
 
Lab11.cppLab11.cpp.docx
Lab11.cppLab11.cpp.docxLab11.cppLab11.cpp.docx
Lab11.cppLab11.cpp.docxDIPESH30
 
Introduction to Assembly Language
Introduction to Assembly LanguageIntroduction to Assembly Language
Introduction to Assembly LanguageMotaz Saad
 
various tricks for remote linux exploits  by Seok-Ha Lee (wh1ant)
various tricks for remote linux exploits  by Seok-Ha Lee (wh1ant)various tricks for remote linux exploits  by Seok-Ha Lee (wh1ant)
various tricks for remote linux exploits  by Seok-Ha Lee (wh1ant)CODE BLUE
 
perl usage at database applications
perl usage at database applicationsperl usage at database applications
perl usage at database applicationsJoe Jiang
 
Kernel Recipes 2019 - GNU poke, an extensible editor for structured binary data
Kernel Recipes 2019 - GNU poke, an extensible editor for structured binary dataKernel Recipes 2019 - GNU poke, an extensible editor for structured binary data
Kernel Recipes 2019 - GNU poke, an extensible editor for structured binary dataAnne Nicolas
 
file_handling_in_c.ppt
file_handling_in_c.pptfile_handling_in_c.ppt
file_handling_in_c.pptyuvrajkeshri
 
The Ruby On Rails I18n Core Api
The Ruby On Rails I18n Core ApiThe Ruby On Rails I18n Core Api
The Ruby On Rails I18n Core ApiNTT DATA Americas
 
Getting Started with Raspberry Pi - DCC 2013.1
Getting Started with Raspberry Pi - DCC 2013.1Getting Started with Raspberry Pi - DCC 2013.1
Getting Started with Raspberry Pi - DCC 2013.1Tom Paulus
 
Phil Bartie QGIS PLPython
Phil Bartie QGIS PLPythonPhil Bartie QGIS PLPython
Phil Bartie QGIS PLPythonRoss McDonald
 
Lua by Ong Hean Kuan
Lua by Ong Hean KuanLua by Ong Hean Kuan
Lua by Ong Hean Kuanfossmy
 
AWS Hadoop and PIG and overview
AWS Hadoop and PIG and overviewAWS Hadoop and PIG and overview
AWS Hadoop and PIG and overviewDan Morrill
 

Similaire à Auxiliary package for MIPS memory functions (20)

Python - Getting to the Essence - Points.com - Dave Park
Python - Getting to the Essence - Points.com - Dave ParkPython - Getting to the Essence - Points.com - Dave Park
Python - Getting to the Essence - Points.com - Dave Park
 
Lab11.cppLab11.cpp.docx
Lab11.cppLab11.cpp.docxLab11.cppLab11.cpp.docx
Lab11.cppLab11.cpp.docx
 
Introduction to Assembly Language
Introduction to Assembly LanguageIntroduction to Assembly Language
Introduction to Assembly Language
 
C to perl binding
C to perl bindingC to perl binding
C to perl binding
 
IO Streams, Files and Directories
IO Streams, Files and DirectoriesIO Streams, Files and Directories
IO Streams, Files and Directories
 
Program For Parsing2
Program For Parsing2Program For Parsing2
Program For Parsing2
 
various tricks for remote linux exploits  by Seok-Ha Lee (wh1ant)
various tricks for remote linux exploits  by Seok-Ha Lee (wh1ant)various tricks for remote linux exploits  by Seok-Ha Lee (wh1ant)
various tricks for remote linux exploits  by Seok-Ha Lee (wh1ant)
 
perl usage at database applications
perl usage at database applicationsperl usage at database applications
perl usage at database applications
 
Kernel Recipes 2019 - GNU poke, an extensible editor for structured binary data
Kernel Recipes 2019 - GNU poke, an extensible editor for structured binary dataKernel Recipes 2019 - GNU poke, an extensible editor for structured binary data
Kernel Recipes 2019 - GNU poke, an extensible editor for structured binary data
 
file_handling_in_c.ppt
file_handling_in_c.pptfile_handling_in_c.ppt
file_handling_in_c.ppt
 
The Ruby On Rails I18n Core Api
The Ruby On Rails I18n Core ApiThe Ruby On Rails I18n Core Api
The Ruby On Rails I18n Core Api
 
Apache pig
Apache pigApache pig
Apache pig
 
Getting Started with Raspberry Pi - DCC 2013.1
Getting Started with Raspberry Pi - DCC 2013.1Getting Started with Raspberry Pi - DCC 2013.1
Getting Started with Raspberry Pi - DCC 2013.1
 
Phil Bartie QGIS PLPython
Phil Bartie QGIS PLPythonPhil Bartie QGIS PLPython
Phil Bartie QGIS PLPython
 
Lua by Ong Hean Kuan
Lua by Ong Hean KuanLua by Ong Hean Kuan
Lua by Ong Hean Kuan
 
Having Fun Programming!
Having Fun Programming!Having Fun Programming!
Having Fun Programming!
 
AWS Hadoop and PIG and overview
AWS Hadoop and PIG and overviewAWS Hadoop and PIG and overview
AWS Hadoop and PIG and overview
 
About Go
About GoAbout Go
About Go
 
Perl Presentation
Perl PresentationPerl Presentation
Perl Presentation
 
Python build your security tools.pdf
Python build your security tools.pdfPython build your security tools.pdf
Python build your security tools.pdf
 

Plus de ececourse

Machine Problem 2
Machine Problem 2Machine Problem 2
Machine Problem 2ececourse
 
Machine Problem 1
Machine Problem 1Machine Problem 1
Machine Problem 1ececourse
 
Chapter 2 Hw
Chapter 2 HwChapter 2 Hw
Chapter 2 Hwececourse
 
Chapter 2 Part2 C
Chapter 2 Part2 CChapter 2 Part2 C
Chapter 2 Part2 Cececourse
 
C:\Fakepath\Chapter 2 Part2 B
C:\Fakepath\Chapter 2 Part2 BC:\Fakepath\Chapter 2 Part2 B
C:\Fakepath\Chapter 2 Part2 Bececourse
 
Chapter 2 Part2 A
Chapter 2 Part2 AChapter 2 Part2 A
Chapter 2 Part2 Aececourse
 
Chapter 2 Part1
Chapter 2 Part1Chapter 2 Part1
Chapter 2 Part1ececourse
 

Plus de ececourse (14)

Chapter 5 c
Chapter 5 cChapter 5 c
Chapter 5 c
 
Chapter 5 b
Chapter 5  bChapter 5  b
Chapter 5 b
 
Chapter 5 a
Chapter 5 aChapter 5 a
Chapter 5 a
 
Chapter 4
Chapter 4Chapter 4
Chapter 4
 
Chapter 3
Chapter 3Chapter 3
Chapter 3
 
Mem Tb
Mem TbMem Tb
Mem Tb
 
Machine Problem 2
Machine Problem 2Machine Problem 2
Machine Problem 2
 
Machine Problem 1
Machine Problem 1Machine Problem 1
Machine Problem 1
 
Chapter 2 Hw
Chapter 2 HwChapter 2 Hw
Chapter 2 Hw
 
Chapter 2 Part2 C
Chapter 2 Part2 CChapter 2 Part2 C
Chapter 2 Part2 C
 
C:\Fakepath\Chapter 2 Part2 B
C:\Fakepath\Chapter 2 Part2 BC:\Fakepath\Chapter 2 Part2 B
C:\Fakepath\Chapter 2 Part2 B
 
Chapter 2 Part2 A
Chapter 2 Part2 AChapter 2 Part2 A
Chapter 2 Part2 A
 
Chapter1
Chapter1Chapter1
Chapter1
 
Chapter 2 Part1
Chapter 2 Part1Chapter 2 Part1
Chapter 2 Part1
 

Dernier

Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityIES VE
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integrationmarketing932765
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Nikki Chapple
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationKnoldus Inc.
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructureitnewsafrica
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxfnnc6jmgwh
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfNeo4j
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Kaya Weers
 

Dernier (20)

Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a reality
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog Presentation
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdf
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)
 

Auxiliary package for MIPS memory functions

  • 1. --------------------------------------------------------------------------<br />-- Download and rename the file to auxiliary.vhd<br />-- AUB<br />-- EECE 321 - Computer Organization, Spring 2009<br />-- Author: M. M.<br />--------------------------------------------------------------------------<br />-- Description: Auxiliary package including user-defined functions<br />--------------------------------------------------------------------------<br />library ieee;<br />use ieee.std_logic_1164.all;<br />use ieee.std_logic_unsigned.all;<br />use ieee.std_logic_arith.all;<br />use ieee.std_logic_misc.all;<br />USE ieee.std_logic_textio.all;<br />USE std.textio.all;<br />-- ---------------------------------------------------------------------------------<br />-- NOTES:<br />-- ---------------------------------------------------------------------------------<br />-- To convert STD_LOGIC_VECTOR to INTEGER, use the built-in function quot; conv_integerquot; <br />-- CONV_INTEGER(ARG: STD_LOGIC_VECTOR) return INTEGER;<br />-- Ex: if x is a STD_LOGIC_VECTOR, then<br />-- y := conv_integer(x) converts x to unsigned integer<br />-- ---------------------------------------------------------------------------------<br />--<br />-- To convert from INTEGER to STD_LOGIC_VECTOR, use the built-in function quot; conv_std_logic_vectorquot; <br />-- CONV_STD_LOGIC_VECTOR(ARG: INTEGER; SIZE: INTEGER) return STD_LOGIC_VECTOR;<br />-- Ex: if y is an integer, then<br />-- x := conv_std_logic_vector(y,4) converts the integer y into a std_logic_vector of width 4<br />-- ---------------------------------------------------------------------------------<br />--<br />-- declare functions and data types here<br />package auxiliary is<br />----------------------------------------------------------------------------------<br /> -- CONSTANTS<br /> ----------------------------------------------------------------------------------<br />CONSTANT MIPS_WORD_SIZE_IN_BYTES : NATURAL := 4;<br />----------------------------------------------------------------------------------<br /> -- DATA TYPES<br /> ----------------------------------------------------------------------------------<br />SUBTYPE MIPS_WORD is STD_LOGIC_VECTOR(MIPS_WORD_SIZE_IN_BYTES * 8 - 1 DOWNTO 0);<br />TYPE MEM_ARRAY is array (INTEGER range <>) of MIPS_WORD;<br />----------------------------------------------------------------------------------<br /> -- USER-DEFINED FUNCTIONS AND PROCEDURES<br /> ----------------------------------------------------------------------------------<br />PROCEDURE read_hex_2_natural(L: INOUT LINE; width: IN NATURAL; natnum : OUT NATURAL);<br />PROCEDURE read_hex_2_word(L: INOUT LINE; width: IN NATURAL; WORD : OUT STD_LOGIC_VECTOR);<br />PROCEDURE init_mem(fname : IN STRING; mem : OUT MEM_ARRAY);<br />PROCEDURE copy_mem_2_file(fname : IN STRING; mem : IN MEM_ARRAY);<br />FUNCTION load_word(mem : IN MEM_ARRAY; byte_addr : IN NATURAL) RETURN MIPS_WORD;<br />PROCEDURE store_word(mem : OUT MEM_ARRAY; word : MIPS_WORD; byte_addr : IN NATURAL);<br />-- add your functions below ...<br />end auxiliary;<br />package body auxiliary is<br />----------------------------------------------------------------<br />-- Read a hexadecimal string and converts it to a natural number<br />----------------------------------------------------------------<br />PROCEDURE read_hex_2_natural(L: INOUT LINE; width: IN NATURAL; natnum : OUT NATURAL) IS<br />VARIABLE result : NATURAL := 0;<br />VARIABLE ch : CHARACTER;<br />BEGIN<br />FOR i in 1 to width LOOP<br />read(L,ch);<br />IF '0' <= ch AND ch <= '9' THEN<br />result := result*16 + character'pos(ch) - character'pos('0');<br />ELSIF 'A' <= ch AND ch <= 'F' THEN<br />result := result*16 + character'pos(ch) - character'pos('A') + 10;<br />ELSIF 'a' <= ch AND ch <= 'f' THEN<br />result := result*16 + character'pos(ch) - character'pos('a') + 10;<br />ELSE<br />report quot; Format error in input file. Line quot; & integer'image(i) & quot; . quot; severity failure;<br />END IF; <br />END LOOP;<br />natnum := result;<br />END read_hex_2_natural;<br />----------------------------------------------------------------<br />-- Read a hexadecimal string and converts it to a STD_LOGIC_VECTOR<br />----------------------------------------------------------------<br />PROCEDURE read_hex_2_word(L: INOUT LINE; width: IN NATURAL; WORD : OUT STD_LOGIC_VECTOR) IS<br />VARIABLE digit : NATURAL;<br />VARIABLE r : NATURAL := 0;<br />VARIABLE ch : CHARACTER;<br />BEGIN<br />-- first check if width of 'word' is equal to width<br />IF width /= (WORD'length)/4 THEN<br />report quot; Input argument width in function 'read_hex_2_vector' incompatible with output width.quot; severity failure;<br />END IF; <br />FOR i in 1 to width LOOP<br />read(L,ch);<br />IF '0' <= ch AND ch <= '9' THEN<br />digit := character'pos(ch) - character'pos('0');<br />ELSIF 'A' <= ch AND ch <= 'F' THEN<br />digit := character'pos(ch) - character'pos('A') + 10;<br />ELSIF 'a' <= ch AND ch <= 'f' THEN<br />digit := character'pos(ch) - character'pos('a') + 10;<br />ELSE<br />report quot; Format error in input file.quot; severity failure;<br />END IF; <br />WORD(31-r DOWNTO 28-r) := conv_std_logic_vector(digit,4);<br />r := r + 4;<br />END LOOP;<br />END read_hex_2_word;<br />----------------------------------------------------------------<br />-- Initializes memory from a file<br />----------------------------------------------------------------<br />PROCEDURE init_mem(fname : IN STRING; mem : OUT MEM_ARRAY) IS<br />FILE binary_file: text;<br />VARIABLE open_status : file_open_status;<br />VARIABLE L: LINE;<br />VARIABLE ch : CHARACTER;<br />VARIABLE line_number : NATURAL := 0;<br />VARIABLE addr : NATURAL;<br />VARIABLE word : MIPS_WORD;<br />BEGIN<br />-- open file<br />file_open(open_status, binary_file, fname, read_mode);<br />-- check status, report error in case something is wrong with input simulation file<br />IF open_status /= open_ok then<br />report file_open_status'image(open_status) & quot; WHILE opening file quot; & fname<br /> severity failure; <br /> END IF;<br />-- First, write zeros in all entries<br />FOR i in mem'RANGE LOOP <br />mem(i) := (OTHERS => '0');<br />END LOOP;<br />-- Fill entries of memory from the input file<br />WHILE NOT endfile(binary_file) LOOP<br />readline(binary_file, L);<br />line_number := line_number + 1;<br />read_hex_2_natural(L,8,addr);<br />read(L,ch); -- space between address and data<br />read_hex_2_word(L,8,word);<br />mem(addr/4) := word;<br />END LOOP;<br /> <br />END init_mem;<br />----------------------------------------------------------------<br />-- Copies the contents of memory into a file<br />----------------------------------------------------------------<br />PROCEDURE copy_mem_2_file(fname : IN STRING; mem : IN MEM_ARRAY) IS<br />FILE binary_file: text;<br />VARIABLE open_status : file_open_status;<br />VARIABLE L: LINE;<br />VARIABLE line_number : NATURAL := 0;<br />VARIABLE addr : MIPS_WORD;<br />VARIABLE word : MIPS_WORD;<br />VARIABLE nibble : STD_LOGIC_VECTOR(3 DOWNTO 0);<br />BEGIN<br />-- open file<br />file_open(open_status, binary_file, fname, write_mode);<br />-- check status, report error in case something is wrong with input simulation file<br />IF open_status /= open_ok then<br />report file_open_status'image(open_status) & quot; WHILE opening file quot; & fname<br /> severity failure; <br /> END IF;<br />-- Fill entries of memory from the input file<br />FOR j in mem'range LOOP<br />-- assemble address field in hexadecimal<br />addr := conv_std_logic_vector(4*line_number,addr'length);<br />for i in 0 to 7 loop<br />nibble := addr(31-4*i downto 28-4*i); <br />hwrite(L,nibble,FIELD=>1,JUSTIFIED=>left);<br />end loop;<br />-- fill space<br />write(L,STRING'(quot; quot; ));<br />-- assemble data field in hexadecimal<br />word := mem(line_number);<br />for i in 0 to 7 loop<br />nibble := word(31-4*i downto 28-4*i);<br />hwrite(L,nibble,FIELD=>1,JUSTIFIED=>left);<br />end loop;<br />-- advance line number<br />line_number := line_number + 1;<br />-- print line to output file<br />writeline(binary_file,L);<br />END LOOP;<br /> <br />END copy_mem_2_file;<br />----------------------------------------------------------------<br />-- Loads a word from memory (address is byte address)<br />----------------------------------------------------------------<br />FUNCTION load_word(mem : IN MEM_ARRAY; byte_addr : IN NATURAL) RETURN MIPS_WORD IS<br />VARIABLE word : MIPS_WORD;<br />BEGIN<br />-- check byte address falls in memory range or is a multiple of the number of bytes within a word<br />IF (byte_addr < 0) OR <br />(byte_addr >= MIPS_WORD_SIZE_IN_BYTES * mem'length) OR<br />(byte_addr mod MIPS_WORD_SIZE_IN_BYTES /= 0)THEN<br />report quot; Invalid byte address in function 'load_word': quot; & integer'image(byte_addr)<br /> severity failure; <br /> END IF; <br />word := mem(byte_addr/4); <br />return word;<br /> <br />END load_word;<br />----------------------------------------------------------------<br />-- Stores a word into memory (address is byte address)<br />----------------------------------------------------------------<br />PROCEDURE store_word(mem : OUT MEM_ARRAY; word : MIPS_WORD; byte_addr : IN NATURAL) IS<br />BEGIN<br />-- check byte address falls in memory range or is a multiple of the number of bytes within a word<br />IF (byte_addr < 0) OR <br />(byte_addr >= MIPS_WORD_SIZE_IN_BYTES * mem'length) OR<br />(byte_addr mod MIPS_WORD_SIZE_IN_BYTES /= 0)THEN<br />report quot; Invalid byte address in function 'store_word': quot; & integer'image(byte_addr)<br /> severity failure; <br /> END IF; <br />mem(byte_addr/4) := word; <br />END store_word;<br />END auxiliary;<br />