Kirk Scott Computer Science The University of Alaska Anchorage 1.

Slides:



Advertisements
Similar presentations
Part IV: Memory Management
Advertisements

Chapter 16 Java Virtual Machine. To compile a java program in Simple.java, enter javac Simple.java javac outputs Simple.class, a file that contains bytecode.
Lecture 13: 10/8/2002CS170 Fall CS170 Computer Organization and Architecture I Ayman Abdel-Hamid Department of Computer Science Old Dominion University.
Goal: Write Programs in Assembly
Week 3. Assembly Language Programming  Difficult when starting assembly programming  Have to work at low level  Use processor instructions >Requires.
The 8051 Microcontroller and Embedded Systems
INSTRUCTION SET ARCHITECTURES
SPIM and MIPS programming
Chapter 2 Instructions: Language of the Computer
Computer Architecture CSCE 350
Ch. 8 Functions.
The Little man computer
Computer Organization. This module surveys the physical resources of a computer system. –Basic components CPUMemoryBus I/O devices –CPU structure Registers.
CPSC Compiler Tutorial 8 Code Generator (unoptimized)
George Blank University Lecturer. CS 602 Java and the Web Object Oriented Software Development Using Java Chapter 4.
Execution of an instruction
CSCE 121, Sec 200, 507, 508 Fall 2010 Prof. Jennifer L. Welch.
Informationsteknologi Friday, November 16, 2007Computer Architecture I - Class 121 Today’s class Operating System Machine Level.
1 Lab Session-IV CSIT-120 Spring 2001 Lab 3 Revision and Exercises Rev: Precedence Rules Lab Exercise 4-A Machine Language Programming The “Micro” Machine.
Chapter 2: Impact of Machine Architectures What is the Relationship Between Programs, Programming Languages, and Computers.
Chapter 6: An Introduction to System Software and Virtual Machines
Group 5 Alain J. Percial Paula A. Ortiz Francis X. Ruiz.
1 CS Programming Languages Random Access Machines Jeremy R. Johnson.
Computer Science 210 Computer Organization The Instruction Execution Cycle.
System Calls 1.
Computer Organization Computer Organization & Assembly Language: Module 2.
Instruction Set Architecture
Machine Instruction Characteristics
Computer Architecture and the Fetch-Execute Cycle
CS 320 Assignment 1 Rewriting the MISC Osystem class to support loading machine language programs at addresses other than 0 1.
Lecture 8 February 29, Topics Questions about Exercise 4, due Thursday? Object Based Programming (Chapter 8) –Basic Principles –Methods –Fields.
Chapter 10 The Assembly Process. What Assemblers Do Translates assembly language into machine code. Assigns addresses to all symbolic labels (variables.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Memory: Relocation.
Execution of an instruction
CMSC 150 PROGRAM EXECUTION CS 150: Wed 1 Feb 2012.
Interrupt driven I/O. MIPS RISC Exception Mechanism The processor operates in The processor operates in user mode user mode kernel mode kernel mode Access.
Object-Oriented Programming (Java), Unit 28 Kirk Scott 1.
© GCSE Computing Candidates should be able to:  describe the characteristics of an assembler Slide 1.
Represents different voltage levels High: 5 Volts Low: 0 Volts At this raw level a digital computer is instructed to carry out instructions.
COMPILERS CLASS 22/7,23/7. Introduction Compiler: A Compiler is a program that can read a program in one language (Source) and translate it into an equivalent.
Computer Organization 1 Instruction Fetch and Execute.
Computer Organization Rabie A. Ramadan Lecture 3.
Processor Structure and Function Chapter8:. CPU Structure  CPU must:  Fetch instructions –Read instruction from memory  Interpret instructions –Instruction.
Digital Computer Concept and Practice Copyright ©2012 by Jaejin Lee Control Unit.
Interrupt driven I/O Computer Organization and Assembly Language: Module 12.
Computer Organization Instructions Language of The Computer (MIPS) 2.
Digital Computer Concept and Practice Copyright ©2012 by Jaejin Lee Control Unit.
Interrupts and Exception Handling. Execution We are quite aware of the Fetch, Execute process of the control unit of the CPU –Fetch and instruction as.
Chapter 8 String Operations. 8.1 Using String Instructions.
F453 Module 8: Low Level Languages 8.1: Use of Computer Architecture.
Computers’ Basic Organization
The Little man computer
Assembly language.
Control Unit Lecture 6.
System Programming and administration
Assembly Language Ms. V.Anitha AP/CSE SCT
Microcomputer Programming
Computer Science 210 Computer Organization
Computer Science 210 Computer Organization
MARIE: An Introduction to a Simple Computer
Instruction encoding We’ve already seen some important aspects of processor design. A datapath contains an ALU, registers and memory. Programmers and compilers.
Memory Management Tasks
Computer Architecture
COMS 361 Computer Organization
Review In last lecture, done with unsigned and signed number representation. Introduced how to represent real numbers in float format.
CPU Structure CPU must:
Computer Architecture Assembly Language
Week 5 Computers are like Old Testament gods; lots of rules and no mercy. Joseph Campbell.
Chapter 4 The Von Neumann Model
Presentation transcript:

Kirk Scott Computer Science The University of Alaska Anchorage 1

 These overheads fall into 3 sections:  1. An explanation of MISC in general  2. Modifications to MISC  3. What is the Point of This? 2

3

 MISC is a Java simulation of a simple CPU  The simulation includes a simple machine language  Machine programs can be written in this language 4

 MISC contains a simple operating system  The operating system functions are written in Java as part of the simulation  In MISC, absolute machine code is loaded at memory address 0 and executed there  Program loading and execution in MISC can be modified in several ways 5

 Bytes and registers  Bytes, words, and memory  General remarks on machine instruction execution  Fetch, decode, and execute  The machine language instruction set 6

 General remarks on the form of machine language  An example program  The Java methods comprising the simulation  The command line interface  A summary of the structure of the Java simulation by class, constructor, and method 7

 The MISC architecture makes use of 4 byte words  The contents of a register are modeled by an object containing a character array of 8 bytes 8

 Each bit is modeled by the presence of the character ‘1’ or the character ‘0’ in a position in an 8 byte array  The registers are packaged together in an array named “reg”  The index of the array identifies the particular register 9

 Registers:  register namedecimal indexbinary code  identificationin reg arrayof index   unusedreg[0]" "   general purpose   Areg[1]" "  Breg[2]" "  Creg[3]" "  Dreg[4]" "  10

 Registers, cont’d.:  register namedecimal indexbinary code  identificationin reg arrayof index  memory offsets   codeoffsetreg[5]" "  dataoffsetreg[6]" "  unused1reg[7]" "  unused2reg[8]" "  unused3reg[9]" "   flagreg[10]" "  11

 Registers, cont’d.:  register namedecimal indexbinary code  identificationin reg arrayof index  control unit registers   instructionreg[11]" "  operand1reg[12]" "  operand2reg[13]" "  extrareg[14]" "   ALU registers   aluinreg1reg[15]" "  aluinreg2reg[16]" "  aluoutregreg[17]" " 12

 A word in MISC consists of 4 bytes  Memory is implemented as an array of words  The index of the array is the word offset into memory   Memory:array name  memory[] 13

 These are the general rules for move and arithmetic instructions ◦ A register or a memory variable can be a destination ◦ A constant, a register, or a memory variable can be a source ◦ Memory to memory operations are not allowed 14

 A program is loaded to memory location 0 by default  The machine takes control of execution  The machine steps through the program code until it encounters an empty (“ ”) instruction byte 15

 Execution starts with the value 0 in the code offset register  The next 4 contiguous bytes of code memory are put into the instruction, operand1, operand2, and extra registers  After the retrieval of each instruction the code offset is incremented for the next retrieval 16

 The MOVE Instruction  assembly instructionmethod in simulationmachine instruction  MOVE register, registervoid moveDestRegSrcReg()“ ”  MOVE memory, registervoid moveToMemFromReg()“ ”  MOVE register, memoryvoid movetoregfrommem()“ ”  MOVE memory, constantvoid movetomemfromconst()“ ”  MOVE register, constantvoid movetoregfromconst()“ ” 17

 The ADD Instruction  assembly instructionmethod in simulationmachine instruction  ADD register, registervoid addDestRegSrcReg()“ ”  ADD memory, registervoid addToMemFromReg()“ ”  ADD register, memoryvoid addToRegFromMem()“ ”  ADD memory, constantvoid addToMemFromConst()“ ”  ADD register, constantvoid addToRegFromConst()“ ” 18

 The SUB Instruction  assembly instructionmethod in simulationmachine instruction  SUB register, registervoid subDestRegSrcReg()“ ”  SUB memory, registervoid subFromMemSrcReg()“ ”  SUB register, memoryvoid subFromRegSrcMem()“ ”  SUB memory, constantvoid subFromMemSrcConst()“ ”  SUB register, constantvoid subFromRegSrcConst()“ ” 19

 The JUMP Instruction  assembly instructionmethod in simulationmachine instruction  JMP unsigned integervoid jumpUnconditional()“ ”  JPOS unsigned integervoid jumpOnPositive()“ ”  JNEG unsigned integervoid jumpOnNegative()“ ”  JZERO unsigned integervoid jumpOnZero()“ ”  JOVER unsigned integervoid jumpOnOverflow()“ ” 20

 The data declarations come first, then the program code  The program will be loaded at offset 0  Words 0-7 are reserved for data variables and will be filled with 0’s if there are not that many variables  No program, including data, can be longer than 31 lines  The source file signals termination with a row of asterisks 21

 Data Declaration Line  Byte 1: value  Bytes 2-4: unused  Line of Code  Byte 1: instruction  Byte 2: operand 1  Byte 3: operand 2  Byte 4: unused 22

 The example is a machine language program that sums the first 10 integers  The machine language alone with artificial line breaks and segment labels follows  The *’s are used on input to detect the end of the program. 23

 data segment   

 code segment         ******************************** 25

 /.DATA///   /LOOPLIM/X0B//  loop limit offset 0, value 11    /ACCUM/X00//  accumulator offset 1, value 0 26

 /.CODE///   /MOVE/D/X01/  move reg D, const 1  movetoregfromconst 4, 1   /.LABEL/LOOPTOP//    /ADD/ACCUM/D/  (LABEL) add data offset 1, reg D  addtomemfromreg 1, 4 27

  /ADD/D/X01/  add reg D, 1  addtoregfromconst 4, 1    /MOVE/C/LOOPLIM/  move reg C, data offset 0  movetoregfrommem 3, 0 28

  /SUB/C/D/  sub reg C, reg D  subtractdestregsrcreg 3, 4   /JPOS/LOOPTOP//  Since space is reserved for 8 variables, the first instruction comes at word 8.  jump on positive to “LABEL”  jumponpositive 9   ******** ******** ******** ********  /.END/// 29

 The simulation consists of 4 java files: ◦ MachineWord.java ◦ Machine.java ◦ Osystem.java ◦ MachineOSProgram.java  MachineOSProgram contains main() 30

 MISC presents these 3 command prompts:  rpf (run program file)  dmc (dump memory contents)  exit 31

 rpf = run program file  This prompts the user for the machine language program to run  Machine language programs should be text files 32

 dmc = dump machine contents  This prompts the user for the name of the output file to create  This should be a text file  MISC has no I/O capabilities  You know what a program did by looking at the dmc file 33

 exit = quit the simulation 34

 MachineByte.java  MachineWord.java  Machine.java  This is the heart of the simulation  It contains these critical methods: ◦ totalReset() ◦ resetOffsets() ◦ takeControl() 35

 Osystem.java  This has a constructor in which a copy of the Machine is constructed  It contains these critical methods: ◦ runProgramFile() ◦ dumpMemoryContents() 36

 MachineOSProgram.java  This contains the main() method  It is the simulation driver  In it a copy of the Osystem is constructed  It loops, checking for user input from the command prompt 37

 MyTerminalIO  This presents the command prompt in a graphical user interface 38

 MISC can be modified to illustrate these operating system concepts: ◦ Memory allocation ◦ Absolute code ◦ Relative code ◦ Concurrency and scheduling 39

 By default, programs in MISC are loaded and executed at address 0 in memory  The following overhead shows a dmc file after running the example program 40

 memory contents            … 41

 Here are three possible modifications to MISC:  1. Load machine programs at addresses other than 0 ◦ Modify relative code to absolute code for a non- zero address  2. Load machine programs at addresses other than 0 with dynamic address checking ◦ Load relative code and modify the simulation to check memory accesses 42

 3. Load and run more than one machine program at a time ◦ This builds on modification 2 ◦ Memory accesses for each loaded program have to be correctly handled ◦ Execution of multiple programs also involves scheduling 43

 Support program loading at an address other than 0  Alter the machine program code at load time  Memory address references are changed to correspond with the load address  The loaded program is absolute code for the new address  The following overhead shows a dmc file after running the example program with these modifications 44

 memory contents   …            … 45

 Support program loading at an address other than 0  Do not alter the machine program code at load time  A machine language program is loaded to an address other than 0  The machine code is relative code 46

 Each time the running machine program wants to do a memory access, it returns the relative address in the machine code to the operating system  The operating system checks to see if it’s within range 47

 The operating system adds the memory access to the base address where the program was loaded  The operating system passes this absolute address back to the machine for program memory access  The following overhead shows a dmc file after running the example program with these modifications  It looks no different from the previous modification 48

 memory contents   …            … 49

 Modify MISC to load and run more than one machine language program concurrently  Round robin scheduling can be implemented  Instead of time-slicing, use instruction counts  Switch between from one machine program to another when it has executed a fixed number of instructions  Note that threading of command prompt input is necessary to accomplish this 50

 The following overhead shows a dmc file taken midstream while two copies of the machine language program are running  It illustrates that concurrency is taking place  Look at the second data variable, the accumulator  Both programs have non-zero totals  Neither program has yet reached the final value of

 memory contents            …             … 52

 MISC and the modifications given are used as part of a course on operating systems  Students are given the original version of MISC and do the modifications as assignments  Because MISC is written in Java, the students program their solutions by writing Java code  Students can work on operating system concepts without having to work with kernel code of a live operating system 53

 MISC as is, or expanded and modified, could be used in other areas of computer science ◦ Machine language coding ◦ Other operating system concepts ◦ Language translation ◦ Machine level operating system implementation ◦ Security exercises 54

 MISC could also be modified for additional purposes  Its machine language could be expanded  It could then be used as a testbed for machine language coding 55

 MISC could be extended to cover other operating system concepts  For example, different scheduling algorithms could be implemented 56

 MISC and its machine language could be used as part of an exercise in language translation  It would be possible to write an assembler for MISC  It would be possible to define a simple high- level language for MISC and write a compiler for it 57

 The MISC machine language could be extended  It could include memory operations  It could include all operations needed in order to support operating system functionality 58

 If this were done, a big conceptual jump would be possible  The operating system of MISC would not be Java code, Osystem  A complete operating system in MISC machine language could be written  Running the MISC simulation would consist of loading and running this machine language program 59

 If the previous step were taken, MISC would closely resemble a real operating system environment  It would then become possible to write malware for that environment  For example, it would become possible to write code which caused buffer overflows in the MISC operating system 60

 The overall idea is this:  A basic version of MISC exists  The three basic modifications have been developed  MISC has potential for further development in other areas 61

62