Chapter 2: Instructions
slt $t0, $s3, $s4 write out the pseudocode and describe what is happening branch on less than?
#t0 = 1 if $s3<$s4 t0 is set equal to one if s3 is smaller than s4 otherwise it is equal 0 this instruction does not exist, this means that another branch would have to be used using t0 to set certain values in another register
what instruction cannot be used in pseudo
$at- reserved for assembler
Why does C provide two sets of operators for AND (& and &&) and two sets of operators for OR (| and ||), while MIPS doesn't?
& and | do bit-by-bit operations, like MIPS' logical operations. && and || compare entire values (vs. bit-by-bit) like branch instructions. Thus, complex C expressions using && and || may be compiled into numerous branch instructions.
general format of how instructions are translated to machine instruction example $t0 $s1 $s2
*first and last for operations* next few are represented as binary numbers
$s0 is reserved for
0
3) What is $s0 after lui $s0, 7 ori $s0, $s0, 8
0000 0000 0000 0111 0000 0000 0000 1000 lui takes 16 bit 7 and is used as the 4 upper bytes of the 32 bit register constant ori simply takes the 16 bit 8 and adds it on top of of $s0
In MPS assembly, $s0 to $s7 registers are mapped to_____
16-23
shifting left by i bits equates to
2^i
an add instruction has fields for how many registers how many bits are used for any of those registers
3 5
32 bit registers holds words of ____bits describe how data is viewed in 32-bit registers
32 bits each register holds 32 bits of data, which is equated to 4 bytes of data or a single word
how many bits are in a register
32 bits wide
registers $t0 - $t7 are mapped to
8 to 15
what do computers offer to represent charcters
8-bit bytes with ASCII standards
Describe how processors program code
A compiler converts high-level language code into low-level language assembly code. Assembly code uses a set of instructions from the processors to define the program This code is put into an operating system loader which loads the program into memory Any data that doesn't fit in the data registers is stored in memory and is accessed through load/store instructions
**what are the lock/unlock operations?** in terms of atomic read and write?
A lock value is read if lock returns 0, the lock is free and memory location is available if lock returns 1 if 1 lock is unavailable
NOT
A logical bit-by-bit operation with one operand that inverts the bits; that is, it replaces every 1 with a 0, and every 0 with a 1
OR
A logical bit-by-bit operation with two operands that calculates a 1 if there is a 1 in either operand.
JVM (java virtual machine)
A program that interprets Java byte codes and executes them.
how are data transfer instructions done?
ALU generates address Address goes to the memory address
ASCII versus Unicode
ASCII has 8-bit bytes encoded character sets while Unicode offers 16 or 32 bit character sets Unicode code is used java and c++
machine langauge
Binary representation used for communication within a computer system
character bit requirements for Java versus C
C requires 8 bits while java requires 16 bits
types of instructions
Data operations Data Transfer Sequencing
beq register1, register2, L1 describe what this entails whats does "beq" mean
If the value in register 1 equals the value in register 2 Go to the statement labeled L1 branch if equal
how is data transferred between a register file and memory
Load (lw instruction) - load data from the memory to the register file Store(sw instruction)-store data from the Register file to memory
describe the MIPS I architecture
Load/Store Register File Machine where instructions compute only on data in the Register file
Do all assembly commands need to be in the Instruction set architecture? What does this mean?
No not all commands need to be in the ISA
describes the three steps for the linker
Place code and data modules symbolically in memory [merging .io files] Determine the addresses of data and instruction labels Patches both the internal and external references
Basic steps for procedure calling
Place parameters in registers or onto the stack Transferring control to the procedure Acquiring storage for procedure Performing procedure operations Placing result in a register (or stack) for caller Return to place of call
MIPS fields and their names(image) what is format of these instructions?
R-type R-format (R stands for register)
what is the meaning of shamt and how many bits
Shift amount 5 bits
Why is memory viewed in 4 byte chunks?
Since one location is 8 bits long, for data to be loaded into a register, 4 of these locations are needed because it takes 4 8 bits of data to make a single word in a 32 bit register
Patches both the internal and external references- what does this mean what kind of labels?
The linker user the relocation information and symbol table in the object module to resolve all undefined labels branch instructions, jump instructions, and data addresses
Just In Time compiler (JIT)
The name commonly given to a compiler that operates at runtime, translating the interpreted code segments into the native code of the compute
How are data operations done describe the role of the: Program counter Instruction register ALU Control logic
There is a program counter that specifies the address of an instruction Instructions are fetched from memory into the instruction register Control logic decodes the instruction and tells the ALU (arithmetic logical unit) what to do and where to read the instructions ALU then executes instructions and results flow back in the register Control updates the program counter for the next instruction
What is a stack pointer
Value denoting the most recently allocated address in a stack that shows where registers should be spilled or where old register values can be found $sp
Mips memory organization for a 32 bit computer, how many memory locations exist?
Viewed as a large 1-D array where each location is one byte(8 bits) A memory address indexes into the array 2^32 -1 memory locations(4294967295)
Translation hierarchy for C describe the process of how code is turned into a program running on a computer
a compiler converts high-level language to assembly An assembler converts assembly to an object module in machine language A linker combines multiple object modules, such as library routines, into an executable machine language program. A loader places the executable file into memory to be run by the computer
instruction format
a form of representation of an instruction composed of fields of binary numbers
what is a stack
a last in first out queue
how are a string of characters stored versus a number (ASII)
a number uses 4 byes while a string of characters can be stored using one byte
what is a leaf procedure
a procedure that does not call another procedure
what is a destination register
a register that receives the result of an operation
what is a symbol table
a table that matches names of labels to the addresses of memory words that instructions occupy
Procedure are ways to implement____in software
abstraction
MIPS assembly language notation to add and describe it's process
add a, b, c instructs a computer to add the sum of variables b and c onto to a
stack push
add elements into the stack
How would you save and restore R16 (how would you push and pop R16 from the stack )
addi $sp, $sp-4 allocating an extra space on the stack sw R16, $sp pushing an element to the stack (loading data from where the stack pointer is) lw R16, $sp "popping" from the stack addi $sp, $sp+4
How many total bits is a machine instruction
adding up all the fields (6+5+5+5+5+6)the answer is 32 for MIPS this is typically 32 bits
what compromise is present in MIPS for the design of instructions
all instructions are kept the same length, thereby requiring different kinds of instruction formats
what is a pseudo instruction
an instruction available in assembly with no actual ISA instruction
what keyword instruction would be used for inequalities and how does MIPS accomplish this **less than
an instruction compares two registers and sets a third register to 1 if the first is less than the second this keyword instruction is called set on less than or slt
Microprocessor without interlocked pipeline stages (MIPS) is an example of____
an instruction set
what is an unconditional branch
an instruction that always follows the branch j Label
What is a conditional branch
an instruction that requires the comparison of two values that allows for a subsequent transfer to a new address in the program based on the outcome of the program
what does jr mean
an unconditional to the address specified in the register this is how an entry jumps back to the register
what is load-linked/ store conditional?
are a pair of instructions used in multithreading to achieve synchronization
what's contained within a jump table
array of words containing addresses that correspond to labels in the code
how are instructions kept in the computer
as a series of high and low electronic signals and may be represented as numbers
debug into for
associating with source code
exchange primitive operations are_____
atomic
C has what two storage classes
automatic and static
what is the meaning of op and how many bits are represented
basic operation of the instruction- usually called opcode 6bits
and logical bit instruction
bit-by-bit operation with two operands that calculates a 1 only if there is a 1 in both operands
if (i==j) f= g+ h;else f = g-h how would this look in assembly? what would the unconditional branch look like
bne $s3, $s4, Else add $s0, $s1, s$2 #f = g+h j Exit Else:sub $s0, $s1, $s2 # f = g Exit **j exit**o- branches past the Else instruction (skips it)
pc-relative addressing
branch address is the sum of the PC and a constant in the instruction
Leaf procedure example(flip)
breakdown in notes
malloc() free()
c functions that allocates and frees space on the heap
function of the linker and the primary purpose
combines multiple object modules, such as library routines, into executable machine language program. To find where symbols and functions are located within all the object modules
what are data transfer instructions
commands that move data between memory and registers
why are instruction sets so similar
computers are constructed from hardware technologies that involve the same principles because all computers provide the same basic operation
bne and beq are classes of
conditional branches
what is an offset
constant value added to base address to locate a particular element [8] A[8] accesses array element
function of the assembler
converts assembly to an object module in machine language
function of the compiler
converts high level language to assembly
operation of store
copies data from a register to memory using sw
describe the process of saving and restoring registers why is this needed
copy a register to memory where they won't be overwritten (saving) copy a register back from memory to the original register (restoring) The callee does not know which registers the caller is using and the caller does not know which registers the callee will use
data access is faster if____
data is in registers instead of memory because registers are faster than memory
describe load format?
data transfer instruction that copies data from memory to a register name of the operation (lw) || register to be loaded || a constant and register used to access memory
what is the header
describes the contents of the object module
to produce the binary version of each instruction in assembly, the assembly must______
determine the addresses corresponding to all labels using the symbol table [found in the object file]
how are the formats distinguished?
distinguished by the values in the first field each format is assigned a distinct set of values in the first field(op)
what does it mean for exchange to atomic
exchange is indivisible, and two simultaneous exchanges are will be ordered by hardware
static variables ?
exist across exist from entries to procedures
what is a CPU register and what's contained within a register
fast locations for data that hold a bit pattern on a processor may hold instructions, storage address, or any kind of data
what is the text segment of the heap
first part of the low end of memory that contains the machine language code for routines in the source file
define word in terms of computer architecture and how many bytes of data are contained within a word
fixed-sized piece of data handled as a unit by the instruction set 4 bytes size of a particular register in register file
$a0 - $a4 are
four argument registers in which to pass parameters
how does a stack grow
from high address to lower addresses
what is an executable file
functional program in the format of an object file that contains no unresolved references
how MIPs access static variables
global pointer
$at is reserved for
handling large constants
6 pieces of the UNIX object file system from top to bottom
header text segment static data segment relocation info symbol table debug info
how does the heap grow compared to the stack
heap grows upward in memory while the stack grows downward
fewer registers would result in a ____clock frequency meaning that
higher less time required to reach each register (smaller is faster)
describe overflow
if the number that is the proper result adding cannot be represented by these rightmost hardware bits
bne register1, register2, L1 describe what this entails and what is the meaning of "bne"
if the value in register 1 does not equal the value in register, go the statement labeled L1 branch if not equal
Differences in how java and c manage data
in C data is managed explicitly while java it is handled implicitly
static linking versus dynamic linking
in static linking, libraries are linked before the program is run, meaning the library is imported into the executable while in dynamic linking, shared libraries are placed in the final executable while the actual linking places at run time Static is faster and begins at beginning of execution while dynamic happens at the end
atomic change and atomic swap
interchanges a value in a register for a value in memory
how is AND called a mask
it "conceals" some bits by forcing a certain bit pattern
what is the meaning of rt in l-format
it is the destination register which is the register that receives that result of an operation
what is the stored-program concept
it's the concept that instructions and data of many types can be stored in memory as numbers, leading to the stored-program computer
MIPS procedure call illustration
jal jumps to the address of the requested function and saves the address of the next main instruction function returns to main with jr$ra
what is a jump-and-link instruction
jumps to an address and simultaneously saves the address of the following instruction in register ($ra) jal
what type of format instruction is used for immediate and data transfer instrsuctions
l-type 1-format
loading and storing bytes lb $t0,0($sp) sb $t0, 0($sp)
lb loads a byte from memory, placing it in the rightmost 8 bits of a register sb means taking a byte from the rightmost 8 bits of a register and writes to memory
what is lui used for and what does it stand for
load upper immediate set the upper 16 bits of constant in a register allowing subsequent instruction (ori) to specify the lower 16 bits of the constant
variables that are local to a procedure but do not fit in register
local arrays and structure
what are automatic varibales
local to the procedure and are discarded when the procedure exits
name an example of an synchronization mechanism
lock and unlock synchronization instructions
load-linked functions as a set of hardware primitives that perform___
lock/unlock operations
how does MIPS deal with static variables and dynamic data structures?
memory allocation at the heap-> allocation similar to a stack as well
what does shift accomplish
moves all bits in a word to the left or right
what does it mean for an instruction pair to be atomic
no other processor can change the value between the instruction pair
Registers names are mapped into___
numbers
what is the meaning of funct and how many bits
often called the function code. selects the specific variant of the operation in the op field
$ra
one return address register to return to the point of origin
base addressing/displacement addressing
operand is at memory location whose address is the sum of a register and a constant in the instruction
function of the loader
places the executable file into memory to be run by the computer
A stack needs a____ to the most recently allocated address in the stack to show _______
pointer where the next procedure should place the registers to be spilled or where old register values are found
what are spilling registers
process of putting less commonly used variables into memory
what are object files?
provides the assembler with information to build a complete program (.io files) the assembler could've made multiple object files based on the code source. It is important to note that each .h file in C is converted to its own object file
what must be done to prevent a data race?
read/write instructions must be synchronized through hardware support
register files versus memory
register files are small and fast while memory is big and slow
what is a base register
register that holds an array's base address
registers vs memory
registers take less time to access and have higher throughput than memory
what registers should be saved in the stack?
registers that are modified by procedures
stack pop
removes an element from the stack
what is alignment restriction what does the offset have to be
requirement that data be aligned in memory on natural boundaries when using load such as lw $t0, offset($s4) the offset needs to be multiples of 4 since memory locations differ by 4 bytes
relocation info
reserved for contents that depend on the location of a loaded program
what happens when a data race occurs
results of the program can change depending on how events happen to occur such as if a program occurs before or after another program
$s0 - $s7
saved registers which must be saved and restored by callee(main)
what is a procedure frame? (activation record)
segment on the stack that contains the procedures' saved register and local variables ($fp)
what is a basic block
sequence of instructions without branches (except possibly at the end) and without branch targets or branch labels
what is critical for implementing synchronization in a multiprocessor
set of hardware primitives that can atomically read and modify a memory location. --> No other accesses to the location allowed between read and write
what does the following instruction accomplish? sll $t2, $s0, 4
shift $s0's value to the left by 4 bits and store the result in $t2
s11 instruction indicates
shift left logical * 2^i adds i bits to the end
sr1 indicates
shift right logical / 2^i add i bits to the front
if you're trying to compare a register to a constant using less than. what would the instruction look like
slit
how would you accomplish #t0 = 1 if $s2 < 10
slt i $t0, $s2, 10
why are argument registers used?
so that procedure can be written independent of regular registers
Ideal data structure for spilling registers
stack
illustration of the heap and stack in memory
stack starts in high end of memory and grows down
what is a base address
starting address of an array in memory
What is stored in Data registers?
store the pieces of data that are being used by the instructions instructions are computed on
what is a procedure
stored subroutine that performs a specified task based on the parameters with which it is provided basically a function
strings in java versus C, operation speed and null character
strings in C uses the null character to mark the end of the string while strings in java reserve the first position of the string to specify the string length Java operations are faster
to know when a task is finished writing so that it is safe for another read is, the tasks need to ______. If they do not, the problem of a _____can occur
synchronize data race
what is a jump address table and how are they used for if else branches
table of alternative sequences the program loads the appropriate entry from the jump table into a register. It then needs to jump using the address in the register
describe the difference in procedure usage for temporary registers($t0-$t9) and saved registers ($s0-$s7)
temporaries($t0) are not preserved by the callee on a procedure call- so if the caller(main) uses these registers, then data must be saved before procedure calls callee saved registers($s0), if callee uses any of these registers, then the callee must saved into the stack before being overwritten and then restored from stack before return
$t0 - $t9
temporary registers can be overwritten by callee
In addition to merging multiple machine modules, the linker also connects to_____
the binary program module library
how many bits are used to indicate that an instruction performs add
the first and last field are used, so 6 +6 12
what is meaning of rs
the first register source operand 5bits
During a procedure call, what kind of data is saved in stack pointer versus a frame pointer
the frame pointer is used to store the location of any saved argument registers, while the stack pointer can store the following: saved return addresses Saved saved registers Local arrays and structures
what is sign extension
the function signed load serves, which is copy the sign repeatedly to fill the rest of register
what does it mean to be _big_endian_
the highest byte is put into the leftmost byte of a word
Describe what this load-linked branch conditional is accomplishing addi $t0,$zero, 1 copy locked value ll $t1, 0($s1) load linked sc $t0, 0($s1) store conditional beq $t0, $zero, again branch if store fails add $s4, $zero, $t1 put load value in $s4 **slide -24**
the load linked instruction is going to ask for the lock value in a location in memory If the lock value is 1, then lock is unavailable
describe immediate addressing
the operand is a constant within the instruction itself
describe register addressing
the operand is a register
what is the meaning of rd and how many bits?
the register destination operand which gets the result of the operation 5bits
what is meaning of rt and how many bits
the second register operand 5bits
define an instruction set
the vocabulary of commands understood by a given architecture
should the caller always save $ra on the stack
this needs to be saved so the callee knows where to return to the caller should save $ra on the stack, and then restore $ra before returning
what are lock and unlock synchronization instruction used for
to create regions where only a single processor can operation -->this is known as mutual exclusion
why does branch on less than not exist?
too complicated, it would either stretch the clock cycle time or it would take extra clock cycles per instruction two faster instructions are more useful
problem with 5 bit registers
too small
what is text segment
translated instructions
describe parallel execution and when is easier?
two or more tasks operating at the same time easier when tasks are independent
when does a data race occur between two or more threads?
two or more threads in a single process access the same memory location One of these memory access writes while the other reads and they occur one after another Threads are not using any exclusive locks to control their access to that memory
$v0-$v1
two value registers in which to return values
How are values pushed and popped from the stack
value are added into the stack by subtracting from the stack pointer (push) values are removed /popped from the stack by adding to the stack pointer the stack pointer needs to move in multiples of 4 because each register is 4bytes
what is frame pointer and where is it located in the stack
value denoting the location of the saved registers and local variables for a given procedure $sp point to the back of the stack (the first word of the frame)
**how would load look like for a 32 bit constant**
what does this accomplish I think: so the bit-immediate operand would be it's binary equivalent in 16 bits[fill to the left with zeros]---> this would specify the lower 16 bits of the 32 bit instruction that would be stored in $s0 Then $s0 would have 32 bits,n with it's first lower 16 bits being the immediate bit operand --> everything in the right would be filled with zeroes
pseudodirect addressing
where the jump address is the 26 bits of the instruction concatenated with the upper bits of the PC
can the compiler use any available register for each variable in a instruction?
yes
how are these slightly different from regular conditionals?
you need to specify the opposite condition that would that would execute a certain statement