Practice Questions for “Behavioral model of memory”:

 

 

A) Test this program on various machines to see if they are little- or big-endian:

 

#include <stdio.h>

unsigned int value = 0x01020304;

 

main ()

{

 

  unsigned char *byte_address = (unsigned char *) &value;

  int i;

 

  printf (“The value as a 32-bit quantity is in hex: 0x%08x\n”, value);

  printf (“The value is stored starting in memory location in hex: 0x%08x\n”, byte_address);

 

  for (i = 0; i < 4; i++)

  {

     printf (“The value stored in the byte at memory location 0x%08lx (hex) is in hex 0x%02x\n”, byte_address, *byte_address);

     byte_address++;

  }

}

 

Use copy/paste but you may have to change the “” characters to the double-quotes character in ASCII.

 

On a little-endian machine you should see something like this:

 

The value as a 32-bit quantity is in hex: 0x01020304

The value is stored starting in memory location in hex: 0x080496b4

The value stored in the byte at memory location 0x080496b4 (hex) is in hex 0x04

The value stored in the byte at memory location 0x080496b5 (hex) is in hex 0x03

The value stored in the byte at memory location 0x080496b6 (hex) is in hex 0x02

The value stored in the byte at memory location 0x080496b7 (hex) is in hex 0x01

 

Notice how the number is stored starting from the least-significant byte.

 

On a big-endian machine you should see something like this:

 

The value as a 32-bit quantity is in hex: 0x01020304

The value is stored starting in memory location in hex: 0x2000000

The value stored in the byte at memory location 0x2000000 (hex) is in hex 0x01

The value stored in the byte at memory location 0x2000001 (hex) is in hex 0x02

The value stored in the byte at memory location 0x2000002 (hex) is in hex 0x03

The value stored in the byte at memory location 0x2000003 (hex) is in hex 0x04

 

 

B) What memory locations are affected by the following assembly program? List memory addresses and contents.

 

 

     Org $2000

     dc.b 1, 2, 3, 4, ‘0’, ‘1’, ‘2’, ‘3’

     dc.l 10, 20, 30

     ds.b 12

     dc.l 100