Lab 1: Part I - Computer Memory


Description
Preparation (1 mark)
Quiz (1 mark)

Description

The purpose of this lab is to demonstrate various concepts related to computer memory, such as data representation, endianness, and sign extension. You must do Part 1 of this lab on your own, prior to coming to the microprocessor lab.

To demonstrate certain concepts related to memory, we will be using the memory simulator embedded below.

Memory:
0x0: 0x
0x1: 0x
0x2: 0x
0x3: 0x
0x4: 0x
0x5: 0x
0x6: 0x
0x7: 0x
0x8: 0x
0x9: 0x
0xa: 0x
0xb: 0x
0xc: 0x
0xd: 0x
0xe: 0x
0xf: 0x
Endianness:

Address:
1
0








Current Address 0x

Data Input:
Byte3 Byte2 Byte1 Byte0

Operation Size Extension


Status:
Loaded Data: 0x

Loaded Data Interpretation:
decimal(signed):
decimal(unsigned):
float:

This program simulates a byte-addressable memory that contains 16 memory locations (i.e., 16 bytes). We will explain its operation through explaining its interface. The left side displays the content of all 16 memory locations using the hexadecimal representation. The right side consists of 7 fields. The first four (Endianness, Address, Data Input and the memory operation) give you the necessary controls to read and write memory. The status field will tell you if the operation you tried to execute was valid or not. The last two (Loaded Data and Loaded Data Interpretation) are used to display the data read from memory, after zero or sign extension to a 32-bit value if necessary.

As was taught in class, the data stored in memory can be interpreted differently, depending on the endianness. That is, when we read (or write) multiple bytes from (to) memory to form a larger data type (e.g., a word or a half-word) in what order do we assemble the bytes into the larger data type? The Endianness field allows you to select between the two commonly used options: big-endian and little-endian.

The Address field allows you to select the memory location being accessed using radio buttons, and displays the current address using a text box. To successfully read and write your memory access must be aligned. A memory access is aligned if the address it accesses is divisible by the size of its data type. So a word sized access must be to an address that is a multiple of 4 and a halfword sized access must be to an address that is a multiple of 2.

The data that will be written to the memory is set using the Data Input field. Byte3 represents the most significant byte, while Byte0 represents the least significant byte of a memory word. Data will be stored in memory according to the endianess selected in the endianness field. For sub-word sized stores the least significant bytes are stored to memory. So when storing a halfword the least significant halfword (Byte1 and Byte0) is used and when storing a byte Byte0 is used.

The fourth field allows you to set the type of operation (load or store), the size of the operation (byte, halfword or word), and for some cases the type of extension to use (i.e. to treat the data as signed or unsigned). By selecting combinations of these 3 fields you can emulate every memory instruction in Nios II. Pressing the execute button will perform the selected memory operation. The memory field will be highlighted to show you the data that was accessed (blue for loaded data and red for stored data). For byte and halfword load operations, the data read from memory will be extended to 32 bits. Unsigned data will be zero extended and signed data will be sign extended. Notice that the extension field will be greyed out when it is not applicable.

The Status field will tell you if the memory operation you tried to execute was sucessful or if the address was misaligned. The Status field will also tell you the equivalent nios2 instruction for that memory operation.

The data loaded from memory using the selected endianness and type of extension is shown in hexadecimal representation in the Data Output field. Finally, the Data Output Interpretation fields displays the data's signed and unsigned decimal and float interpretation.

Preparation (1 Mark)

Perform the following tasks in the order in which they are listed and use the results from the previous operations when performing a particular task.

  1. Record the initial memory contents by reading the left side of the simulator. Make sure the endianness is initially set to little-endian. Note that all memory locations are initialized to random numbers.
  2. Write the value 0xab into the memory location 0xa. Do this as follows:
  3. Store the value 0xabcd into the memory locations starting at 0xc.
  4. Store the value 0xffcd into the memory locations starting at 0xe.
  5. Store the value 0x12345678 into the memory locations starting at 0x0 in big endian notation.
  6. Store the number -22.875 into the memory locations starting at 0x4 in little endian notation using the single-precision floating point representation. Check your result by reading a word from the address 0x4 and observing the value shown in the Data Output Interpretation field.
  7. Store the number -101 as a byte into the memory location 0x8 using the 2's complement representation. Check your result by reading a byte from the address 0x8 and observing the value shown in the Data Output Interpretation field. What is the unsigned decimal interpretation of this byte?
  8. Record the memory contents.
  9. Answer the following questions, and be ready to explain your answers.

Quiz (1 Mark)

Be prepared to answer any questions about the simulator, or any of the memory concepts.