Comp 2280 Finals terms and Concepts

ohsobeezee23's version from 2018-04-06 03:17


Question Answer
What is a Von Neumann Machinesingle instruction stream, single data stream SISD
ALUArithmetic Logic Unti
What is the purpose of the ALUperforms the desired operations on the data.
Control UnitCoordinates the activities of the computer system and it's components
Input UnitAccepts coded information from human operators (keyboards, mice, etc)
Output Unit Results are sent to the outside world
Memory UnitInformation to be processed by the central processing unit is stored in main memory
What is a busa series of hardware connections that transport address, data, and control signals to and from devices
Primary memoryfast and expensive, stores progs that are executing and the data they are processing
Secondary storage cheaper and slower, this is your cd's and and dvds
When it comes to instructions and Dataevery Cpu has an ISA which can be used to write programs

Data representation

Question Answer
How do we represent data in a computer1's and 0's based on presence of voltage "1" and absence of voltage "0"
One's complementsPositive #'s begin with a 0, and use the same encoding
Negative numbers use the complement (flip the bits)
eg. 5 = 0101, -5 = 1010
Two's complementTo make negative flip bits and add 1
ex 12 = 01100, -12 = 10011 + 1 = 10100
What is the most significant bitthe bit in a binary number that is of the greatest numerical value.
Benefits of 2's compAllows logic circuits to be kept as simple as possible for doing arithmetic. All arithmetic & logic done by the ALU
Sign Extension (Sext)to add two numbers we must represent them using the same number of bits
if we just pad with zeroes on the left
4 =0100, -4 = 1100
however in 8-bit 4 = 00000100 still true BUT 0000 1100 =12 not 4
what we do instead is replicate the msb until the end so (-4) = 11111100
Overflowoperands are too big, then sum cannot be represented as n-bit 2's comp number
example (8)+(9) = (-15) (imagine binary) sam eis true for vice versa
When do we have overflowsigns of both oprands are the same, and sign of sum is different. (USED AS TEST TO DETECT OVERFLOW)
Another test for overflowthe carry bit into the msb does not equal the carry out bit. IN the above example the two msb 0's yield a 1 and vice versa
What is the AND operator useful for?clearing bits
What is the OR operator useful for?setting bits
What is the NOT operator useful for?flipping bits
What base is Hexadecimal in and what are it's values0-9, and A-F
0xFE6FAE = 16674734 and in binary 1111 1110 0110 1111 1010 1110
Binary to Hexevery four bit is a hex digit start grouping from right hand side
Dealing with decimalsex convert 0.125 to binary representation
0.125*2 = 0.25, so take the 0 bit
0.25*2 = 0.5 so take the 0 bit. continue on until needed
IEEE floating pointMost computers use IEEE-754 encoding [1 sign bit ][ 8 exponent bits ][ 23 fraction bits(for significant digits) ]

IEEE Floating point representation example

eg Encode -65.2 in IEEE format
Question Answer
First stepturn 65 into binary so 10000001
2nd stepturn 0.2 into binary (steps from above) 0.2*2 = 0.4 so we take the 0 etc. etc. until we get 0.00110011....
3rd stepcombine the two 10000001.00110011...
4th stepNormalize (move deciaml point to the msb) 1.0000001.00110011 x 2^6
5th stepthe exponent is 6 and therefore the exponent field will contain 127+6 =133, which is 10000101
6th stepsign bit is 1 (because we negative my guy)
7th stepfinal answer 1 10000101 00000100110011001100110 [s][exp][fraction]

Introduction to Instruction set architecture

LC-3 ISA (Appendix A)
Question Answer
Purpose of ISAprovides the interface between computer programs and the hardware
which part of the ISA is visible to the programmerCPU, where each type of cpu has its own isa
What does the IS in ISA meanthe commands that can be used to program a CPU or the ops that can be performed by the CPU
What does the ISA specifythe instruction set of the computer
the acceptable representation of operands (format of data)
how data is accessed or where it is located
where operands are stored in the CPU
Instructions can be classified asData processing (ALU)
Data storage (Mem instructoins)
Control (comparison/test and branch instructions)
Data movement(I/O instructions)
How is memory layed out in LC316 bits at a time (look at photo)
Registershigh speed storage addressable in a single machine cycle
How many general purpose registers do we have in LC-3eight from r0 to r7
PCprogram counter
IRinstruction register
condition codesN = negative, Z = zero, P = positive
Opcodesthese are the actual instructions available (get into specifics in a bit)
Mnemonicssymbols that correspond to LC-3 instructions
Operandsregisters, numbers, lables
Labelplaced at the beginning of a line assigns symbolic name to the address corresponding to the line
Pseudo-operationsex .fill mnemonics that start with a dot and are used by the assembler
(Come back to this after doing some testing of the labs)

Assembler Directives


Question Answer
.ORIG|Address| starting address of program
.ENDend of program
.BLKW|n| allocate n words of storage
.FILL|n| allocate one word, initialize with value n
.STRINGZ|n-character string| allocate n+1 locations, init chars and null terminator


Question Answer
What is purpose of trapsmechanism for user (unprivileged) code to execute OS (privilaged) code.
In our casetraps provide a way to do I/O and halt the machine
HALTTRAP x25, halts execution and print msg to the console
INTRAP x23, Print prompt on console / read(and echo) one char from kybrd, character stored in R0[7:0]
OUTTRAPx21, write one char (in R0[7:0]) to console
GETCTTRAPx20, Read one char from kybrd, char stored in R0[7:0]
PUTSTRAP x22, write null-terminated string to console, address of string is in R0

Branching and Control Statements

Question Answer
3 condition codes (as mentioned earlier)N-negative, P-positive, Z-zero
Conditional branch instruction formbrX label, where X is either n,z,p,nz,zp, or nzp
Example of a simple loopAND R0,R0,#0
ADD R0,R0,#10
ADD r0,r0,#-1
BRP loop
brnbranch if z=0,n=1,p=0
brzbranch if z=1,n=0,p=0
brpbranch if z=0,n=0,p=1
brnzbranch if (z=1 or n=1) and (p=0)
brnpbranch if (z=0) and (n=1 or p=1)
brzpbranch if (z=1 or p=1) and (n =0)
brnzp (same as br)branch if n=1 or z=1 or p=1 (aka unconditional branch)
JUMP?an unconditional branch that is ALWAYS TAKEN
what does target address in contents of a register meanmeans we can use jmp to go to any register location in range
Why have a jmp and a br?jmp can go beyond -255 to 256 distance where as BR can't // JMP can go anywhere in memory
How do we read from a keyboardusing TRAPx20 or GETC
How do we print to the console?TRAPx22 or PUTS (the string needs to be stored in R0 using LEA instruction)

Intro to digital design and computational circuits


Question Answer
a and b and c can be split like(a and b) and c or a and (b and c)
Combinational circuitoutput depends on only on the current inputs
Sequential circuitoutput depends on current inputs and it's state

Addressing Modes

Question Answer
meaning of EAeffective memory address
why is EA usefulit is the location containing the referenced operand
how many addressing modes does the LC-3 have 5
what are the addressing modesImmediate, Register, Direct/Pc-relative, Indirect, Relative/base+offset
Immediatethe operand is encoded right in the instruction ex) ADD R1,R1,#5 the operand #5 is given immediate mode
Registerthe operand is a register ex) ADD R1,R1,R2 the operand R2 is given in register mode
Direct or Pc - relativeoperand is in memory, where the EA is encoded in the instruction
Relative or base+offsetoperand is in memory, a pointer to the EA is stored in a register
why does LC-3 not support moving from memory to memorybecause this is RISC-type architecture
What are ways LC-3 provides to move data between CPU and memoryLD, LDI, LDR, LEA (move data from memory to CPU) and ST, STI ,STR (move data from CPU to memory)
typical encoding for LD, and ST are[opcode][REG][9 bit offset]
Indirect modeSTI and LDI where EA is stored at the memory location given by adding the 9-bit offset on the instruction to the current value of the PC
what is Load effective address (LEA)allows you to load the address specified by a label
explain what LEA R1,NumArr doesloads r1 with the address of the label NumArr(its memory location)
....Note: dif between this and LD r1,numarr which loads the content of the memory location labeled by NumArr.
Major key use for LEAuseful for loading the address of the start of an array or the address of a string display
base + offset modeLDR and STR, the EA is based on the contents of a specified register instead of the PC. ex) LDR R4,R5,#30
offset mode is useful for?accessing array elements

Subroutines and the Runtime Stack (RTS)


Question Answer
LC-3 has 3 instructions for implementing subroutinesJSR, JSRR, RET
JSRjump to subroutine
JSRRsimilar to JSR except for addressing mode
RETreturn from subroutine
what is a subroutinesimply a jump to a different location (and then jump back to curr location when subroutine is done)
how is the jumping doneby changing the PC register's value
Why is register R7 special?It contains the return address of a subroutine call... Always ensure the value of R7 is the same right before your program executes RET as when you entered the subroutine. Otherwise your program will not be able to return from the subroutine
how would we use JSR and RET togetherex. JSR myFunctionjump to myFunctioncode does it's thingWhen it's finished it will execute RET. This will leave the subroutine and continue execution of the caller
What happens when a RET instruction is executed?value of R7 is copied into the PC (check simple example in NOMAN notes)
Are registers global?Yes
How can we avoid overwriting registers when we use them for a subroutine1. Save the values of the registers at the start of a subroutine, and then restore their values before exiting the subroutine. OR 2. Set aside memory on the runtime stack to use like local variables
Breakdown Saving and restoring registerssubroutines will want access to registers the caller is using
2 options: Callee and Caller
what is the Callee optionthe Callee saves the registers it needs
before starting any computations, save any registers that will be alteredbefore return, restore those same registers
What is the caller optioncaller saves the registers it's usingSave registers if values are needed later
Which one is mostly usedCallee-save approach (and we will use that one as well)
big thing we have to take care of about subroutines internallySAVE ANYTHING THAT THE SUBROUTINE WILL ALTER INTERNALLY!!
If we call any other subroutine or trap in a subroutineWE MUST SAVE R7

Arguments and return values

Question Answer
Arguments arethings we work on (duh)
Return valuesthings we get out of arguments
Where do we put the arguments and return valuesOne place is registers (often r0 but not always), we could also define which registers must contain parameters for a routine (save our curr register contents, load args, and restore register contents)
What is wrong with using registers for passing arguments?anyone can access them and can be easily overwritten

The Runtime Stack (RTS)

Question Answer
Key things we need to use RTSA stack pointer (top), Push/Pop operations, a frame pointer
What is a frame pointerused for working with the current activation record
An activation record (for a subroutine) is the space allocated on the RTS for arguments and return value(s) for the subroutine
Top of memory0x0000
Bottom of memory0xffff
Since LC-3 does not have a dedicated register for stack and frame pointer we useR6 as the stack pointer and R5 as the frame pointer
SP (stack pointer)R6
FP (frame pointer)R5
Stack pointer always points where?to the top of the stack
Implement PushADD R6, R6 #-1
STR Rx,R6,#0 ;this pushes Rx onto the stack (look at example in notes)
Implement PopLDR Rx, R6,#0
ADD R6,R6,#1 ; this pops item at top of stack into Rx (look at example in notes)
How are we saving info with push and popSave most registers before using them i.e.
R6 is global so you shouldn't use it as a general purpose register in your subroutine
R0 is often used for return value, but not always (depends on contract between caller and callee)
What is the basic Idea of thisWe push each register we intend on using within a subroutine onto the stack at the start of the subroutine
before the call to RET, pop the regisers in the reverse order that they were pushed onto the stack

RTS Frame pointer

Question Answer
What is an activation recordWhenever a subroutine is called, certain info used by the subroutine needs to be provided (on the stack) -> includes arguments and we need space to store a return value (if not in R0)
How to use the frame pointer1.Push arguments onto the stack before the subroutine call
2.Set aside space on the stack for return values if necessary
3.Set Aside space on the stack for return values if necessary
3. The items of the previous step form the activation record for the subroutine call
4. In our subroutine, save the val of FP and then set FP to point to the last item put on the activation record
5. Push any other registers values onto the stack as necessary
6. Write subroutine's code
7 Before the RET instruction, adjust R6 as neessary depending if local vars were set aside or not and then restore registers values.
8. In the caller: copy the return value if any from the stack
9. in the caller: adjust the stack pointer R6 to remove argumetns and return values from the stack
please go over example code
how to call routines from routinesMust save value of R7 (it contains the return address of a subroutine call)
before calling a routine from the current routine, push R7 onto the stack before pushing arguments onto the stack, this should be one where you saved the registers used by the subroutine
Upon return from routine call, pop the args and restore register R7, should be done where you restore registers from the stack

Pt 2

Question Answer
part 2