Ch.2 Instructions: Language of the Computer
sll $t2,$s0,4 # reg $t2 = reg $s0 << 4 bits The first class of such operations is called shifts. They move all the bits in a word to the left or right, filling the emptied bits with 0s. For example, if register $s0 contained 0000 0000 0000 0000 0000 0000 0000 1001two = 9ten and the instruction to shift left by 4 was executed, the new value would be:
0000 0000 0000 0000 0000 0000 1001 0000two= 144ten
Why do we use procedures?
1. clarity 2. reusability
How many bits are in a data word?
32
One major difference between the variables of a programming language and registers is the limited number of registers, typically ____ on current computers, like MIPS.
32
The size of a register in MIPS architecture is ____ bits; groups of ____ bits occur so frequently that they are given the name ____ in the MIPS architecture.
32, 32, word
In MIPS, words must start at addresses that are multiples of ____. This requirement is called an ______ ________, and many architectures have it.
4, alignment restriction
What does AND do?
AND is a bit-by‑bit operation that leaves a 1 in the result only if both bits of the operands are 1. For example, if register $t2 contains 0000 0000 0000 0000 0000 1101 1100 0000two and register $t1 contains 0000 0000 0000 0000 0011 1100 0000 0000two then, after executing the MIPS instruction and $t0,$t1,$t2 # reg $t0 = reg $t1 & reg $t2 the value of register $t0 would be 0000 0000 0000 0000 0000 1100 0000 0000two
Assume variable h is associated with register $s2 and the base address of the array A is in $s3. What is the MIPS assembly code for the C assignment statement below? A[12] = h + A[8];
Although there is a single operation in the C statement, now two of the operands are in memory, so we need even more MIPS instructions. The first two instructions are the same as the prior example, except this time we use the proper offset for byte addressing in the load word instruction to select A[8], and the add instruction places the sum in $t0: lw $t0,32($s3) # Temporary reg $t0 gets A[8] add $t0,$s2,$t0 # Temporary reg $t0 gets h + A[8] The final instruction stores the sum into A[12], using 48 (4 × 12) as the offset and register $s3 as the base register. sw $t0,48($s3) # Stores h + A[8] back into A[12]
Let's assume that A is an array of 100 words and that the compiler has associated the variables g and h with the registers $s1 and $s2 as before. Let's also assume that the starting address, or base address, of the array is in $s3. Compile this C assignment statement: g = h + A[8];
Although there is a single operation in this assignment statement, one of the operands is in memory, so we must first transfer A[8] to a register. The address of this array element is the sum of the base of the array A, found in register $s3, plus the number to select element 8. The data should be placed in a temporary register for use in the next instruction. Based on Figure 2.2, the first compiled instruction is lw $t0,8($s3) # Temporary reg $t0 gets A[8] (On the next page we'll make a slight adjustment to this instruction, but we'll use this simplified version for now.) The following instruction can operate on the value in $t0 (which equals A[8]) since it is in a register. The instruction must add h (contained in $s2) to A[8] ($t0) and put the sum in the register corresponding to g (associated with $s1): add $s1,$s2,$t0 # g = h + A[8] The constant in a data transfer instruction (8) is called the offset, and the register added to form the address ($s3) is called the base register
Why do we not allow blt, bge, etc to be instructions?
Because they would be slow. Then the machine would only use blt and bge.
What does OR do?
It is a bit-by‑bit operation that places a 1 in the result if either operand bit is a 1. To elaborate, if the registers $t1 and $t2 are unchanged from the preceding example, the result of the MIPS instruction or $t0,$t1,$t2 # reg $t0 = reg $t1 | reg $t2 is this value in register $t0: 0000 0000 0000 0000 0011 1101 1100 0000two
bne register1, register2, L1 means?
It means go to the statement labeled L1 if the value in register1 does not equal the value in register2. The mnemonic bne stands for branch if not equal.
What does NOT do?
NOT takes one operand and places a 1 in the result if one operand bit is a 0, and vice versa. In keeping with the three-operand format, the designers of MIPS decided to include the instruction NOR (NOT OR) instead of NOT. If one operand is zero, then it is equivalent to NOT: A NOR 0 = NOT (A OR 0) = NOT (A). If the register $t1 is unchanged from the preceding example and register $t3 has the value 0, the result of the MIPS instruction nor $t0,$t1,$t3 # reg $t0 = ~ (reg $t1 | reg $t3) is this value in register $t0: 1111 1111 1111 1111 1100 0011 1111 1111two
Given: f = ( g + h ) - ( i + j ); The variables f, g, h, i, and j are assigned to the registers $s0, $s1, $s2, $s3, and $s4, respectively. What is the compiled MIPS code?
The compiled program is very similar to the prior example, except we replace the variables with the register names mentioned above plus two temporary registers, $t0 and $t1, which correspond to the temporary variables above: add $t0,$s1,$s2 # register $t0 contains g + h add $t1,$s3,$s4 # register $t1 contains i + j sub $s0,$t0,$t1 # f gets $t0 - $t1, which is (g + h)-(i + j)
What might a C compiler produce from: f = ( g + h ) - ( i + j );
The compiler must break this statement into several assembly instructions, since only one operation is performed per MIPS instruction. The first MIPS instruction calculates the sum of g and h. We must place the result somewhere, so the compiler creates a temporary variable, called t0: add t0,g,h # temporary variable t0 contains g + h Although the next operation is subtract, we need to calculate the sum of i and j before we can subtract. Thus, the second instruction places the sum of i and j in another temporary variable created by the compiler, called t1: add t1,i,j # temporary variable t1 contains i + j Finally, the subtract instruction subtracts the second sum from the first and places the difference in the variable f, completing the compiled code: sub f,t0,t1 # f gets t0 - t1, which is (g + h) - (i + j)
beq register1, register2, L1 means?
This instruction means go to the statement labeled L1 if the value in register1 equals the value in register2. The mnemonic beq stands for branch if equal. if (rs == rt) branch to instruction labeled L1 L1 is the label
Translate this into MIPS language: a = b + c; d = a - e;
add a, b, c sub d, a, e
Which instructions are R-types? add, sub, addi, lw, sw
add and sub
A quick add instruction that is an alternative method that avoids the load instruction is to use one operand as a constant. Like addi $s3, $s3, 4 This is called....
add immediate
Which instructions are I-type? add sub, addi, lw, sw
addi, lw, and sw
A value used to delineate the location of a specific data element within a memory array.
address
A requirement that data be aligned in memory on natural boundaries.
alignment restriction
bit by bit AND in mips
and, andi
What are the 3 types of instructions we need to remember?
arithmetic logic operations ALU, loading and store, making decisions with branches
a sequence of instructions without branches; except possibly at the end, and without branch targets or branch labels, except possibly at the beginning.
basic block
Does MIPS use big-endian addressing or little-endian addressing?
big-endian
MIPS assembly language includes two decision-making instructions, similar to an if statement with a go-to. They are ____ ____ ____ (__) and _______ ___ ______ _____ (__).
branch if equal (beq), branch if not equal (bne)
Virtually all architectures today address individual _______.
bytes
Design 3: Good design demands good _________.
compromises
bne and beq are two instructions that are called ______________.
conditional branches
Processors can only keep a small amount of instructions in registers so how do they handle data structures such as arrays? They are kept in memory. Therefore, MIPS must include instructions that transfer between the processor and memory. Such instructions are called _____ _____ instructions.
data transfer
A command that moves data between memory and registers.
data transfer instructions
IN a load word instruction, the rt field specifies the ___________ register, which receives the result of the load.
destination
Design Principle 2: Smaller is _____.
faster
function. This field often called functon code, selects the specific variant of the operation in the field
funct
Numbers in base 16.
hexadecimal
Instructions are kept in the computer as a series of _____ and ______ electronic signals and may be represented as _______.
high, low, numbers
How do you negate a binary number?
if there's leading 1's replace with 0's, vice versa. Then add 1
What is I-format used for?
immediate and data transfer instructions
A form of representation of an instruction composed of fields of binary numbers.
instruction format
The vocabulary of commands understood by a given architecture.
instruction set
A table of addresses of alternative instruction sequences.
jump address table
The rightmost bit in a MIPS word.
least significant bit
la (pretty important)
load address pseudo code. It takes the address and puts it in a register.
MIPS offers two flavors of byte loads: ___ _____ (__) treats the byte as a signed number and thus sign-extends to fill the 24 left-most bits of the register. _____ ______ _______ (__) works with unsigned integers.
load byte, (lb), Load byte unsigned, (lbu)
The data transfer instruction that copies data from memory to a register is traditionally called load. The actual MIPS name for this is ____, which stands for ______ ______.
lw, load word
Binary representation used for communication within a computer system.
machine language
What happens when you don't put the stack pointer back?
memory leak
The compiler tries to keep the _____ _______ _______ variables in registers and places the rest in memory, using loads and stores to move variables between registers and memory.
most frequently used
The leftmost bit in a MIPS word.
most significant bit
bit by bit NOT
nor
Since registers are referred to in instructions, there must be a convention to map register names into ______. In MIPS assembly language, registers ____ to _____ map onto registers 16 to 23, and registers ____ to ____ map onto registers 8 to 15.
numbers, $s0, $s7, $t0, $t7
for lw $t0, 8($s3) 8 is called the....
offset
Each MIPS arithmetic instruction performs only ____ operation and must always have exactly _____ variables.
one, three
What are the fields for I-format?
op, rs, rt, constant or address 6 bits, 5 bits, 5 bits, 16 bits,
What are the fields for r-format?
op, rs, rt, rd, shamt, funct 6 bits, 5 bits, 5 bits, 5 bits, 5 bits, 6 bits
The field that denotes the operation and format of an instruction.
opcode
The format of a store is similar to that of a load: the name of the ______, followed by the register to be______, then ____ to select the array element, and finally the _____ ______.
operation, stored, offset, base register
bit by bit OR in mips
or, ori
In two's complement representation, the leading 0s mean ______ and leading 1s mean _____.
positive, negative
A stored subroutine that performs a specific task based on the parameters with which it is provided.
procedure
mov
pseudo instruction
the register destination operand. It gets the result of the operation
rd
_________ are primitives used in hardware design that are also visible to the programmer when the computer is completed, so you can think of them as the bricks of computer instructions. The operands of arithmetic instructions are restricted; they must be from a limited number of special locations built directly in this hardware.
registers
Design Principle 1: Simplicity favors _______.
regularity
The first register source operand
rs
the second register source operand
rt
shift amount.
shamt
Shift left logical in mips
sll
The process of putting less commonly used variables or those needed later is called _______ registers.
spilling
shift right logical in mips
srl
The instruction complementary to load is called ______. It copies data from a register to memory. The format is similar to that of load: the name of the operation, followed by the register to be stored, then offset to select the array element, and finally the base register.
store
The idea that instructions and data of many types can be stored in memory as numbers, leading to the stored-program computer.
stored-program concept
The actual MIPS name for store is _____, which stands for _____ ______.
sw, store word
How can arrays and structures exist when registers can only hold a small amount of memory?
they're kept in memory
blt (pretty important)
this does two instructions for you. This is pseudo instruction.
j L1
unconditional jump to instruction labled L1. In high level programming you shouldn't use jumps because then its hard to debug.
The compiler associates ______ with registers.
variables