







Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!








What is the decimal equivalent of the IEEE-754 floating point number: 1 10000000 10010000000000000000000 -3. Convert the decimal number #-476 to a 12-bit twoâs complement binary number, and Represent the result as hexadecimal xE Given the instruction (located at address x3500) X3500 LDI R1, label
And given: Label1 translates to address x35A0, which contains the value xC000; Memory location xC000 contains the value xD000; Memory location xD000 contains the value xFFFF;
What value will R1 contain after the instruction executes? xD
Simplify the Boolean expression: a.bâ.câ.d + a.bâ.c.d + a.b.câ.d + a.b.c.dâ + a.b.c.d a.d + a.b.c How many memory locations can be addressed by a microprocessor that uses 24 bit
Addressing? 16 M
How many select lines does an 8 input multiplexer have? 3
How many input lines does an 8 input multiplexer have? 8
How many output lines does an 8 input multiplexer have? 1
How many inputs does a full adder circuit have? 3 A âgate delayâ can be described as the time needed for the output of a gate to settle to its Correct level after one of its inputs has been changed. The full-adder circuit we have Designed would therefore result in a gate delay of 2 units.
How many units of gate delay would a 4-bit ripple-adder display? 8
How do we turn 8 separate gated D-latches into a single 8-bit register? (WE = âWrite Enableâ) Connect their WE lines together to a single external WE
How do we turn 8 separate gated D-latches into 8 addressable registers, each 1-bit wide? Connect the WE of each one separately to an output of a 3-bit decoder, and multiplex their outputs with The same decoder The following very complex subroutine moves the cursor down to the next line. What, if
Anything, is wrong with it? .ORIG x NEWLINE LD R0, CRLF
CRLF .FILL x0A c. it should save and restore the contents of R d. it should save and restore the contents of R both c) and d) A subroutine was called using a conditional branch (BR) instruction. The subroutine ends,
As usual, with a RET instruction. What will happen when the subroutine terminates? Control will return to an unknown instruction, either crashing the program or producing unpredictable Results. Consider the controller of an elevator that connects the 1st, 2nd, 3rd & 4th floors of a building as An example of a finite state machine. The states of this FSM correspond to the elevator stopped at each of the four floors, either With the doors closed, or with the doors open (i.e. âdoors openâ and âdoors closedâ are Separate states). Transitions between states will thus correspond to the elevator moving between floors, Including âexpressâ transitions between non-adjacent floors, and opening and closing doors While stopped at any given floor (obviously, the elevator can move only if the doors are closed) External inputs are determined by the elevator call buttons.
How many separate states does this finite state machine have? 8 How many distinct transitions are there between states (not including ânull transitionsâ, i.e.
Transitions from a state back to itself)? 20
How many bits would the Storage Logic component of the fsm have to store? 3 A computer system has a word addressable memory. Each word is 32 bits (4 bytes) wide.
There are 24 memory address lines. What is the maximum available system memory? 64M bytes A computer system has a word addressable memory. Each word is 32 bits (4 bytes) wide.
There are 24 memory address lines. How many data lines are required for the system in the previous question? 32 A computer system has a word addressable memory. Each word is 32 bits (4 bytes) wide. There are 24 memory address lines. If the system in the previous questions were instead byte-addressable, and were to retain
The same total number of bytes of memory, how many address lines would it require? 26 Given a very peculiar memory system that uses 22 bit-addressing, and is âthree-bitâ Addressable (i.e. each location in memory stores 3 bits), how many bits of storage does
The memory contain in total? 12 Mbits The central idea in the von Neumann model is that the program and data both reside in: Memory A certain ISA has a 32-bit word size, uses single word (32-bit) instructions, has 60 opcodes, 32 Registers, and 4Gbyte of byte-addressable memory.
Each instruction consists of up to 6 steps One of the four control signals to the LC-3 ALU is âpass-through input Aâ â i.e. input A is Connected directly to the output.
Which of the following instructions would use this control signal? ST, STI & STR In the LC-3, the DR decoder input comes from the DRMUX. What are two of the inputs to The DRMUX? (Hint: think about the JSR and TRAP instructions) [111] and IR[11:9] In the LC-3, the SR1 decoder input comes from the SR1MUX. What are two of the inputs to The SR1MUX? (Hint: think about the load and store instructions) IR[8:6] and IR[11:9] In the LC-3 (and most ISAs), the System Control Block, or Trap Vector Table, contains: The starting addresses of the Trap Service Routines
What is the main purpose of the first pass of a two-pass assembler? To build a symbol table relating labels to memory addresses In a cpu that uses the technique of memory mapping to address ports (registers that
Interface between the cpu and peripherals), how must the ports actually be accessed? Via standard Load/Store instructions What component of the cpu gets âinterruptedâ by an Interrupt signal? (i.e. where does the Interrupt signal go to?) The FSM
In Interrupt processing, what is the purpose of the IACK signal? It polls multiple peripherals to find which initiated an interrupt In the LC-3, the TRAP instruction and the interrupt handler both manage the invocation of
Service routines in a similar fashion. Specifically, both use: A trap/interrupt vector as an entry point into a table of service routine addresses What system state information has to be saved before an interrupt-enabled LC-3 can
Proceed with servicing an interrupt? The PC, and the PSR (Processor Status Register, containing the NZP condition codes, the Privilege level, And the current task priority)
At what point in the instruction cycle is an interrupt handled? Only at the very start of the fetch instruction phase The data protocol of a stack data structure is known as LIFO (Last In, First Out) The two main approaches to converting a HLL source code to ML (Machine Language) are: Interpreting and compiling The structure which allows Higher Level Languages to make nested function calls is: Activation records stored on the run-time stack Which LC-3 assembly language instruction is most likely to be used to compile a HLL
(Higher Level Language) access to a local variable: LDR Which register is most likely to be used as the Base Register in accessing the variable, in
The situation described in the previous question? Frame pointer (R5 in the LC3) Exam 2 Iteration with mutated lists
If you use a for loop on a list where the list is mutating inside the for loop: -the length of the list (if called in the FOR loop) will NOT change and will remain the same as the length of the original list for I in range(len(lst)) will take in the length of the original list -the length of a list, if called in a WHILE loop will call the mutated version of the list and you risk an infinite loop Append(el) Add el to the end of the list; this is mutative. Return None Iterable Any object where calling the built in Iter function on it returns an itetor; any Python object capable of returning its members one at a time, permitting it to be iterated over in a for-loop. Common iterables are ranges and lists Operand One of the values on which an operator operates. Abstract Data Type (ADT) A container whose properties (data and operations) are specified independently of any particular implementation .extend vs .append Both are mutative and both return None. However, .append appends ONE item to the end of the list (could be a nested list) whereas .extend adds every element to the list Dictionaries -Dictionaries are used to store data values in key:value pairs. -A dictionary is a collection which is ordered, changeable and does not allow duplicates. -dictionaries are written with curly brackets Image: dictionaries Tuple A native type in Python that can store a collection but cannot assign new values to individual elements. Basically a list that cannot be changed. To create a tuple itâs defined in parentheses not brackets Exam 3 Primitive expressions and statements Which represent the simplest building blocks that the language provides Means of combination By which compound elements are built from simpler ones Means of abstraction By which compound elements can be named and manipulated as units Infix operators In infix notation, unlike in prefix or postfix notations, parentheses surrounding groups of operands and operators are necessary to indicate the intended order in which operations are to be performed. Expression Describes a computation and evaluates to a value Evaluation Procedure When evaluating nested expressions
To evaluate a call expression, Python will do the following: Evaluate the operator and operand subexpressions, then Apply the function that is the value of the operator subexpression to the arguments that are the values of the operand subexpressions.
Function definition is a more powerful means of abstraction: binds names to expressions. A much more powerful abstraction technique by which a name can be bound to compound operation.
Abstraction
Taking something complex giving it a to a name and treating it is a whole without worrying about all of it details
Name Evaluation
A name evaluates to the value bound to that name in the earliest frame of the current environment in which that name is found.
Model of evaluation
Our conceptual framework of environments, names, and functions constitutes a model of evaluation; while some mechanical details are still unspecified (e.g., how a binding is implemented), our model does precisely and correctly describe how the interpreter evaluates call expressions. In Chapter 3 we will see how this model can serve as a blueprint for implementing a working interpreter for a programming language.
Scope
We say that the scope of a local name is limited to the body of the user-defined function that defines it. When a name is no longer accessible, it is out of scope. This scoping behavior isnât a new fact about our model; it is a consequence of the way environments work.
Aspects of functional abstraction
Aspects of a functional abstraction. To master the use of a functional abstraction, it is often useful to consider its three core attributes. The domain of a function is the set of arguments it can take. The range of a function is the set of values it can return. The intent of a function is the relationship it computes between inputs and output (as well as any side effects it might generate). Understanding functional abstractions via their domain, range, and intent is critical to using them correctly in a complex program.
For example, any square function that we use to implement sum_squares should have these attributes:
The domain is any single real number.
The range is any non-negative real number.
The intent is that the output is the square of the input.
These attributes do not specify how the intent is carried out; that detail is abstracted away.
True division (decimal division) The / operator
>>> 2013/
From operator import truediv
>>> 1 / 5
>>> 25 / 4
>>> 5 / 0
ZeroDivisionError
Floor division (integer division) The // operator
>>> 2013//
201
Only gives the number of times that the divisor (10) goes into the dividend (2013) not including any remember so we lost the.
From operator import floordiv
Mod operator
Gives the remainder
From operator import mod Guide to designing a good function Functions are an essential ingredient of all programs, large and small, and serve as our primary medium to express computational processes in a programming language. So far, we have discussed the formal properties of functions and how they are applied. We now turn to the topic of what makes a good function. Fundamentally, the qualities of good functions all reinforce the idea that functions are abstractions. Each function should have exactly one job. That job should be identifiable with a short name and characterizable in a single line of text. Functions that perform multiple jobs in sequence should be divided into multiple functions. Donât repeat yourself is a central tenet of software engineering. The so-called DRY principle states that multiple fragments of code should not describe redundant logic. Instead, that logic should be implemented once, given a name, and applied multiple times. If you find yourself copying and pasting a block of code, you have probably found an opportunity for functional abstraction. Functions should be defined generally. Squaring is not in the Python Library precisely because it is a special case of the pow function, which raises numbers to arbitrary powers. Control Statements They are statements that control the flow of a programâs execution based on the results of logical comparisons. Statements differ fundamentally from the expressions that we have studied so far. They have no value. Instead of computing something, executing a control statement determines what the interpreter should do next. To execute a sequence of statements To execute a sequence of statements, execute the first statement. If that statement does not redirect control, then proceed to execute the rest of the sequence of statements, if any remain. This definition exposes the essential structure of a recursively defined sequence: a sequence can be decomposed into its first element and the rest of its elements. The ârestâ of a sequence of statements is itself a sequence of statements! Thus, we can recursively apply this execution rule. This view of sequences as recursive data structures will appear again in later chapters. Statement A statement is executed by the interpreter to perform some action So far weâve seen assignment statements def statements return statements Boolean contexts Above, the execution procedures mention âa false valueâ and âa true value.â The expressions inside the header statements of conditional blocks are said to be in boolean contexts: their truth values matter to control flow, but otherwise their values are not assigned or returned. Python includes several false values, including 0, None, and the boolean value False. All other numbers are true values. In Chapter 2, we will see that every built-in kind of data in Python has both true and false values. Boolean Values Python has two boolean values, called True and False. Boolean values represent truth values in logical expressions. The built-in comparison operations, >, <, >=, <=, ==, !=, return these values.
To evaluate the expression and :
To evaluate the expression or :
functions that are associated with a local environment. In the call Hence, we realize two key advantages of lexical scoping in Python. The names of a local function do not interfere with names external to the function in which it is defined, because the local function name will be bound in the current local environment in which it was defined, rather than the global environment. A local function can access the environment of the enclosing function, because the body of the local function is evaluated in an environment that extends the evaluation environment in which it was defined. The sqrt_update function carries with it some data: the value for a referenced in the environment in which it was defined. Because they âencloseâ information in this way, locally defined functions are often called closures. Closures The sqrt_update function carries with it some data: the value for a referenced in the environment in which it was defined. Because they âencloseâ information in this way, locally defined functions are often called closures.
From Wikipedia: In programming languages, closures (also lexical closures or function closures) are a technique for implementing lexically scoped name binding in languages with first-class functions. Currying We can use higher-order functions to convert a function that takes multiple arguments into a chain of functions that each take a single argument. More specifically, given a function f(x, y), we can define a function g such that g(x)(y) is equivalent to f(x, y). Here, g is a higher-order function that takes in a single argument x and returns another function that takes in a single argument y. This transformation is called currying.
Taken from Wikipedia: In mathematics and computer science, currying is the technique of translating the evaluation of a function that takes multiple arguments (or a tuple of arguments) into evaluating a sequence of functions, each with a single argument (partial application). First-Class Status In general, programming languages impose restrictions on the ways in which computational elements can be manipulated. Elements with the fewest restrictions are said to have first-class status. Some of the ârights and privilegesâ of first-class elements are: They may be bound to names. They may be passed as arguments to functions. They may be returned as the results of functions. They may be included in data structures. Python awards functions full first-class status, and the resulting gain in expressive power is enormous A functionâs domain A functionâs domain is the set of all inputs it might possibly take as arguments. A functionâs range A functionâs range is the set of output values it might possibly return. Applying a user-defined function -Create a new frame -Bind formal parameters to arguments -Execute the body Exam 4
Rewrite without assignment: >>> square = lambda x: x * x >>> square(2)
(lambda x: x * x)(2) >>> print(print(1), print(2)) 1 2 None None >>> two = print(2) >>> print(two) 2 None 1/0 or True Zero Division Error
>>> def go(n):
⌠if n % 2 != 0: ⌠print(n / 2) ⌠return
⌠while n > 0: ⌠print(n) ⌠n = n // 2 >>> go(4) >>> go(5) 4 2 1
⌠print(âbigâ) ⌠return âbigâ Big âbigâ
>>> def function(): ⌠return âbobâ >>> a = function [What does this print, if anything?] >>> a = function() [What does this print, if anything?] The first âaâ points to âfunction.â The second âaâ wonât return anything, until âaâ is explicitly called.
>>> def function(): ⌠print(âbobâ) The first âaâ points to âfunction.â The second âaâ prints âbob,â but doesnât has a return value of None. >>> (lambda: 3)() 3 >>> b = lambda x: lambda x >>> c = b(88) >>> c >>> c() Function 88 >>> z = 3
2) Each name is bound to a�
Whatâs the execution rule for assignment statements?
Assignment is a simple means of� Abstraction: it binds names to values
Function signatures contains� The function name and formal parameters (how many arguments it will take)
Function body defines/contains� The computational process expressed by the function
Whatâs the execution procedure for def statements?
Whatâs the procedure for calling/applying a user-defined function?
Is a function body needed to create a local frame? No, the signature has all the information needed to create a local frame
Whatâs the context in which every expression is evaluated? Its current environment (global or local frame)
What is an environment? A sequence of frames
If there are duplicate name-value pairs in different frames of the same environment, which value would names evaluate to? To the value bound to that name in the earliest frame of the current environment in which it resides
What does return function do? It brings information from local frame back into frame that was the current frame where function was called