LAB 3 Memory Addresses

Similar documents
LAB 4 Extending Signed and Unsigned Numbers

LAB 5 Arithmetic Operations Simple Calculator

Lab 8 The Stack (LIFO) Structure

mith College Computer Science CSC231 - Assembly Week #4 Dominique Thiébaut

In order to run the program, go to the folder Release and run project.exe.

Practical Malware Analysis

mith College Computer Science CSC231 - Assembly Week #3 Dominique Thiébaut

MODE (mod) FIELD CODES. mod MEMORY MODE: 8-BIT DISPLACEMENT MEMORY MODE: 16- OR 32- BIT DISPLACEMENT REGISTER MODE

Islamic University Gaza Engineering Faculty Department of Computer Engineering ECOM 2125: Assembly Language LAB

Computer Systems Lecture 9

Lab 3: Defining Data and Symbolic Constants

CNIT 127: Exploit Development. Ch 1: Before you begin. Updated

Load Effective Address Part I Written By: Vandad Nahavandi Pour Web-site:

Lab 4: Basic Instructions and Addressing Modes

ADDRESSING MODES. Operands specify the data to be used by an instruction

Lab 5: Input/Output using a Library of Procedures

Faculty of Engineering Student Number:

UMBC. A register, an immediate or a memory address holding the values on. Stores a symbolic name for the memory location that it represents.

Islamic University Gaza Engineering Faculty Department of Computer Engineering ECOM 2125: Assembly Language LAB. Lab # 7. Procedures and the Stack

Assembly Language Lab # 9

mith College Computer Science CSC231 - Assembly Week #8 Dominique Thiébaut

Faculty of Engineering Computer Engineering Department Islamic University of Gaza Assembly Language Lab # 2 Assembly Language Fundamentals

Full Name: CISC 360, Fall 2008 Example of Exam

Assembly Language Each statement in an assembly language program consists of four parts or fields.

CS , Fall 2001 Exam 1

Dr. Ramesh K. Karne Department of Computer and Information Sciences, Towson University, Towson, MD /12/2014 Slide 1

mith College Computer Science CSC231 Assembly Week #9 Fall 2017 Dominique Thiébaut

CS , Fall 2004 Exam 1

OBJECT ORIENTED PROGRAMMING

Name: CMSC 313 Fall 2001 Computer Organization & Assembly Language Programming Exam 1. Question Points I. /34 II. /30 III.

Islamic University Gaza Engineering Faculty Department of Computer Engineering ECOM 2125: Assembly Language LAB

The Instruction Set. Chapter 5

mith College Computer Science CSC231 - Assembly Week #9 Dominique Thiébaut

Assembly Language LAB

We can study computer architectures by starting with the basic building blocks. Adders, decoders, multiplexors, flip-flops, registers,...

CSE2421 FINAL EXAM SPRING Name KEY. Instructions: Signature

CPU. IBM PC and compatible Memory Structure

C and Programming Basics

X86 Assembly Language and C Fundamentals. Chapter 5. Data Transfer Instructions. X86 Code Figures

By: Dalbir Singh, Computer Science Dep't

16.317: Microprocessor Systems Design I Fall 2014

Module 3 Instruction Set Architecture (ISA)

Chapter 11. Addressing Modes

CS , Fall 2002 Exam 1

Data Transfers, Addressing, and Arithmetic. Part 2

CS , Spring 2004 Exam 1

Lab 2: Introduction to Assembly Language Programming

Microprocessors & Assembly Language Lab 1 (Introduction to 8086 Programming)

Subprograms: Local Variables

CS 3843 Final Exam Fall 2012

CS 3330 Introduction 1

Computer Systems II. Memory Management" Subdividing memory to accommodate many processes. A program is loaded in main memory to be executed

Question 4.2 2: (Solution, p 5) Suppose that the HYMN CPU begins with the following in memory. addr data (translation) LOAD 11110

COMP 210 Example Question Exam 2 (Solutions at the bottom)

Representation of Information

/ 28 HLL assembly Q4: Conditional instructions / 40 TOTAL SCORE / 100 EXTRA CREDIT / 10

buffer overflow exploitation

Chapter 3: Addressing Modes

mith College Computer Science CSC231 Assembly Week #5 Fall 2017 Dominique Thiébaut

16.317: Microprocessor Systems Design I Fall 2015

Lab 6: Conditional Processing

CS 5513 Entry Quiz. Systems Programming (CS2213/CS3423))

Assembly Language Programming: Procedures. EECE416 uc. Charles Kim Howard University. Fall

Introduction to 8086 Assembly

CPSC 121: Models of Computation Lab #9: A Working Computer

16.317: Microprocessor Systems Design I Spring 2015

EEM336 Microprocessors I. Addressing Modes

Assembly Language Programming

X86 Addressing Modes Chapter 3" Review: Instructions to Recognize"

Datorarkitektur, 2009 Tentamen

Ethical Hacking. Assembly Language Tutorial

Computer Systems Organization V Fall 2009

CS 31: Intro to Systems ISAs and Assembly. Martin Gagné Swarthmore College February 7, 2017

ECOM 2325 Computer Organization and Assembly Language. Instructor: Ruba A.Salamah INTRODUCTION

Philadelphia University Student Name: Student Number:

6/20/2011. Introduction. Chapter Objectives Upon completion of this chapter, you will be able to:

EECE416 :Microcomputer Fundamentals and Design. X86 Assembly Programming Part 1. Dr. Charles Kim

Basic Information. CS318 Project #1. OS Bootup Process. Reboot. Bootup Mechanism

Assembly Language for Intel-Based Computers, 4 th Edition

CPSC 213. Introduction to Computer Systems. Numbers and Memory. Unit 1a

EXPERIMENT WRITE UP. LEARNING OBJECTIVES: 1. Get hands on experience with Assembly Language Programming 2. Write and debug programs in TASM/MASM

Is stack overflow still a problem?

Experiment 8 8 Subroutine Handling Instructions and Macros

Operating Systems. Part 8. Operating Systems. What is an operating system? Interact with Applications. Vector Tables. The master software

(the bubble footer is automatically inserted into this space)

Assembly Language for Intel-Based Computers, 4 th Edition. Chapter 5: Procedures. Chapter Overview. The Book's Link Library

CS 3330 Introduction. Daniel and Charles. CS 3330 Computer Architecture 1

Computer Architecture and Assembly Language. Practical Session 3

Islamic University Gaza Engineering Faculty Department of Computer Engineering ECOM 2125: Assembly Language LAB. Lab # 10. Advanced Procedures

ET156 Introduction to C Programming

ECOM Computer Organization and Assembly Language. Computer Engineering Department CHAPTER 7. Integer Arithmetic

Lab 3. Pointers Programming Lab (Using C) XU Silei

Q1: Multiple choice / 20 Q2: Memory addressing / 40 Q3: Assembly language / 40 TOTAL SCORE / 100

CMSC Lecture 03. UMBC, CMSC313, Richard Chang

CS 31: Intro to Systems ISAs and Assembly. Kevin Webb Swarthmore College September 25, 2018

CS 31: Intro to Systems ISAs and Assembly. Kevin Webb Swarthmore College February 9, 2016

Variables Data types Variable I/O. C introduction. Variables. Variables 1 / 14

Buffer overflow is still one of the most common vulnerabilities being discovered and exploited in commodity software.

C++ to assembly to machine code

Introduction to C. Why C? Difference between Python and C C compiler stages Basic syntax in C

Transcription:

LAB 3 Memory Addresses Objective: To access and explain the computer memory and memory addresses. To develop a program for moving data between CPU and RAM, and find the contents and addresses for each memory variable. To exam the address relationship among the memory variables and declared poers. To find the size of a variable in bytes. To exam indirect memory addressing mode. 1) Type and explain Example 1. Compile, Build, and Run the program. Example 1 illustrates to use of a. a poer to store the address of each element in an 8-bit array b. the address of operator (&) to initialize a poer c. MOV instruction to move the address of each element in an array to registers EAX (or EBX or ECX or EDX, etc), such as MOV EAX, cptr d. sizeof operator to find out the number of bytes of each element in the array and the address of each element in the array. e. indirect memory addressing mode to access the content stored in the memory location, for instance, MOV DL, [EAX] 2) Explain each line of Example 1 (addressconten.cpp) and describe the output of each in your lab report 3) Modify Example 2 and Example 3 provided in addresscontentemp.cpp to do: a. find the content and memory address of a16-bit array b. find the content and memory address of a 32-bit array c. find the size in bytes of the content and memory address of a 16 bit array d. find the size in bytes of the content and memory address of a 32 bit array e. use indirect addressing mode to find the content stored in the memory location and compare to the content of the original array 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 of the relationship among the variable value, the size of the variable, and the memory address of the variable. 6) Analyze the information in the table to understand the Little Endian Computer 7) Exam byte-addressable memory to store a byte, a word, and a double word, respectively. Written exercises: A title page with the lab title, your name and other identification, the current date, and the due date. If you modify or create a program in an exercise, the source code with comments for that program should appear in the laboratory report. The output from all programs should also appear in the lab report. For each exercise, you should provide a write-up describing the purpose of the exercise, what you learned from the exercise, and any comments, improvements, or other work you ve done with the exercise. If you make any mistakes that require correction, you should include the source code for the incorrect program with your lab report. Hand write on the listing where the error occurs and describe what you did to correct the problem. Appropriate diagrams can be included if needed.

Example 1 /*********************************************************** File name: addresscontent.cpp Find the content and the address for each memory variable in the array Method: Embedding an in-line assembly language module in a C program A. Find the contents for each element of an 8-bit array B. Find the addresses for each element of an 8-bit array C. Find out the number of bytes of each element in an 8-bit array D. Find out the number of bytes of the address of each element in an 8-bit array E. Access the content stored in the memory location by indirect memory addressing mode MOV DL, [EAX] to access the content stored in the memory location EAX sizeof() to find the number of byte prf() is used to display information on the console scanf_s() is used to receive the information from the keyboard std::cout is used to display the output on the console system ("pause") is used to hold console *************************************************************/ #include <stdio.h> // to use prf() #include <iostream> // to use system ("pause") to hold console; main() /*An 8-bit one dimensional sc8_arr[5] array declaration and initialization. Poers of scptr0, scptr1, etc will be used to store the address of each element of the array A 32-bit array md[5] will be used to store each of poers A 32-bit array madd[5] is used to store the address of each element of the array A 8-bit array var[5] is used to store the retrieved value by indirect memory addressing mode*/ sc8_arr[5] = 0x41, 0x42, 0x79, 0x7A, 0x7B ; *scptr0, *scptr1, *scptr2, *scptr3, *scptr4; md[5], madd[5]; var[4]; i; // used as index //address for each element in an array sc8_arr[5] scptr0 = &sc8_arr [0]; scptr1 = &sc8_arr [1]; scptr2 = & sc8_arr[2]; scptr3 = & sc8_arr[3]; scptr4 = & sc8_arr[4]; //Display Hex value, decimal value, and value for each element of array prf("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n"); prf("---------------the value of each element of 8-bit array-------\n"); for (i=0; i < 5; i++) prf ("The value of element %d in an array is 0x%x (hex), %d(decimal), %c (acter)\n", i, sc8_arr[i], sc8_arr[i], sc8_arr[i]);

//Display address in hexadecimal for each element of array prf("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n"); prf("--------------the address of each element of 8-bit array-------\n"); for (i=0; i < 5; i++) prf ("The memory address of element %d in an array is 0x%X (hexidecimal)\n", i, scptr0+i); prf("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n"); //find the total numbers in byte of array sc8_arr[5] // find the number of byte of each element of array prf("\n"); prf("--------------the size information in bytes of an 8-bit array-------\n"); prf ("The total numbers in bytes of an 8-bit array with 5 elements is %d bytes\n", sizeof (sc8_arr)); md[i] = sizeof (sc8_arr [i]); madd[i] = sizeof(scptr0+i); prf ("-------------------------------------------------------\n"); prf ("the size of element %d is %d bytes\n", i, md[i]); prf ("the size of the address of the element %d is %d bytes\n ", i, madd[i]); //Indirect memory addressing by MOV DL, [EAX] /*move the address of element 0 to EAX store the content at the address shown in EAX o DL(indirect addressing) move the content of DL o the variable of var[0]*/ MOV EAX, scptr0; MOV DL, [EAX]; MOV var[0], DL; /*move the address of element 1 to EAX store the content at the address shown in EAX o DL(indirect addressing) move the content of DL o the variable of var[1]*/ MOV EAX, scptr1; MOV DL, [EAX]; MOV var[1], DL; /* move the address of element 2 to EAX store the content at the address shown in EAX o DL(indirect addressing) move the content of DL o the variable of var[2]*/ MOV EAX, scptr2;

MOV DL, [EAX]; MOV var[2], DL; /*move the address of element 3 to EAX store the content at the address shown in EAX o DL(indirect addressing) move the content of DL o the variable of var[3]*/ MOV EAX, scptr3 MOV DL, [EAX]; MOV var[3], DL; prf("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n"); prf("---------------the value of each element of two 8-bit arrays-------\n"); prf("the values at the index %d of the original array and the retrieved array \n", i); prf("by indirect addressing mode are: 0x%x(hex) and 0x%x(hex), respectively\n", sc8_arr[i], var[i]); prf ("-------------------------------------------------------\n"); system ("pause"); return 0;

The output from addresscontent.cpp Example 2 (Template for 16 bit array) /*********************************************************** File name: addresscontenttemp.cpp Find the content and the address for each memory variable in the array Method: Embedding an in-line assembly language module in a C program A. Find the contents for each element of a 16-bit array B. Find the addresses for each element of a 16-bit array C. Find out the number of bytes of each element in a 16-bit array D. Find out the number of bytes of the address of each element in a 16-bit array E. Access the content stored in the memory location by indirect memory addressing mode

MOV DL, [EAX] to access the content stored in the memory location EAX sizeof() to find the number of byte prf() is used to display information on the console scanf_s() is used to receive the information from the keyboard std::cout is used to display the output on the console system ("pause") is used to hold console *************************************************************/ #include <stdio.h> // to use prf() #include <iostream> // to use system ("pause"); main() /*A 16-bit one dimensional array declaration and initialization. Poers of svptr0, svptr1, etc will be used to store the address of each element of the array A 32-bit array md[4] will be used to store each of poers A 32-bit array madd[4] is used to store the address of each element of the array A 16-bit array svar[4] is used to store the retrived value by indirect memory addressing mode*/ short sh16_arr[4] = -1, -3, 1000, 2000; //16-bit array short *svptr0, *svptr1, *svptr2, *svptr3; // used to store the address md[4], madd[4]; short svar[4]; i; // used as index //address for each element in an array sh16_arr[4] //Display Hex value, decimal value, and short value for each element of array prf("---------------the value of each element of 16-bit array-------\n"); //Display address in hexadecimal for each element of array prf("\n"); prf("--------------the address of each element of 16-bit array-------\n"); // find the numbber of byte of each element of array prf("\n"); prf("--------------the size information in byte of 8-bit array-------\n"); //Indirect memory addressing by MOV DX, [EAX]

prf("---------------the value of each element of two 16-bit arrays-------\n"); system ("pause"); return 0; Example 3 (Template for 32 bit array) /*********************************************************** File name: addresscontenttemp.cpp Find the content and the address for each memory variable in the array Method: Embedding an in-line assembly language module in a C program A. Find the contents for each element of a 32-bit array B. Find the addresses for each element of a 32-bit array C. Find out the number of bytes of each element in a 32-bit array D. Find out the number of bytes of the address of each element in a 32-bit array E. Access the content stored in the memory location by indirect memory addressing mode MOV DL, [EAX] to access the content stored in the memory location EAX sizeof() to find the number of byte prf() is used to display information on the console scanf_s() is used to receive the information from the keyboard std::cout is used to display the output on the console system ("pause") is used to hold console *************************************************************/ #include <stdio.h> // to use prf() #include <iostream> // to use system ("pause"); main() /*A 32-bit one dimentional array declaration and initilization.

Poers of ivptr0, ivptr1, etc will be used to store the address of each element of the array A 32-bit array md[4] will be used to store each of poers A 32-bit array madd[4] is used to store the address of each element of the array A 32-bit array ivar[4] is used to store the retrived value by indirect memory addressing mode*/ i32_arr[4]=0x8000000, 0x0000ffff, -660000, 6600000; //32-bit (double word) array *ivptr0, *ivptr1, *ivptr2, *ivptr3; //ivptr0, ivptr1, ivptr2 are used to store the address md[4], madd[4]; short svar[4]; i; // used as index //address for each element in an array i32_arr[4] //Display Hex value, decimal value, and short value for each element of array prf("---------------the value of each element of 32-bit array-------\n"); //Display address in hexadecimal for each element of array prf("--------------the address of each element of 32-bit array-------\n"); // find the numbber of byte of each element of array prf("--------------the size information in byte of 8-bit array-------\n"); //Indirect memory addressing by MOV EDX, [EAX]

prf("---------------the value of each element of two 32-bit arrays-------\n"); system ("pause"); return 0; Fill in the table with data types, memory contents, and memory addresses Data type short short Short (array with 4 elements) short Variable name sc8_arr[0] sc8_arr[1] sc8_arr[2] sc8_arr[3] sc8_arr[4] sh16_arr[0] sh16_arr[1] sh16_arr[2] sh16_arr[3] i32_arr[0] i32_arr[1] i32_arr[2] i32_arr[3] Hexadecimal Decimal Address

Fill in the table with the size of memory contents, and the size of memory addresses, respectively Data type (array with 5 elements) short short short short (array with 4 elements) Variable name sc8_arr[0] sc8_arr[1] sc8_arr[2] sc8_arr[3] sc8_arr[4] sh16_arr[0] sh16_arr[1] sh16_arr[2] sh16_arr[3] i32_arr[0] i32_arr[1] i32_arr[2] i32_arr[3] Size of each contents in byte(s) Size of each memory addresses in byte(s)