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.

Slides:



Advertisements
Similar presentations
Computer Programming w/ Eng. Applications
Advertisements

 Suppose for a moment that you were asked to perform a task and were given the following list of instructions to perform:
CS0007: Introduction to Computer Programming Console Output, Variables, Literals, and Introduction to Type.
The Assembly Language Level
ABNIAC The following slide presentation is to acquaint the student with ABNIAC. The version used for presentation is the Java version, which can be found.
The Little man computer
 2005 Pearson Education, Inc. All rights reserved Introduction.
Primitive Data Types There are a number of common objects we encounter and are treated specially by almost any programming language These are called basic.
1 Lecture-2 CSIT-120 Spring 2001 Revision of Lecture-1 Introducing Computer Architecture The FOUR Main Elements Fetch-Execute Cycle A Look Under the Hood.
IntroductionIntroduction  Computer program: an ordered sequence of statements whose objective is to accomplish a task.  Programming: process of planning.
Introduction to Computers and Programming Lecture 7:
Introduction to Computers and Programming Lecture 7:
TK 2633 Microprocessor & Interfacing Lecture 3: Introduction to 8085 Assembly Language Programming (2) 1 Prepared By: Associate Prof. Dr Masri Ayob.
Mathematical Operators: working with floating point numbers and more operators  2000 Prentice Hall, Inc. All rights reserved. Modified for use with this.
CSCE 121, Sec 200, 507, 508 Fall 2010 Prof. Jennifer L. Welch.
Room: E-3-31 Phone: Dr Masri Ayob TK 2633 Microprocessor & Interfacing Lecture 1: Introduction to 8085 Assembly Language.
8 November Forms and JavaScript. Types of Inputs Radio Buttons (select one of a list) Checkbox (select as many as wanted) Text inputs (user types text)
 2002 Prentice Hall. All rights reserved. 1 Intro: Java/Python Differences JavaPython Compiled: javac MyClass.java java MyClass Interpreted: python MyProgram.py.
Working with the data type: char  2000 Prentice Hall, Inc. All rights reserved. Modified for use with this course. Introduction to Computers and Programming.
Introduction to C Programming Overview of C Hello World program Unix environment C programming basics.
1 Lecture-2 CS-120 Fall 2000 Revision of Lecture-1 Introducing Computer Architecture The FOUR Main Elements Fetch-Execute Cycle A Look Under the Hood.
1 Lab Session-IV CSIT-120 Fall 2000 Precedence Rules Machine Language Programming The “Micro” Machine The “Micro” Simulator The “Micro” Translator (Thanks.
Chapter 2 Data Types, Declarations, and Displays
JavaScript, Third Edition
Introduction to C Programming
1 Lab Session-III CSIT-120 Spring 2001 Revising Previous session Data input and output While loop Exercise Limits and Bounds GOTO SLIDE 13 Lab session.
COMPUTER SCIENCE I C++ INTRODUCTION
© The McGraw-Hill Companies, 2006 Chapter 1 The first step.
EG280 - CS for Engineers Chapter 2, Introduction to C Part I Topics: Program structure Constants and variables Assignment Statements Standard input and.
1 Lab Session-III CSIT-120 Fall 2000 Revising Previous session Data input and output While loop Exercise Limits and Bounds Session III-B (starts on slide.
Fortran 1- Basics Chapters 1-2 in your Fortran book.
Introduction to Python
General Computer Science for Engineers CISC 106 Lecture 02 Dr. John Cavazos Computer and Information Sciences 09/03/2010.
Machine Instruction Characteristics
IT253: Computer Organization Lecture 4: Instruction Set Architecture Tonga Institute of Higher Education.
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA 1 CST 221 OBJECT ORIENTED PROGRAMMING(OOP) ( 2 CREDITS.
1 Programming in Machine Language SCSC 311 Spring 2011.
Copyright © 2002 W. A. Tucker1 Chapter 7 Lecture Notes Bill Tucker Austin Community College COSC 1315.
Computer Systems Organization CS 1428 Foundations of Computer Science.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
Introduction to Computer Systems and the Java Programming Language.
CS100J Spring 2006 CS100J: 11 weeks of programming using Java and 2 weeks using Matlab. David Gries is teaching CS100J. Graeme Bailey is teaching a special.
Chapter 2: Using Data.
Chapter 8 High-Level Programming Languages. 8-2 Chapter Goals Describe the translation process and distinguish between assembly, compilation, interpretation,
1 INTRODUCTION TO PROBLEM SOLVING AND PROGRAMMING.
Execution of an instruction
Computer Engineering 1 st Semester Dr. Rabie A. Ramadan 3.
A summary of TOY. 4 Main Components Data Processor Control Processor Memory Input/Output Device.
8-1 Compilers Compiler A program that translates a high-level language program into machine code High-level languages provide a richer set of instructions.
A Simple Java Program //This program prints Welcome to Java! public class Welcome { public static void main(String[] args) { public static void main(String[]
Introduction to Python Dr. José M. Reyes Álamo. 2 Three Rules of Programming Rule 1: Think before you program Rule 2: A program is a human-readable set.
Programming Fundamentals. Overview of Previous Lecture Phases of C++ Environment Program statement Vs Preprocessor directive Whitespaces Comments.
Digital Computer Concept and Practice Copyright ©2012 by Jaejin Lee Control Unit.
Georgia Institute of Technology Speed part 1 Barb Ericson Georgia Institute of Technology May 2006.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
Representing Characters in a Computer System Representation of Data in Computer Systems.
OPERATORS IN C CHAPTER 3. Expressions can be built up from literals, variables and operators. The operators define how the variables and literals in the.
Lecture 3: More Java Basics Michael Hsu CSULA. Recall From Lecture Two  Write a basic program in Java  The process of writing, compiling, and running.
© 2004 Pearson Addison-Wesley. All rights reserved August 27, 2007 Primitive Data Types ComS 207: Programming I (in Java) Iowa State University, FALL 2007.
The Little man computer
Control Unit Lecture 6.
Programming in Machine Language
CMSC201 Computer Science I for Majors Lecture 22 – Binary (and More)
Primitive Data Types August 28, 2006 ComS 207: Programming I (in Java)
Revision Lecture
The Processor and Machine Language
CSCE Fall 2013 Prof. Jennifer L. Welch.
Introduction to Java, and DrJava part 1
CSCE Fall 2012 Prof. Jennifer L. Welch.
DATA TYPES There are four basic data types associated with variables:
Presentation transcript:

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 The “Micro” Simulator Lab 4 Continued

Rev: Increment Operator In Experiment 3.2, we have seen the use of the unary increment operator ==> number++; i++ Similarly we have a unary decrement operator ==> number--, i-- Instead of number=number-1;

Rev: ASCII and UNICODE The alphabets and digits are represented by integer values and this mapping is called a code ASCII code was originally 7 bits (128 values) Values from 00 to 1F were reserved for special non-printable control characters

Rev: ASCII and UNICODE For example, trying to print ASCII code 7 will ring a bell on the computer Example: cout<< “\7” To print spaces cout<<“\t” Up from 20 are the uppercase, lowercase letters and digits alongwith punctuation marks

Rev: ASCII and UNICODE ASCII was not sufficient as more symbols were needed ASCII was revised to be “Latin-1”, an 8-bit code that can have 256 symbols Latin-1 can cover some European languages Computers are being used all over the world A unified coding system was needed

6 Rev: ASCII and UNICODE A consortium developed a standard code called UNICODE. This code has 16 bits, thus 65,536 code points are possible World languages have 200,000 symbols so all cannot be accommodated Values from 0 to 255 map to Latin-1 or ASCII so changes are not felt in English

7 Rev: ASCII and UNICODE UNICODE allocates code points to languages in an “official” way Number of code points given is more than the letters in each language to accommodate different forms of each letter Adding new words in English e.g. applets does not require new code points but adding new words in Japanese requires new points

8 Rev: Uncover the ASCII code Experiment 3.5 Why do we include ? What is toascii? What is toupper? What is tolower? (HINT: Use these functions in your program to find out)

9 Rev: Simple Encryption Techniques Once you are able to process a text string, you can convert the characters to their ASCII values The ASCII values are numeric. You can modify these values so that no one can understand what is in the string Exercise 3-C Take a character from the user, add 8 to it and print it. (DEMO)

10 Rev: Mixing Arithmetic Operations When we try to perform several arithmetic operations in one expression, the expression becomes quite complex For example, consider the following Q = (A+B*C)(A+B/C) Q = ((A+B)*C)((A+B)/C)??? OR Q = (A+(B*C))(A+(B/C))???

11 Rev: Using Precedence Rules We can use the precedence rules to get an expression evaluated as per our needs Following are the precedence rules in C++ for arithmetic operations Highest Priority is given to () (parenthesis) Multiplication (*) and Division (/) take precedence over addition (+) and subtraction (-) Assignment (=) is done at the end We should use parenthesis to make the expression clear

12 Lab Exercise 4-A (Demo Required) Develop a program that asks the user to input the daily snowfall totals (in inches) for the last week of February in Chautaqua county. Your program then calculates and displays the average snowfall per day during the week.(BONUS FLAG: All calculations are done in one single statement)

13 Machine Language Programming All programs written in C++, Java or any other user-level language are translated to the machine language after compilation Look at an example that shows how a C++ program line will be converted to the machine language

14 C++ Program My_var = this_data+next_data Compilation and Linking //Load R5 from Memory //Load R4 from Memory //Add R4,R5 & store result in R //Store R6 into Memory The Compilation of Programs

15 Machine Language Programs A compiled and linked program is a series of machine language instructions and data Each processor has its own set of machine language instructions Can programs compiled for Pentium II run on Alpha workstation?

16 The “Micro” Machine The Micro Machine has >256 Memory cells, each cell can hold 1 byte >Memory addresses range 00-FF (two digits) >16 General Purpose Registers >Register addresses range 0-F (one digit) >Program Counter and Instruction Register >12 Machine Language Instructions (1-C)

17 The “Micro” Simulator The “Micro” Simulator is a C++ Program Download this program by visiting “The Micro” link in the labs webpage of the course Click on “micro” to download or cut & paste this program and save as a C++ file Double click on this file to run Visual C++ Compile and run the program

18 The Micro Simulator The full screen display shows the contents of the memory from cell 00 to cell FF It also shows contents of registers R0 through R15 PC and IR contents are visible too The machine has several single-letter commands (4-A): Experiment 4.1 (PC incr?)

19 The Instructions of “Micro”

20 Lab-4 Continued The Micro Machine and its Simulator An example program Exercises The JUMP instruction and its usage Experiment 4.4

21 Micro and its Simulator What is the memory size in Micro? How many instructions are there? How can we start executing a program in Micro? What is the difference between S and G commands?

22 How to Program the Micro Let us walk through an example to learn how to program the Micro EXAMPLE: Write a program in Micro to add numbers stored in R1,R2 and R3 together and leave the result in R4 This program will have two parts. The initialization part will store the values in registers and then the program will perform the desired operation

23 Example INITIALIZATION //Move 5 into R1, (2RXY ==> 2105) //Move 8 into R2 (2RXY ==> 2208) //Move 7 into R3 (2RXY ==>2307) ACTUAL ADDITION //Add R1 and R2 and store the result at temporary location R5 (5RST ==>5512) //Add R5 and R3 and store the result in R4 (5RST ==> 5453) //Stop the program (HALT C000)

24 Example Program in Hex code C000

25 How to load the program? You cannot run your program until it is loaded in Micro’s memory Divide the memory into two equal blocks. First block should be reserved for data and second block for programs. Since the memory is 256 bytes (numbered from 0 to 255) exactly byte 0 to byte 127 are to be reserved for data

26 How to load the program? Byte 128 onwards can be used for loading the programs Byte 128 has the binary address It can be expressed in Hex as 80 Type M and give starting address as 80 When entering your program, only two digits can be stored in each memory location

27 How to run the program? Before running the program, you have to set the Program counter to point to the first instruction in the program Select P and enter 80 Run the program all at once by typing G or one step at a time by typing S Do both one by one (First S then G)

28 The Power to Simulate The Micro Simulator can run programs designed by you too Lab Exercise 4-B Design a program that adds numbers 1 through 5 together and leaves the result in register R9. (DEMO REQUIRED) (DATA SHOULD BE IN MEMORY OR REGISTERS) (4-C) Experiment 4.2

29 JUMP Instruction JUMP instruction is provided to facilitate the implementation of loops and branches Its format is B RXY (JUMP RXY) It means “jump to location XY if R=R0 Unconditional jump if R0 compared to itself Experiment 4.4