Addressing a memory

We need to put our instructions in memory.

Design a memory where the program can be stored. We can implement a memory in SystemC by using TLM (TBD URL). We use TLM as a means to model communication over a memory-mapped bus.

A memory implementation in SystemC/TLM is shown in Figure 11.

#ifndef MEMORY_H
#define MEMORY_H

#include "tlm.h"
#include "tlm_utils/simple_target_socket.h"

class Memory : sc_core::sc_module
{
public: 
    tlm_utils::simple_target_socket<Memory> socket; 
    Memory(sc_core::sc_module_name name, int size); 
private: 
    void read_contents_from_file(const char *file_name, int *mem, int max_values);
    void b_transport(tlm::tlm_generic_payload& trans, sc_core::sc_time& delay); 
    unsigned int size;
    int *mem;
}; 

#endif

Figure 11. A memory in SystemC/TLM.

This the SystemC-TLM view - other views are VHDL - Verilog

Describe the code in Figure 11, and give examples of the implementation, as verb_code_figure listings.

Create a pc that reads addresses expressed in bytes. Meaning that it increments itself with four for each instruction read. We can implement a program counter SystemC by using TLM (TBD URL). We use TLM as a means to model communication over a memory-mapped bus.

A program counter implementation in SystemC/TLM is shown in Figure 12.

#ifndef PC_H
#define PC_H

#include "tlm.h"
#include "tlm_utils/simple_initiator_socket.h"

class Pc : sc_core::sc_module
{
public: 
    tlm_utils::simple_initiator_socket<Pc> socket; 
    Pc(sc_core::sc_module_name name); 
private:
    void process(); 
    int pc_value; 
    int data_read; 
}; 

#endif

Figure 12. A program counter in SystemC/TLM.

This the SystemC-TLM view - other views are VHDL - Verilog

Describe the code in Figure 12, and give examples of the implementation, as verb_code_figure listings.

Connect the pc and the memory into a design, so that when it runs, the program is read, and printed.