Chap 2 - PART 1 - Language of the Computer Flashcards

1
Q

Image showing a Simplified Overview of compiling your program

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Image:

Assembly language

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

List the characteristics of the assembly language:

RISC

A

RISC: Reduced Instruction Set Computer

  • Provides a small set of instructions, each designed to attain a small task
  • The programmer may need to use more instructions to complete some given task
  • Less straining on the hardware
    • eg. MIPS, ARM, RISC-V
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

List the characteristics of the assembly language:

CISC

A

CISC: Complex Instruction Set Computer

  • Provides instructions skilled in executing multi-step operations
  • Same task can be achieved using less instructions than RISC
  • Difficult to implement on the hardware
    • eg. x86
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Image:

Table showing the differences between RISC vs CISC

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Describe the arithmetic operations:

State: Design Principle 1

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Arithmetic Example:

  • C Code:

f = (g+h) - (i+j);

  • Compile the code above to MIPS Code
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Describe: Registers

A
  • This refers to the small bit of memory in the cetral processing unit (CPU)
  • It is used in assembly language to perform different instructions
  • Limited number of special locations built directly into the hardware
  • Operations can only be performed on these; registers are the tiniest, fastest, and most expensive type of memory

Benefit:

  • Since registers are directly in hardware, they are very fast (faster than 0.25ns)
  • Unlike HLL like C or Java, assembly cannot use variables
    • why not? find out? maybe to keep hardware simple?
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Image:

Registers inside the processor

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q
  • State the drawback of registers:
  • State the solution for this drawback:
  • Why are there 32 registers only in MIPS
  • What is a group of 32 bits called?
A
  • Since registers are in hardware, there is a predetermined number of them, hence, limited.
  • The solution is that MIPS code must be very carefully put together to efficiently use registers. In other words, the power is in the hand of the programmer.
  • 32 bits because smaller is faster, however, too small is bad
  • group of 32 bits is called a word. EACH MIPS register is only 32 bits wide.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Describe:

the Constant Zero

A

MIPS register 0 ($zero) is known as the constant zero

  • it cannot be overwritten

Useful for common operations

  • eg. Move between registers
    • add $t2, $s1, $zero
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Image:

Register usage

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

About register operands:

  • what types of instructions uses register operands?
  • Describe the characteristics of MIPS that has a 32x32 bit register file
A
  • arithmetic instructions
  • Use for frequently accessed data ; numbered 0 to 31
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

List the Assembler names for register operands

A

$t0, $t1, … $t9, for temporary values

$s0, $s1, …, $s7, for saved variables.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

State:

the design principle 2

A

Smaller is faster:

  • c.f. main memory: millions of location
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Register Operand Example:

  • C code:
    • f = ( g + h ) - ( i + j );
    • f, …., j in $s0, …, $s4
  • Compile the code above in MIPS
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

List the main memory that is used for composite data

A
  • arrays
  • structures
  • dynamic data
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q
  • How to apply arithmetic operations? What are the steps?
A
  • Load values from memory into registers
  • Store result from register to memory
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

Memory is byte addressed, each address identifies an?

A

each address identifies an 8 bit style

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

Words are aligned in memory, therefore, address must be a multiple of?

21
Q

MIPS is Big ____

why?

A

Endian

because most significant byte at lowest address of a word

22
Q

Memory Operand Example 1

C code:

  • g = h + A[8];
  • g in $s1, h in $s2, base address of A in $s3

Compile the code above in MIPS code:

  • Note that: index 8 requires offset of 32
  • There are 4 bytes per word
23
Q

Memory Operand Example 2

Code:

  • A[12] = h + A[8];
  • h in $s2, base address of A in $s3

Compile the code above in MIPS code:

  • Note that: Index 8 requires offset of 32
24
Q

Describe:

the differences between Register vs Memory

A
  • Registers are faster to access THAN memory
  • operating on memory datra requires loads and stores
    • thus, more instructions to be executed!!!!
  • Compiler must use registers for variables as much as possible
    • only spill to memory for less frequently used vars
    • Remember that register optimization is important!!!
25
Immediate Operaands: * Examples of Constant data specified in an instruction:
addi $s3, $s3, 4 #$s3 = $s3 + 4
26
Since there are no subctract immediate instruction, how should we approach this instruction?
Just use a negative constant. Eg. addi $s2, $s1, -1
27
State: The design principle #3
Make the common case faster: * small constants are common * immediate operand **avoids a load instruction**
28
What are instructions that encoded in binary called?
machine code
29
Describe: MIPS instructions
* encoded as 32-bit instruction words * small number of formats encoding operation code (opcode), register numbers... etc. * Regularity!
30
List: the register numbers format
31
MIPS R-Format Instructions includes?
Instruction fields consist: * op: operation code (opcode) * rs: first source register number * rt: second source register number * rd: destination register number * shamt: shift amount (00000 for now) * funct: function code (extends opcode) Image showing the MIPS R-Formate Instruction
32
R-Format Example: add $t0, $s1, $s2
33
MIPS I-Format Instructions: List the instructions included in this format
Immediate arithmetic and load/store instructions * rt: destination or source register number * Constant: -215 to + 215 - 1 * Address: offset added to base address in rs Image:
34
State: The design principle 4:
Good design demands good compromises * Different formates complicate decoding, but allow 32-bit instructions uniformly * keeps formates as similar as possible
35
Image: Stored Porgram Computers
36
Image: Logical Operations: These are instructions for bitwise manipulation. They are useful for extracting and inserting groups of bits in a word
37
Shift Operations: R-Format: Explain it
shamt: how many positions to shift shift left logical: * shift left and fill with 0 bits * sll by i bits multiplies by 2i Shift right logical: * shift right and fill with 0 bits * srl by i bits divides by 2i (unsigned only) Image Showing R-Format: Shift Operations:
38
AND Operations: Why is it useful?
It is useful to mask bits in a word * select some bits, clear others to 0 * and $t0, $t1, $t2 image explaining this further:
39
OR Operations: Why is it useful?
It is useful to includes bits in a word: * Set some bits to 1; leave others unchanged. * or $t0, $t1, $t2 Image showing the above eg:
40
NOT operations: why is it useful?
It is useful to invert bits in a word: * change 0 to 1, and 1 to 0 Note: MIPS has NOR 3-Operand Instruction * a NOR b == NOT (a OR b) * nor $t0, $t1, $zero Image showing the above eg:
41
Conditional Operations: Explain it further
Branch to a labeled instruction if a condition is true * otherwise, continue sequentially **beq rs, rt, L1** * if (rs == rt) branch to instruction labelled L1; **bne rs, rt, L1** * if (rs != rt) branch to instruction labelled L1; **j L1** * unconditional jump to instruction labelled L1; similar to goto statements in C language
42
Conditional Operations Example: C Code: * if ( i == j ) f = g + h; * else f = g - h; * f, g, ... in $s0, $s1,.... compile the above code in MIPS:
43
Compiling Loop Statements Example: C Code: * while (save[i] == k) i += 1; * i in $s3, k in $s5, address of save in $s6 Compile the above code in MIPS code:
44
# Define: Basic Blocks
A basic block is a sequence of instructions with: * no embedded branches **(except at the end)** * No branch targets **(except at the beginning)** Image:
45
A compiler identifies basic blocks for \_\_\_\_\_?
optimization
46
what can accelerate execution of basic blocks?
an advanced processor can
47
More Examples on Conditional Operations: Set result to 1 if a condition is true: * otherwise, set to 0: * slt rd, rs, rt #if(rs \< rt) rd = 1; else rd = 0; * slti rt, rs, constant #if(rs \< constant) rt = 1; else rt = 0; How to use this in combination with **beq** and **bne?**
* slt $t0, $s1, $s2 #if($s1 \< $s2) * bne $t0, $zero, L #branch to L
48
Branch Instruction Design: Why not blt, bge, etc?
49