Week 6 CMPE 12 Notes
Week 6 CMPE 12 Notes CMPE 12
Popular in Comp Sys/Lang Lab
Popular in Computer Science and Engineering
This 16 page Class Notes was uploaded by Shanee Dinay on Sunday February 14, 2016. The Class Notes belongs to CMPE 12 at University of California - Santa Cruz taught by Dunne,M.J. in Winter 2016. Since its upload, it has received 176 views. For similar materials see Comp Sys/Lang Lab in Computer Science and Engineering at University of California - Santa Cruz.
Reviews for Week 6 CMPE 12 Notes
Report this Material
What is Karma?
Karma is the currency of StudySoup.
You can buy or earn more Karma at anytime and redeem it for class notes, study guides, flashcards, and more!
Date Created: 02/14/16
Day 11 2/9/2016 CMPE 12 Midterm in One Week Review Next Class (should take most of class time) Will go over most of the problem types expected No homework this week due to Midterm ALU Lab Extended until 19th Solutions for Homeworks and Quizzes should go up tomorrow Simple LC3 Program Program Execution assembler translates to executable machine language linker combines multiple LC3 giles if any loader puts executable into memory and makes the CPU jump to first instruction, .ORIG executes when executing is done returns controls to OS or simulator or monito load again to run again with different data in this case, assemble again, too, since data is in program HLL if/else statements if (condition) statement else statement “C” if(count < 0) count = count + 1; “LC3” LD R0, count BRpz greatzero ADD R0, R0, #1 greatzero ; next instruction goes here Loops loops can be built out of IF’s WHILE “C” while (count > 0) a = a + count; count; “LC3” LD R1, a LD R0, count while BRnz endwhile ADD R1, R1, R0 ADD R0, R0, #1 BR while endwhile ST R1, a ST R0, count what is BR by itself? Branch unconditional, it is equal to BNZP Procedure Calls simple procedure calls require 2 instructions: “JSR” or “JSRR” Jump Service Routine saves the return address into R7 “RET” Jump Return be careful with registers!! cannot nest unless R7 is saved elsewhere cannot be recursive without a stack Example Repeat Loops Do While Loop “C” “LC3” For Loops “C” for (i 3; i <= 8, i++) a = a +i; “LC3” we use BRz so have our loops count down to zero! TRAP (system calls) very tedious and dangerous for a programmer to deal with IO at the OS level need an instruction though to get the attention of the OS use the TRAP instruction and a “trap vector” ASCII Codes are all within A bits Size of LC3, 16 bits To print a character ; the char must be in R0 TRAP x21 or OUT To read in a character ; will go into R0, no echo. TRAP x20 or GETC No Echo = you will not seen anything printing on the screen To end your program: TRAP x25 or HALT LC3 first program we will write always need in our program .ORGx300 HAL .EN we will need these three in all our programs “HelloWorld” program .ORGx300 LEAR0 ELLO HAL HELO .TRINZ “ELL WORD\n” .EN System Calls (TRAPS) and Subroutines Chapter 9 certain operations require specialized knowledge and protection specific knowledge or I.O device registered and the sequence of operations need to use them I/O resources shared among multiple users/programs, a mistake could affect lots of other users! not every programmer knows (or wants to know) this level of detail provide service routines or system calls (part of operating system) to safely and conveniently perform lowlevel, privileged operations System Calls (service routines) 1. user program invokes system call 2. operating system code performs operation 3. returns control to user program LC3 TRAP Mechanism 1. a set of service routines part of operating system routines start at arbitrary addresses system code by convention is typically below address x3000 up to 256 routines 2. table of starting addresses stored at x0000 through x00FF in memory 3. TRAP instruction used by user program to transfer control to operating system 8 bit trap vector names one of the 256 service routines 4. a linkage back to the user program want execution to resume immediately after the TRAP instruction TRAP Instruction trap vector (trapvect8) identifies which system call to invoke 8bit index into table of service routine address in LC3 this table is tored in memory at 0x0000 0x00FF where to go lookup starting address from table, place in PC how to get back saves address of next instruction (current PC) in R7 before changing PC RET (JMP R7) how do we transfer control back to instruction following the TRAP? save old P Cin R7 JMP R7 gets us back to the user program at the right spot LC3 assembly langugae lets us use RET (return) in place of “JMP R7” must make sure that service routine does not change R7 or it won’t know where to return Trap Mechanism Operation Example: Using the TRAP Instruction The OUT Service Routine TRAP Routines and their Assembler Names Saving and Restoring Registers must save the value of a register if: its value will be destroyed by service routine, and we will need to use the valye after that action Who saves? caller of servicec routine? knows what is needs later, but may not know what gets altered by called routine called service routine? knows what it alters, but does not know what will be needed later by calling routine Example Saving and Restoring Registers Called routine “calleesave” before start, save any registers that will be altered before return, restore those same registers Calling routine “callersave” save registers destroyed by own instructions or by called routines (if known), if values needed later save R7 before TRAP save R0 before TRAP x23 (input character) or avoid using those registers altogether Question can a service routine call another service routine? sure, PUTS calls OUT If so, is there anything special the calling service routine must do? better save R7 What about User CODe? Service routines provide three main functions: 1. shield programmers from systemspecific details 2. write frequentlyused code just once 3. protect system resources from malicious/clumsy programmers Are there any reasons to provide the same functions for nonsystem (user code) YES Subroutines A subroutine is a program fragment that: lives in user space performs a welldefined task is invoked (called) by another user program returns control to the calling program when finished Like a service routine but not part of the OS not concerned with protecting hardware resourses Reasons for subroutines reuse useful code without having to keep typing it in JSR Instruction jumps to a location (like a branch but unconditional), and saves current PC in R7 saving the return address is called “linking” target address is PCrelative bit 11 specifies addressing mode JSRR Instruction just like JSR, except Register addressing mode target address is Base Register bit 11 specifies addressing mode Returning from a Subroutine RET (JMP R7) gets us back to the calling routine just like the TRAP does Example: Negate the value in R0 Passing Information to/from Subroutines Arguments a value passed in to a subroutine is called an argument this is a value needed by the subroutine to do its job ex: in 2's Comp routine, R0 is the number ot be negated in OUT service routine, R0 is the character to be printed Return Values a value passed out of a subroutine is called a return value this is the value that you called the subroutine to compute ex: in 2's Comp routine, negated value is returned in R0 Using Subroutines in order to use a subroutine, a programmer must know: its address (or at least a label that will be bound to its address) its function (what does it do) the programer does not need to know how the subroutine works, but what changes are visible in the machine’s state after the routine has run its arguments (where to pass data in, if any) its return values (where to get computed data, if any) Saving and Restore Registers since subroutines are just like service routines, we also need to save and restore registers, if needed generalled use “calleesave” strategy, except for return values save anything that the subroutines will alter internally that shouldn’t be visible when the subroutine returns it’s good practice to restore incoming arguments to their original values Remember: you must save R7 if you call any other subroutine or service routine Example: CountChar Algorithm Day 12 2/11/2016 CMPE 12 Max Dunne Midterm Overview no books, notes, or calculators show your work no credit if we don’t know how you did something lots of partial credit no timing diagrams no ascii Solutions all the homeworks 1 4 solutions Transistor and Gates Truth Table to Gates A B F 0 0 1 0 1 1 1 0 0 1 1 1 Transistor and Gates Truth Table to Transistors A B F 0 0 1 0 1 1 1 0 0 1 1 1 Transistors and Gates Transistors to truth Table we will be given a not “basic” gate look and simplify it if you can Logic Elements to Gates Draw the gate level diagram of a 24 decoder be familiar with MUXs, DECODERS, etc have a better understanding of how each one works know all the logical elements PoS and SoP A B C F 0 0 0 0 0 0 1 1 0 1 0 0 0 1 1 1 1 0 0 1 1 0 1 1 1 1 0 0 1 1 1 1 SoP: find all the rows that have “1” and we want to write the products of those rows look at each row and write it out in boolean algebra A’B’C + A’BC + AB’C’ + AB’C + ABC tick marks, do the bars for the exam PoS: look for the “0”s, we write out the inverted expression (A + B + C)(A + B’ + C)(A’ + B’ + C) Label Please, whether you are doing SoP and PoS There will be a problem with the big diagram given a command and point out what lines are being used for lets do NOT for example: NOT R0 R1 we are going to have an instruction register program counter is going to have its little loop these are the major ones what are we doing with the NOT? we are going to invert we are going to use the ALU the remainder we need to do, record it back, it progresses along the bust, it goes back in the ALU ask for values: they will say R0 = xfff they want us to write down where the values go PC counter increments by one might be a memory, might be … not control instructions so not xffff → x0000 labels: 1 and 0, source registers and other one… Given entire the LC3 Instructions given boolean algebra all instructions we won’t be writing programs on the midterm we will be given 16 bit binary numbers and asked to translate it R3 = R2 + R1, given binary code of command and we translate to what is actually going on. Understand how off codes work Major one we want to look at, boolean algebra, and number representations Conversion Tables Base Conversion Table 8 Bits Decimal 1’s Complement 2’s Complement Signed Magnitude 35 11011100 11011101 10100011 X 0110 0001 X 1001 1101 X 10011101 we will have a bias one as well 35 → 1’s 00100011 binary 11011100 that is the 1’s complement add ‘1’ to get the 2’s complement 11011101 this is 2’s complement now we want signed magnitude start with unsigned: 00100011 change the last number to a 1: 10100011 now we want to do Bias 46, we add 46 35 + 46 = 11 then we write it in binary: 00001011 this is 35 in bias 46 Arbitrary Base Conversion 1210 3in base 10 we will not have 3 powers of 3: 1 3 9 27 1 x 27 + 2 x 9 + 1 x 3 + 0 x 1 27 + 18 + 3 + 0 = 48 10 4810to base 3 one way we can do this is subtracting, easy another way is successive divisions: we will get remainder 48 / 3 = 16 remainder 0 → 0 16 / 3 = 5 remainder 1 → 1 5 / 3 = 1 remainder 2 → 2 1 / 3 = 0 remainder 1 → 0 Binary Arithmetic unsigned 2’s complement signed magnitude expect the same table for the homework Fractional Representation 4.6 in Base 2? take the whole portion and write it in binary: 100. take .6 .6 → 1.2 → 1 .2 → .4 → 0 .4 → .8 → 0 .8 → 1.6 → 1 .6 repeat 100.1001 Binary Division 11 √ 101110111 → the answer is 1111101 Boolean Algebra XY + X(Y + Z) + Z(X + X) + (X + X’)YZ + Y + Y’Z we will have three or four terms XY + X(Y + Z) + Z(X + X) + (X + X’)YZ + Y + Y’Z XY + XY + XZ + ZX + YZ + Y + Y’Z → X+X = X, X + X’ = 1 XY + XZ + YZ + Y + Y’Z XY + XZ + Z(Y + Y’) + Y XY + XZ + Z + Y XZ + Z + XY + Y Z(X + 1) + Y(X + 1) → X + 1 = 1 Z + Y
Are you sure you want to buy this material for
You're already Subscribed!
Looks like you've already subscribed to StudySoup, you won't need to purchase another subscription to get this material. To access this material simply click 'View Full Document'