Introduction to Computers - 4 th exam- 授課教授:李錫智. Hints: ADD [DR] [SR1] [SR2] ------- 1010000100 DR SR1 SR2 SUB [DR] [SR1] [SR2] ------- 1010001000 DR.

Slides:



Advertisements
Similar presentations
Stored Program Architecture
Advertisements

P3- Represent how data flows around a computer system
Chapter 2 Machine Language.
SPIM and MIPS programming
2.3) Example of program execution 1. instruction  B25 8 Op-code B means to change the value of the program counter if the contents of the indicated register.
Introduction to computers Exam 2 授課教授:李錫智. Question_1 For the following program: Suppose the user enters 43 、 57 in the text boxes numberBox1 and numberBox2,
Introduction to Computers - 3 rd exam- 授課教授:李錫智. 1.Consider the following program: Magic 8-ball function GetResponse()
授課教授:李錫智 Data Structures -3 rd exam-. 1.[5] Refer to the two trees in Fig. 1. Let’s define the balance factor BF of a node to be the absolute value of.
Introduction to Computers - 2 nd exam- 授課教授:李錫智. 1. Double the Number
Introduction to Computers -1 st exam- 授課教授:李錫智. 1. Given 12 bits, (a).How many different distinct combinations can we get from these bits? Ans: 2 12 =
Introduction to Computing Systems (2nd Exam). 1. [15] Complete a truth table (inputs: A, B, C; output: D) for the transistor-level circuit shown in Figure.
The Control Unit: Sequencing the Processor Control Unit: –provides control signals that activate the various microoperations in the datapath the select.
LAB 9 Simulator Chap 14 REED. Datapath Simulator accompanying the text is a datapath simulator a.k.a. the Knob & Switch Computer developed by Grant Braught.
Chapters 5 - The LC-3 LC-3 Computer Architecture Memory Map
Chapters 4 & 5: LC-3 Computer Architecture Machine Instructions Assembly language Programming in Machine and Assembly Language.
Assembly & Machine Languages
Introduction to Computers -3rd exam- 授課教授:李錫智. Q1 What will the web page look like if the user type 100 、 20 in the numberbox1 、 numberbox2 respectively?
Quiz # 2 Chapters 4, 5, & 6.
Tutorial 11 Using and Writing Visual Basic for Applications Code
Introduction to Computers 第三次考試 授課教授 : 李錫智. 第一題 [15] Suppose random(x,y) returns an integer randomly between x and y inclusively. Consider the following.
Introduction to Computing Systems from bits & gates to C & beyond Chapter 4 The Von Neumann Model Basic components Instruction processing.
Data Structures -1 st test- March 30, 2015 授課教授:李錫智.
Chap 8. Sequencing and Control. 8.1 Introduction Binary information in a digital computer –data manipulated in a datapath with ALUs, registers, multiplexers,
CPU Design. Introduction – The CPU must perform three main tasks: Communication with memory – Fetching Instructions – Fetching and storing data Interpretation.
Introduction to computers 103 學年度 上學期 Solution of Homework_ch1 授課教授:李錫智.
Computer Systems Week 7: Looping and Input/Output with 3-bit Alma Whitfield.
Model Computer CPU Arithmetic Logic Unit Control Unit Memory Unit
1 Lesson: Applets with User Input and Output with GUI ICS4M.
Introduction to Computers -Final exam- 授課教授:李錫智. Q1 Write a function named Reverse that takes a string as input and returns a copy of that string in reverse.
1 Control Unit Operation and Microprogramming Chap 16 & 17 of CO&A Dr. Farag.
Computer Science 101 Computer Systems Organization ALU, Control Unit, Instruction Set.
A summary of TOY. 4 Main Components Data Processor Control Processor Memory Input/Output Device.
1 CSC 221: Introduction to Programming Fall 2011 Lists  lists as sequences  list operations +, *, len, indexing, slicing, for-in, in  example: dice.
Lecture 161 Lets examine a SPIM program in detail. io.asm This program is a simple routine which demonstrates input/output using assembly code. SPIM.
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 Systems Organization
Introduction to computers 103 學年度 上學期 Solution of Homework_ch12 授課教授:李錫智.
An Example Architecture. A Paper Computer - Woody Woody's characteristics Word size – 8 bits One word.
Data Structures -3 rd test- 2015/06/01 授課教授:李錫智. Question 1 Suppose we use an array to implement a sorted list. Please answer the following questions.
Introduction to Computing Concepts Note Set 14. What if… You had to print “I love Java” to the screen 125 times. How? 125 lines of ▫ System.out.println(“I.
Introduction to Computers -1 st exam- 授課教授 : 李錫智 教授.
Data Structures -3 rd exam- 授課教授:李錫智. 1.[10] Suppose we want to implement a queue by using the following List operations: getLength(); remove(position);
This is where you can reset and run your program. If your program has an “INP” (input) command, you will type it in this box here. Using the LMC These.
Data Structures -1 st exam- 授課教師 : 李錫智 教授. 1.[10] Suppose we have the ADT Bag which has the following operations: bool isEmpty(): tests whether Bag is.
INTRODUCTION TO COMPUTERS
Logic Gates Dr.Ahmed Bayoumi Dr.Shady Elmashad. Objectives  Identify the basic gates and describe the behavior of each  Combine basic gates into circuits.
Mastering LMC Coding Part #1 Introduction to Low Level Languages Introduction to Little Man computer Simple examples (demos) with video tutorials included.
Data Structures -3 rd exam- 授課教師 : 李錫智 教授. 1.[10] Please answer the following questions about queue: [ 2] What is the response of the statement: “(new.
The Postman in your PC Today you are going to learn how a computer’s CPU works to handle data. Teachcompsci.co.uk.
Instruction Memory value Description ADD1xx Add the value stored at memory address xx to the value in the accumulator register SUB2xx Subtract the value.
Exam-like questions.
Dr.Ahmed Bayoumi Dr.Shady Elmashad
Computer Science 210 Computer Organization
Big-O notation Linked lists
CHAPTER 6: The Little Man Computer
Computer Design & Organization
Do it now You will find your do it now task in your workbook – look for the start button! Thursday, 20 September 2018.
Chapter 5 The LC-3.
The Processor and Machine Language
Design of the Control Unit for One-cycle Instruction Execution
Computer Science 210 Computer Organization
Instruction and Control II
Topic 6 LC-3.
CS334: Memory _ Mars simulator Lab 4(part2-2)
Language Constructs Construct means to build or put together. Language constructs refers to those parts which make up a high level programming language.
Program Execution.
Chapter 6 Programming the basic computer
Basic components Instruction processing
Instruction execution and ALU
Little Man Computer.
Presentation transcript:

Introduction to Computers - 4 th exam- 授課教授:李錫智

Hints: ADD [DR] [SR1] [SR2] DR SR1 SR2 SUB [DR] [SR1] [SR2] DR SR1 SR2 LOAD [DR] [MEM] DR MEM STORE [MEM] [SR] MEM SR MOVE [DR] [SR] DR SR HALT where each of the DR, SR, SR1, and SR2 fields contains 2 bits, and each MEM field contains 5 bits.

1.What task would the following assembly-language program perform? LOAD R0 10 ADD R0 R0 R0 STORE 10 R0 HALT Ans: 將 MEM[10] 的值,乘以 4 ,再存回 MEM[10]

2. How many cycles are required to execute the instructions in Problem 1? Describe the settings for each cycle. Ans: 5 cycles. (1) 初始化;執行 Load R0 10 (2) ADD R0 R0 R0 (3) ADD R0 R0 R0 (4) STORE 10 R0 (5) HALT A AddressB AddressALU OpSwitch PosC AddressRW Address A AddressB AddressALU OpSwitch PosC AddressRW Address A AddressB AddressALU OpSwitch PosC AddressRW Address A AddressB AddressALU OpSwitch PosC AddressRW Address A AddressB AddressALU OpSwitch PosC AddressRW Address

3.Write a sequence of assembly-language instructions that would add the contents of memory locations 10 and 11 then store the result in memory location 12. Ans: LOAD R0 10 LOAD R1 11 ADD R2 R0 R1 STORE 12 R2 HALT

4. What sequence of machine-language instructions corresponds to the assembly-language instruction set you wrote in problem 3? Ans: LOAD R0 10  LOAD R1 11  ADD R2 R0 R1  STORE 12 R2  HALT 

5.How many cycles are required to execute the instructions in Problem 4? Describe the settings for each cycle. Ans:5 cycles (1) 初始化; LOAD R0 10 (2) LOAD R1 11 (3) ADD R2 R0 R1 (4) STORE 12 R2 (5) HALT A AddressB AddressALU OpSwitch PosC AddressRW Address A AddressB AddressALU OpSwitch PosC AddressRW Address A AddressB AddressALU OpSwitch PosC AddressRW Address A AddressB AddressALU OpSwitch PosC AddressRW Address A AddressB AddressALU OpSwitch PosC AddressRW Address

6.Consider the following program: Pig Latin function PL(word) { var index; index = word.search(/[aeiouAEIOU]/); if (index <= 0) { return word + "way"; } else { return word.substring(index, word.length) + word.substring(0,index) + "ay"; }

function PP(phrase) { var words, pig, index; words = phrase.split(/[,\n]+/); if (words.length == 0) { return ""; } else { pig = PL(words[0]); index = 1; while (index < words.length) { pig = pig + " " + PL(words[index]); index = index + 1; } return pig; }

Enter a phrase: <input type="button" value="Convert to PL" onclick="document.getElementById('pW').value = PP (document.getElementById('word').value);" /> In PL: What will happen if the user types in the string “Oh, how pretty and handsome you are” and hits the button? Ans: Ohway owhay ettypray andway andsomehay ouyay areway

7.Do the following: (a). Consider the following program: function nsysu(string) { var i, str; str = string; i = str.search(/[aeiou]/); while (i != -1) { str = str.substring(0, i) + "*" + str.substring(i+1,str.length); i = str.search(/[aeiou]/); } return str; } What will be returned for the function call nsysu(“I love nsysu”)? Ans:I l*v* nsys*

7.Do the following: (b). Consider the following program: function IsP(string) { var stripped, front, back; stripped = string; front = 0; back = stripped.length - 1; while (front < back) { if (stripped.charAt(front) != stripped.charAt(back)) { return false; } front = front + 1; back = back - 1; } return true; } What will be returned for the function call IsP(“usysu”)? Ans: True

8.Write a function named Reverse that takes a string as input and returns a copy of that string in reverse order. For example, the function call Reverse("abcd") should return the string "dcba". Ans: Number_8

function Reverse(str) { var len,restr; len=str.length; restr=""; i=len-1; while(i!=-1) { restr=restr+str.charAt(i); i=i-1; } document.getElementById('output').value=restr; } Enter a string: Reverse String:

9.Write a function named Remove that removes all spaces and commas from a given string. For example, the function call Remove(“Hey, you there”) should return the string “Heyyouthere”. Ans: Number_9

function Remove(phrase) { var words=phrase.split(/[,]+/); newphrase=""; index=0; while(index<words.length) { newphrase=newphrase+words[index]; index=index+1; } document.getElementById('output').value=newphrase } Enter a phrase: The result:

10.Consider the following circuit. A, B, and C are inputs. P and Q are outputs. Please list the input-output relationship in a truth table.

Ans: ABCPQ