Chapter 14: the Memory

Total Page:16

File Type:pdf, Size:1020Kb

Chapter 14: the Memory TCSS 422 A – Winter 2018 2/21/2018 Institute of Technology TCSS 422: OPERATING SYSTEMS OBJECTIVES Optional Ungraded Quiz – Synchronized Array Homework 2 Questions Memory API, Homework 3 Address Translation, Memory Segmentation, Ch. 14 Free Space Management . Memory API Ch. 15 . Address Translation Wes J. Lloyd Ch. 16 Institute of Technology . (Memory) Segmentation Ch. 17 University of Washington - Tacoma . Free Space Management TCSS422: Operating Systems [Winter 2018] TCSS422: Operating Systems [Winter 2018] February 21, 2018 February 21, 2018 L12.2 Institute of Technology, University of Washington - Tacoma Institute of Technology, University of Washington - Tacoma FEEDBACK FROM 2/14 FEEDBACK - 2 What is a bounded buffer, and when is it used? Homework #2: I’m using “for_each_process(task)” but Ubuntu can’t find this function… HELP!? What is piping in operating systems? In your kernel module make file, note the required files: All target: What is a condition variable? make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules Check to be sure you have this kernel sources: sudo apt-get install build-essential linux-headers-`uname –r` Helpful command - list kernel modules: $lsmod TCSS422: Operating Systems [Winter 2018] TCSS422: Operating Systems [Winter 2018] February 21, 2018 L12.3 February 21, 2018 L12.4 Institute of Technology, University of Washington - Tacoma Institute of Technology, University of Washington - Tacoma FEEDBACK - 3 “TCSS 422 has overlap with TCSS 333 for memory maps, memory/address translation”… Initial chapters of memory virtualization may be review However, memory virtualization spans chapters 13, 14, 15, CHAPTER 14: THE 16, 17, 18, 19, 20, 21, 22. (10 chapters) MEMORY API . Suspect this is not all review… TCSS422: Operating Systems [Winter 2018] TCSS422: Operating Systems [Winter 2018] February 21, 2018 L12.5 February 21, 2018 Institute of Technology, University of Washington - Tacoma Institute of Technology, University of Washington - Tacoma L12.6 Slides by Wes J. Lloyd L12.1 TCSS 422 A – Winter 2018 2/21/2018 Institute of Technology MALLOC SIZEOF() Not safe to assume data type sizes using Allocates memory on the heap different compilers, systems size_t unsigned integer (must be +) size size of memory allocation in bytes Dynamic array of 10 ints Returns Static array of 10 ints SUCCESS: A void * to a memory address FAIL: NULL sizeof() often used to ask the system how large a given datatype or struct is TCSS422: Operating Systems [Winter 2018] TCSS422: Operating Systems [Winter 2018] February 21, 2018 L12.7 February 21, 2018 L12.8 Institute of Technology, University of Washington - Tacoma Institute of Technology, University of Washington - Tacoma #include<stdio.h> FREE() What will this code do? int * set_magic_number_a() { int a =53247; return &a; } Free memory allocated with malloc() void set_magic_number_b() { Provide: (void *) ptr to malloc’d memory int b = 11111; } Returns: nothing int main() { int * x = NULL; x = set_magic_number_a(); printf("The magic number is=%d\n“,*x); set_magic_number_b(); printf(“The magic number is=%d\n“,*x); TCSS422: Operating Systems [Winter 2018] return 0; February 21, 2018 L12.9 Institute of Technology, University of Washington - Tacoma } 10 #include<stdio.h> What will this code do? DANGLING POINTER (1/2) int * set_magic_number_a() { int a =53247; Dangling pointers arise when a variable referred (a) goes return &a; Output: “out of scope”, and it’s memory is destroyed/overwritten } $ ./pointer_error The magic number is=53247 (by b) without modifying the value of the pointer (*x). void set_magic_number_b() The magic number is=11111 { int b = 11111; The pointer still points to the original memory location } of the deallocated memory (a), We have not changed *x but which has now been reclaimed for (b). int main() the value has changed!! { int * x = NULL; Why? x = set_magic_number_a(); printf("The magic number is=%d\n“,*x); set_magic_number_b(); printf("The magic number is=%d\n“,*x); return 0; TCSS422: Operating Systems [Winter 2018] February 21, 2018 L12.12 } 11 Institute of Technology, University of Washington - Tacoma Slides by Wes J. Lloyd L12.2 TCSS 422 A – Winter 2018 2/21/2018 Institute of Technology DANGLING POINTER (2/2) CALLOC() Fortunately in the case, a compiler warning is generated: Allocate “C”lear memory on the heap $ g++ -o pointer_error -std=c++0x pointer_error.cpp Calloc wipes memory in advance of use… size_t num : number of blocks to allocate pointer_error.cpp: In function ‘int* set_magic_number_a()’: size_t size : size of each block(in bytes) pointer_error.cpp:6:7: warning: address of local variable ‘a’ returned [enabled by default] Calloc() prevents… char *dest = malloc(20); This is a common mistake - - - printf("dest string=%s\n", dest); accidentally referring to addresses that have gone “out of scope” dest string=��F TCSS422: Operating Systems [Winter 2018] TCSS422: Operating Systems [Winter 2018] February 21, 2018 L12.13 February 21, 2018 L12.14 Institute of Technology, University of Washington - Tacoma Institute of Technology, University of Washington - Tacoma REALLOC() DOUBLE FREE Resize an existing memory allocation Can’t deallocate twice Returned pointer may be same address, or a new address Second call core dumps . New if memory allocation must move void *ptr: Pointer to memory block allocated with malloc, calloc, or realloc size_t size: New size for the memory block(in bytes) EXAMPLE: realloc.c EXAMPLE: nom.c TCSS422: Operating Systems [Winter 2018] TCSS422: Operating Systems [Winter 2018] February 21, 2018 L12.15 February 21, 2018 L12.16 Institute of Technology, University of Washington - Tacoma Institute of Technology, University of Washington - Tacoma SYSTEM CALLS brk(), sbrk() Used to change data segment size (the end of the heap) Don’t use these CHAPTER 15: ADDRESS Mmap(), munmap() TRANSLATION Can be used to create an extra independent “heap” of memory for a user program See man page TCSS422: Operating Systems [Winter 2018] TCSS422: Operating Systems [Winter 2018] February 21, 2018 L12.17 February 21, 2018 Institute of Technology, University of Washington - Tacoma Institute of Technology, University of Washington - Tacoma L12.18 Slides by Wes J. Lloyd L12.3 TCSS 422 A – Winter 2018 2/21/2018 Institute of Technology OBJECTIVES ADDRESS TRANSLATION Virtual mapping Address translation 64KB Address space Base and bounds example HW and OS Support Translation: mapping virtual to Memory segments physical Memory fragmentation Address Space TCSS422: Operating Systems [Winter 2018] TCSS422: Operating Systems [Winter 2018] February 21, 2018 L12.19 February 21, 2018 L12.20 Institute of Technology, University of Washington - Tacoma Institute of Technology, University of Washington - Tacoma BASE AND BOUNDS INSTRUCTION EXAMPLE Dynamic relocation Base = 32768 Two registers base & bounds: on the CPU Bounds =16384 OS places program in memory Fetch instruction at 128 (virt addr) ↑ Sets base register . Phy addr = virt addr + base reg . 32896 = 128 + 32768 (base) Execute instruction . Load from address (var x is @ 15kb=15360) Bounds register . 48128 = 15360 + 32768 (base) -- found x… . Stores size of program address space (16KB) Bounds register: terminate process if OS verifies that every address: . ACCESS VIOLATION: Virtual address > bounds reg 0≤ 푣푖푟푡푢푎푙 푎푑푑푟푒푠푠 < 푏표푢푛푑푠 Int x TCSS422: Operating Systems [Winter 2018] TCSS422: Operating Systems [Winter 2018] February 21, 2018 L12.21 February 21, 2018 L12.22 Institute of Technology, University of Washington - Tacoma Institute of Technology, University of Washington - Tacoma MEMORY MANAGEMENT UNIT DYNAMIC RELOCATION OF PROGRAMS MMU Hardware requirements: . Portion of the CPU dedicated to address translation Requirements HW support . Contains base & bounds registers Privileged mode CPU modes: kernel, user Base & Bounds Example: Base / bounds registers Registers to support address translation . Consider address translation Translate virtual addr; check if in Translation circuitry, check limits . 4 KB (4096 bytes) address space, loaded at 16 KB physical location bounds Privileged instruction(s) to Instructions for modifying base/bound Virtual Address Physical Address update base / bounds regs registers 0 16384 Privileged instruction(s) Set code pointers to OS code to handle faults 1024 17408 to register exception handlers 3000 19384 Ability to raise exceptions For out-of-bounds memory access, or attempts to access privileged instr. FAULT 4400 20784 (out of bounds) TCSS422: Operating Systems [Winter 2018] TCSS422: Operating Systems [Winter 2018] February 21, 2018 L12.23 February 21, 2018 L12.24 Institute of Technology, University of Washington - Tacoma Institute of Technology, University of Washington - Tacoma Slides by Wes J. Lloyd L12.4 TCSS 422 A – Winter 2018 2/21/2018 Institute of Technology OS SUPPORT FOR MEMORY OS: WHEN PROCESS STARTS RUNNING VIRTUALIZATION For base and bounds OS support required OS searches for free space for new process . Free list: data structure that tracks available memory slots . When process starts running . Allocate address space in physical memory . When a process is terminated . Reclaiming memory for use . When context switch occurs . Saving and storing the base-bounds pair . Exception handlers . Function pointers set at OS boot time TCSS422: Operating Systems [Winter 2018] TCSS422: Operating Systems [Winter 2018] February 21, 2018 L12.25 February 21, 2018 L12.26 Institute of Technology, University of Washington
Recommended publications
  • Security and Performance Analysis of Custom Memory Allocators Tiffany
    Security and Performance Analysis of Custom Memory Allocators by Tiffany Tang Submitted to the Department of Electrical Engineering and Computer Science in partial fulfillment of the requirements for the degree of Master of Engineering in Electrical Engineering and Computer Science at the MASSACHUSETTS INSTITUTE OF TECHNOLOGY September 2019 c Massachusetts Institute of Technology 2019. All rights reserved. Author.............................................................. Department of Electrical Engineering and Computer Science June 10, 2019 Certified by. Howard E. Shrobe Principal Research Scientist and Associate Director of Security, CSAIL Thesis Supervisor Certified by. Hamed Okhravi Senior Technical Staff, MIT Lincoln Laboratory Thesis Supervisor Accepted by . Katrina LaCurts, Chair, Masters of Engineering Thesis Committee 2 DISTRIBUTION STATEMENT A. Approved for public release. Distribution is unlimited. This material is based upon work supported by the Assistant Secretary of Defense for Research and Engineering under Air Force Contract No. FA8702-15-D-0001. Any opinions, findings, conclusions or recommendations expressed in this material are those of the author(s) and do not necessarily reflect the views of the Assistant Secre- tary of Defense for Research and Engineering. 3 Security and Performance Analysis of Custom Memory Allocators by Tiffany Tang Submitted to the Department of Electrical Engineering and Computer Science on June 10, 2019, in partial fulfillment of the requirements for the degree of Master of Engineering in Electrical Engineering and Computer Science Abstract Computer programmers use custom memory allocators as an alternative to built- in or general-purpose memory allocators with the intent to improve performance and minimize human error. However, it is difficult to achieve both memory safety and performance gains on custom memory allocators.
    [Show full text]
  • CSE421 Midterm Solutions —SOLUTION SET— 09 Mar 2012
    CSE421 Midterm Solutions —SOLUTION SET— 09 Mar 2012 This midterm exam consists of three types of questions: 1. 10 multiple choice questions worth 1 point each. These are drawn directly from lecture slides and intended to be easy. 2. 6 short answer questions worth 5 points each. You can answer as many as you want, but we will give you credit for your best four answers for a total of up to 20 points. You should be able to answer the short answer questions in four or five sentences. 3. 2 long answer questions worth 20 points each. Please answer only one long answer question. If you answer both, we will only grade one. Your answer to the long answer should span a page or two. Please answer each question as clearly and succinctly as possible. Feel free to draw pic- tures or diagrams if they help you to do so. No aids of any kind are permitted. The point value assigned to each question is intended to suggest how to allocate your time. So you should work on a 5 point question for roughly 5 minutes. CSE421 Midterm Solutions 09 Mar 2012 Multiple Choice 1. (10 points) Answer all ten of the following questions. Each is worth one point. (a) In the story that GWA (Geoff) began class with on Monday, March 4th, why was the Harvard student concerned about his grade? p He never attended class. He never arrived at class on time. He usually fell asleep in class. He was using drugs. (b) All of the following are inter-process (IPC) communication mechanisms except p shared files.
    [Show full text]
  • Paging: Smaller Tables
    20 Paging: Smaller Tables We now tackle the second problem that paging introduces: page tables are too big and thus consume too much memory. Let’s start out with a linear page table. As you might recall1, linear page tables get pretty 32 12 big. Assume again a 32-bit address space (2 bytes), with 4KB (2 byte) pages and a 4-byte page-table entry. An address space thus has roughly 232 one million virtual pages in it ( 212 ); multiply by the page-table entry size and you see that our page table is 4MB in size. Recall also: we usually have one page table for every process in the system! With a hundred active processes (not uncommon on a modern system), we will be allocating hundreds of megabytes of memory just for page tables! As a result, we are in search of some techniques to reduce this heavy burden. There are a lot of them, so let’s get going. But not before our crux: CRUX: HOW TO MAKE PAGE TABLES SMALLER? Simple array-based page tables (usually called linear page tables) are too big, taking up far too much memory on typical systems. How can we make page tables smaller? What are the key ideas? What inefficiencies arise as a result of these new data structures? 20.1 Simple Solution: Bigger Pages We could reduce the size of the page table in one simple way: use bigger pages. Take our 32-bit address space again, but this time assume 16KB pages. We would thus have an 18-bit VPN plus a 14-bit offset.
    [Show full text]
  • Memory Management
    Memory Management Reading: Silberschatz chapter 9 Reading: Stallings chapter 7 EEL 358 1 Outline ¾ Background ¾ Issues in Memory Management ¾ Logical Vs Physical address, MMU ¾ Dynamic Loading ¾ Memory Partitioning Placement Algorithms Dynamic Partitioning ¾ Buddy System ¾ Paging ¾ Memory Segmentation ¾ Example – Intel Pentium EEL 358 2 Background ¾ Main memory → fast, relatively high cost, volatile ¾ Secondary memory → large capacity, slower, cheaper than main memory and is usually non volatile ¾ The CPU fetches instructions/data of a program from memory; therefore, the program/data must reside in the main (RAM and ROM) memory ¾ Multiprogramming systems → main memory must be subdivided to accommodate several processes ¾ This subdivision is carried out dynamically by OS and known as memory management EEL 358 3 Issues in Memory Management ¾ Relocation: Swapping of active process in and out of main memory to maximize CPU utilization Process may not be placed back in same main memory region! Ability to relocate the process to different area of memory ¾ Protection: Protection against unwanted interference by another process Must be ensured by processor (hardware) rather than OS ¾ Sharing: Flexibility to allow several process to access the same portions of the main memory ¾ Efficiency: Memory must be fairly allocated for high processor utilization, Systematic flow of information between main and secondary memory EEL 358 4 Binding of Instructions and Data to Memory Compiler → Generates Object Code Linker → Combines the Object code into
    [Show full text]
  • Virtual Memory Basics
    Operating Systems Virtual Memory Basics Peter Lipp, Daniel Gruss 2021-03-04 Table of contents 1. Address Translation First Idea: Base and Bound Segmentation Simple Paging Multi-level Paging 2. Address Translation on x86 processors Address Translation pointers point to objects etc. transparent: it is not necessary to know how memory reference is converted to data enables number of advanced features programmers perspective: Address Translation OS in control of address translation pointers point to objects etc. transparent: it is not necessary to know how memory reference is converted to data programmers perspective: Address Translation OS in control of address translation enables number of advanced features pointers point to objects etc. transparent: it is not necessary to know how memory reference is converted to data Address Translation OS in control of address translation enables number of advanced features programmers perspective: transparent: it is not necessary to know how memory reference is converted to data Address Translation OS in control of address translation enables number of advanced features programmers perspective: pointers point to objects etc. Address Translation OS in control of address translation enables number of advanced features programmers perspective: pointers point to objects etc. transparent: it is not necessary to know how memory reference is converted to data Address Translation - Idea / Overview Shared libraries, interprocess communication Multiple regions for dynamic allocation
    [Show full text]
  • Chapter 4 Memory Management and Virtual Memory Asst.Prof.Dr
    Chapter 4 Memory management and Virtual Memory Asst.Prof.Dr. Supakit Nootyaskool IT-KMITL Object • To discuss the principle of memory management. • To understand the reason that memory partitions are importance for system organization. • To describe the concept of Paging and Segmentation. 4.1 Difference in main memory in the system • The uniprogramming system (example in DOS) allows only a program to be present in memory at a time. All resources are provided to a program at a time. Example in a memory has a program and an OS running 1) Operating system (on Kernel space) 2) A running program (on User space) • The multiprogramming system is difference from the mentioned above by allowing programs to be present in memory at a time. All resource must be organize and sharing to programs. Example by two programs are in the memory . 1) Operating system (on Kernel space) 2) Running programs (on User space + running) 3) Programs are waiting signals to execute in CPU (on User space). The multiprogramming system uses memory management to organize location to the programs 4.2 Memory management terms Frame Page Segment 4.2 Memory management terms Frame Page A fixed-lengthSegment block of main memory. 4.2 Memory management terms Frame Page A fixed-length block of data that resides in secondary memory. A page of data may temporarily beSegment copied into a frame of main memory. A variable-lengthMemory management block of data that residesterms in secondary memory. A segment may temporarily be copied into an available region of main memory or the segment may be divided into pages which can be individuallyFrame copied into mainPage memory.
    [Show full text]
  • Chapter 7 Memory Management Roadmap
    Operating Systems: Internals and Design Principles, 6/E William Stallings Chapter 7 Memory Management Dave Bremer Otago Polytechnic, N.Z. ©2009, Prentice Hall Roadmap • Basic requirements of Memory Management • Memory Partitioning • Basic blocks of memory management – Paging – Segmentation The need for memory management • Memory is cheap today, and getting cheaper – But applications are demanding more and more memory, there is never enough! • Memory Management, involves swapping blocks of data from secondary storage. • Memory I/O is slow compared to a CPU – The OS must cleverly time the swapping to maximise the CPU’s efficiency Memory Management Memory needs to be allocated to ensure a reasonable supply of ready processes to consume available processor time Memory Management Requirements • Relocation • Protection • Sharing • Logical organisation • Physical organisation Requirements: Relocation • The programmer does not know where the program will be placed in memory when it is executed, – it may be swapped to disk and return to main memory at a different location (relocated) • Memory references must be translated to the actual physical memory address Memory Management Terms Table 7.1 Memory Management Terms Term Description Frame Fixed -length block of main memory. Page Fixed -length block of data in secondary memory (e.g. on disk). Segment Variable-length block of data that resides in secondary memory. Addressing Requirements: Protection • Processes should not be able to reference memory locations in another process without permission
    [Show full text]
  • A+ Certification for Dummies, 2Nd Edition.Pdf
    A+ Certification for Dummies, Second Edition by Ron Gilster ISBN: 0764508121 | Hungry Minds © 2001 , 567 pages Your fun and easy guide to Exams 220-201 and 220-202! A+ Certification For Dummies by Ron Gilster Published by Hungry Minds, Inc. 909 Third Avenue New York, NY 10022 www.hungryminds.com www.dummies.com Copyright © 2001 Hungry Minds, Inc. All rights reserved. No part of this book, including interior design, cover design, and icons, may be reproduced or transmitted in any form, by any means (electronic, photocopying, recording, or otherwise) without the prior written permission of the publisher. Library of Congress Control Number: 2001086260 ISBN: 0-7645-0812-1 Printed in the United States of America 10 9 8 7 6 5 4 3 2 1 2O/RY/QU/QR/IN Distributed in the United States by Hungry Minds, Inc. Distributed by CDG Books Canada Inc. for Canada; by Transworld Publishers Limited in the United Kingdom; by IDG Norge Books for Norway; by IDG Sweden Books for Sweden; by IDG Books Australia Publishing Corporation Pty. Ltd. for Australia and New Zealand; by TransQuest Publishers Pte Ltd. for Singapore, Malaysia, Thailand, Indonesia, and Hong Kong; by Gotop Information Inc. for Taiwan; by ICG Muse, Inc. for Japan; by Intersoft for South Africa; by Eyrolles for France; by International Thomson Publishing for Germany, Austria and Switzerland; by Distribuidora Cuspide for Argentina; by LR International for Brazil; by Galileo Libros for Chile; by Ediciones ZETA S.C.R. Ltda. for Peru; by WS Computer Publishing Corporation, Inc., for the Philippines; by Contemporanea de Ediciones for Venezuela; by Express Computer Distributors for the Caribbean and West Indies; by Micronesia Media Distributor, Inc.
    [Show full text]
  • Memory Management
    Memory Management 1 Learning Outcomes • Appreciate the need for memory management in operating systems, understand the limits of fixed memory allocation schemes. • Understand fragmentation in dynamic memory allocation, and understand dynamic allocation approaches. • Understand how program memory addresses relate to physical memory addresses, memory management in base-limit machines, and swapping • An overview of virtual memory management, including paging and segmentation. 2 Process • One or more threads of execution • Resources required for execution – Memory (RAM) • Program code (“text”) • Data (initialised, uninitialised, stack) • Buffers held in the kernel on behalf of the process – Others • CPU time • Files, disk space, printers, etc. 3 Some Goals of an Operating System • Maximise memory utilisation • Maximise CPU utilization • Minimise response time • Prioritise “important” processes • Note: Conflicting goals ⇒ tradeoffs – E.g. maximising CPU utilisation (by running many processes) increases (degrades) system response time. 4 Memory Management • Keeps track of what memory is in use and what memory is free • Allocates free memory to process when needed – And deallocates it when they don’t • Manages the transfer of memory between RAM and disk. 5 Memory Hierarchy • Ideally, programmers want memory that is – Fast – Large – Nonvolatile • Not possible • Memory manager coordinates how memory hierarchy is used. – Focus usually on RAM ⇔ Disk 6 Memory Management • Two broad classes of memory management systems – Those that transfer processes
    [Show full text]
  • The RISC-V Instruction Set Manual, Volume II: Privileged Architecture, Version 1.10”, Editors Andrew Waterman and Krste Asanovi´C,RISC-V Foundation, May 2017
    The RISC-V Instruction Set Manual Volume II: Privileged Architecture Privileged Architecture Version 1.10 Document Version 1.10 Warning! This draft specification may change before being accepted as standard by the RISC-V Foundation. While the editors intend future changes to this specification to be forward compatible, it remains possible that implementations made to this draft specification will not conform to the future standard. Editors: Andrew Waterman1, Krste Asanovi´c1;2 1SiFive Inc., 2CS Division, EECS Department, University of California, Berkeley [email protected], [email protected] May 7, 2017 Contributors to all versions of the spec in alphabetical order (please contact editors to suggest corrections): Krste Asanovi´c,Rimas Aviˇzienis,Jacob Bachmeyer, Allen J. Baum, Paolo Bonzini, Ruslan Bukin, Christopher Celio, David Chisnall, Anthony Coulter, Palmer Dabbelt, Monte Dal- rymple, Dennis Ferguson, Mike Frysinger, John Hauser, David Horner, Olof Johansson, Yunsup Lee, Andrew Lutomirski, Jonathan Neusch¨afer,Rishiyur Nikhil, Stefan O'Rear, Albert Ou, John Ousterhout, David Patterson, Colin Schmidt, Wesley Terpstra, Matt Thomas, Tommy Thorn, Ray VanDeWalker, Megan Wachs, Andrew Waterman, and Reinoud Zandijk. This document is released under a Creative Commons Attribution 4.0 International License. This document is a derivative of the RISC-V privileged specification version 1.9.1 released under following license: c 2010{2017 Andrew Waterman, Yunsup Lee, Rimas Aviˇzienis,David Patterson, Krste Asanovi´c.Creative Commons Attribution 4.0 International License. Please cite as: \The RISC-V Instruction Set Manual, Volume II: Privileged Architecture, Version 1.10", Editors Andrew Waterman and Krste Asanovi´c,RISC-V Foundation, May 2017. Preface This is version 1.10 of the RISC-V privileged architecture proposal.
    [Show full text]
  • Name: ID# Q1. Suppose That the Following Directives Are Declared in the Memory Data Segment Starting at Offset 0000. X DB
    ٢٠ ر ا ١٤٣١ ھـ 2nd Semester 1430/1431 Quiz 3 Monday 5 April 2010 ات وا ا ٣ - ١٤٠١٢١٤ Offset Content Name: ID# 0018 Q1. Suppose that the following directives are declared in the 0017 00 memory data segment starting at offset 0000. 0016 00 00 15 00 x DB -4, 4, 12 y DW 1101b, 13, 13h m 0014 0F z EQU 9h 0013 41 k DB ‘C’, ‘D’, ‘CD’ 0012 41 n DB 99h, 2 DUP ( 2 , 2 DUP ‘A’) 00 11 2 m DD 15 0010 41 Fill in the offsets in normal hexadecimal numbers. 000F 41 - Fill in the memory content in hexadecimal. Notice that the 000E 2 ASCII code for ‘A’, ‘a’, ‘0’ is 41h, 61h, 30h, respectively. n 000 D 99 - What are the decimal offset values of the variables: 000C 44 x = 0 000B 43 000A 44 y = 3 k 000 9 43 0008 00 z = Not in memory 0007 13 0006 00 k = 9 0005 0D 0004 00 n = 000Dh = 13 y 0003 0D 0002 0C m = 0014h = 20 0001 04 x 0000 FC Q2. Instructions that utilize registers for operands' storage execute much faster than instructions that utilize the main memory for operand storage. True False Q3. Newer IA32 processors won't run old programs written for older x86 processors due to their different register sizes. True False Q4. The lower 8-bits of the BX register can be addressed as:AX AH AL BX BH BL CX CH CL Q5. The register acting as a counter for repeating or looping instructions is: AX BX CX DX Q6.
    [Show full text]
  • • Programs • Processes • Context Switching • Protected Mode Execution • Inter-Process Communication • Threads
    • Programs • Processes • Context Switching • Protected Mode Execution • Inter-process Communication • Threads 1 Running Dynamic Code • One basic function of an OS is to execute and manage code dynamically, e.g.: – A command issued at a command line terminal – An icon double clicked from the desktop – Jobs/tasks run as part of a batch system (MapReduce) • A process is the basic unit of a program in execution 2 How to Run a Program? • When you double-click on an .exe, how does the OS turn the file on disk into a process? • What information must the .exe file contain in order to run as a program? 3 Program Formats • Programs obey specific file formats – CP/M and DOS: COM executables (*.com) – DOS: MZ executables (*.exe) • Named after Mark Zbikowski, a DOS developer – Windows Portable Executable (PE, PE32+) (*.exe) • Modified version of Unix COFF executable format • PE files start with an MZ header. Why? – Unix/Linux: Executable and Linkable Format (ELF) – Mac OSX: Mach object file format (Mach-O) 4 test.c #include <stdio.h> int big_big_array[10 * 1024 * 1024]; char *a_string = "Hello, World!"; int a_var_with_value = 100; int main(void) { big_big_array[0] = 100; printf("%s\n", a_string); a_var_with_value += 20; printf("main is : %p\n", &main); return 0; } 5 ELF File Format • ELF Header – Contains compatibility info – Entry point of the executable code • Program header table – Lists all the segments in the file – Used to load and execute the program • Section header table – Used by the linker 6 ELF Header Format• Entry point of typedef struct
    [Show full text]