Lab 3 The Addresses in Memory (Little Endian)

CET3510 Lab
Developed by Dr. Y.Wang
Lab 3 The Addresses in Memory (Little Endian)
Objective: Understand the computer memory and memory address. Develop a program for data moving between
CPU and RAM and find the content and address for each memory variable. Exam the address relationship among
the memory variables and pointers you declare.
In your lab:
1) Type and understand Program 1 listed in the Appendix A. Compile and run the program. This example
illustrates to use of
a. a pointer to store the address of each element in an array
b. MOV instruction to move the address of each element in an array to register BL(CL, DL), BX(CX,
DX), EBX (ECX, EDX), such as MOV EAX, Ptr,
2) Understand example program. Explain each line of the program and describe the output of each in your lab
report.
3) Modify the example program provided in the Appendix and find:
(a) the content and memory address of 8-bit array element
(b) the content and memory address of 16-bit array element
(c) the content and memory address of 32-bit array element
4) Explore the relationship among these addresses in memory. Understand the addresses for a byte, a word, and a
double word, respectively.
5) Draw a table for the relationship between the variable value, the size of the variable, and the address for the
variable.
Include the source code and all above output in your lab report. If you have any syntax errors in your code, be sure
to include a printout of the incorrect code with hand-written annotations describing how you fixed the problem(s)
in your program.
Appendix A: Program
//chapter 5.2.1 address indirectly, page 198
//chapter 14.1 one dimentional array, page580
//Appendix B pointer example 4.38, page 693
#include <stdio.h> // to use printf()
#include <iostream> // to use system ("pause");
int main()
{
char sc8_arr[4] = { 0x41, 0x42, 0x79, 0x7A} ; //8-bit (a byte) array
char *scPtr0, *scPtr1, *scPtr2, *scPtr3; //scPtr0, scPtr1, … will be used to store the address
short ush16_arr[4] = {1000, 2000, -1, -3};
short *svPtr0, *svPtr1, *svPtr2, *svPtr3;
//16-bit (a word) array
int i32_arr[4]={0x8000000, 0x0000ffff, -660000, 6600000}; //32-bit (double word) array
int *ivPtr0, *ivPtr1, *ivPtr2, *ivPtr3; //ivPtr0, ivPtr1, ivPtr2… are used to store the address
//address for each element in an array
scPtr0 = &sc8_arr [0];
scPtr1 = &sc8_arr [1];
CET3510 Lab
Developed by Dr. Y.Wang
scPtr2 = & sc8_arr[2];
scPtr3 = & sc8_arr[3];
// continue your code
//print Hex value and decimal value and char and address of each element in 8-bit array
printf("---------------------8-bit array------------------------\n");
printf ("The first element in hex is 0x%x, in decimal is %d, the character is %c\n", sc8_arr[0], sc8_arr[0], sc8_arr[0]);
printf ("The address for memory at the first element in an array 0x%X \n", scPtr0);
printf("----------------------------------------------------------------------------\n");
printf ("The second element in hex is 0x%x, in decimal is %d, the character is %c\n", sc8_arr[1], sc8_arr[1], sc8_arr[1]);
printf ("The address for memory at the second element in an array 0x%X \n", scPtr1);
printf("----------------------------------------------------------------------------\n");
printf ("The third element in in hex is 0x%x, in decimal is %d, the character is %c \n", sc8_arr[2], sc8_arr[2], sc8_arr[2]);
printf ("The address for memory at the third element in an array 0x%X \n", scPtr2);
printf("----------------------------------------------------------------------------\n");
// continue your code here
printf("----------------------------------------------------------------------------\n");
/////////////////////////////////////////////////////////////////////////////
//Display Hex value and decimal value and address of each element in 16-bit array
//Your code
printf("----------------------------------------------------------------------------\n");
/////////////////////////////////////////////////////////////////////////////
//Display Hex value and decimal value and address of each element in 32-bit array
//Your code
printf("----------------------------------------------------------------------------\n");
//getchar();
system ("pause");
return 0;
}
In you lab report, fill the table of data type, memory content, and memory address
Data type
char
(array with 4 elements)
char
(array with 4 elements)
char
(array with 4 elements)
char
(array with 4 elements)
short
(array with 4 elements)
short
(array with 4 elements)
short
(array with 4 elements)
short
(array with 4 elements)
Variable
name
sc8_arr[0]
sc8_arr[1]
sc8_arr[2]
sc8_arr[3]
sh16_arr[0]
sh16_arr[1]
sh16_arr[2]
sh16_arr[3]
HEX
Decimal
Address
CET3510 Lab
int
(array with 4 elements)
int
(array with 4 elements)
int
(array with 4 elements)
int
(array with 4 elements)
Developed by Dr. Y.Wang
i32_arr[0]
i32_arr[1]
i32_arr[2]
i32_arr[3]
What is the relationship among these addresses in memory for a byte, a word, and a double word, respectively?