lecture 8 Flashcards
GNU Compiler Collection (GCC) : Compile, Assemble, Machine Language
3 compilation steps
- compiler
- assembler
- linker
what enters the compiler?
filename.c –> your program in high level language (text)
what is the gcc compiler command?
gcc -s filename.c
what does the gcc -s filename.c create?
when this is entered into the terminal and completes, an assembly program is created (filename.c –> filename.s)
what does the compiler change your program to?
filename.s –> assembler program
what is the .s/assembler program?
set of text instructions used to program the processor
what enters the assembler?
filename.s (assembly program)
what is the gcc command for the assembler?
gcc -c filename.s
what does the gcc -c filename.s create?
filename.o –> object program/machine program (binary)
what is the .o/object program?
machine program –> set of binary instructions that configure and control hardware
what enters the linker?
filename.o –> machine program (binary)
what is the gcc command for the linker?
gcc filename.o
what does the gcc filename.o create?
executable program (a.out)
who is the intended user for the machine program?
hardware (computer)
highest level language
highest level of abstraction, closest to human language, java python etc
your code basically
text
assembly language
lowest level of abstraction, specific to processor architecture (RISC CISC), syntax is human readable but language of machine
text
machine language
no abstraction, not human readable, syntax is binary encoded instructions and data, configure and control hardware (MIPS, processor, specific)
binary
instruction set architecture
combines instructions with registers, addressing modes, data types
MIPS
microprocessor without interlocked pipelined stages
RISC architecture
3 MIPS Instruction Types:
- R-TYPE
- I-TYPE
- J-TYPE
what is R-TYPE?
instruction operands are registers
what is I-TYPE?
instruction operands are registers and a constant (immediate) value
anatomy of R-TYPE instruction
operation $1, $2, $3
$1 –> destination operand
$2 and $3 –> source operands
(variables, arguments, etc)
anatomy of I-TYPE instruction
operation i $1, $2, 1
i –> immediate (how to tell its I-TYPE)
$1 –> destination operands
$2 –> source operands
1 –> immediate operand (constant)
what does the instruction mean?
primitive operation
- specify operation and its operands
–> operands = necessary variables to perform the operation
what are operands?
necessary variables to perform the operation
types of operands
immediate (data), source and destination (registers)
what is the register symbol
$
how many registers does MIPS have?
32 general purpose registers
what does the assembler do with the MIPS instructions?
assembler translates MIPS to machine language
what step in the compilation system translates code to MIPS?
compiler –> filename.s = MIPS instructions
c program:
int a = 10;
int b = 2;
int c = a + b + 2;
MIPS Program:
addi $8, $0, 10
^ what does this line mean?
addi $8, $0, 10
$8 –> register $8 holds the value in variable a (a = 10)
register $8 = $0(0) + 10 = 10 (AKA a)
c program:
int a = 10;
int b = 2;
int c = a + b + 2;
MIPS Program:
addi $8, $0, 10
addi $9, $0, 2
^ what does this line mean?
addi $9, $0, 2
$9 –> register $9 holds the value in variable b (b = 2)
register $9 = $0(0) + 2 = 2 (AKA b)
c program:
int a = 10;
int b = 2;
int c = a + b + 2;
MIPS Program:
addi $8, $0, 10
addi $9, $0, 2
add $10, $8, $9
^ what does this line mean?
add $10, $8, $9
register $10 –> holds value in variable c (int c = a + b)
$10 = $8 + $9 c = a + b = 10 + 2
c program:
int a = 10;
int b = 2;
int c = a + b + 2;
MIPS Program:
addi $8, $0, 10
addi $9, $0, 2
add $10, $8, $9
addi $10, $10, 2
^what does this line mean?
addi $10, $10, 2
register $10 –> holds value in variable c (a + b) from line above
*now adding 2 to this register since its c = a + b + 2 (cant do this in one MIPS instruction –> had to split it into 2)
$10 = $10 + 2 c = (a + b) + 2 = (10 + 2) + 2
what is always the opcode for R-TYPE?
000000
what are the parts of a 32-bit R-TYPE instruction?
opcode (6)
rs (5)
rt (5)
rd (5)
shamt (5)
func (6)
what are the parts of a 32-bit I-TYPE instruction?
opcode (6)
rs (5)
rt (5)
immediate (16)
once the program is in MIPS (assemble program), what does the assembler then do?
translates MIPS to machine language
(binary)
in the MIPS cheat sheet, what does each part in R-type and I-type get translated to?
its binary equivalent
ex) $8 = 01000 for rt (5)
what is rt for I-Type?
destination register
what is rd for R-type?
destination register
what is rs for both R-type and I-type?
source register
what is immediate for I-type?
constant
what is func for R-Type?
operation (add)
what is shamt for R-type?
amount of shift, set to zero in all non-shift instructions