140 likes | 178 Views
This article explores the concept of Instruction Set Architecture (ISA) and its role in software and hardware interaction. It discusses the history of ISA's, compares CISC and RISC, examines x86 dominance in PCs, explains the compilation process and the purpose of linkers, and covers object file formats, loaders, memory images, and structs. It also touches on the relevance and usage of assembly language.
E N D
Instruction sets, RISC vs. CISC, Compilers, Assemblers, Linkers, Loaders, Memory images, and who cares about assembly. CS232 ISA's, Compilers, and Assembly
ISA Proc #1 Proc #2 Software Instruction Set Architecture (ISA) • The ISA is the interface between hardware and software. • The ISA serves as an abstraction layer between the HW and SW • Software doesn’t need to know how the processor is implemented • Any processor that implements the ISA appears equivalent • An ISA enables processor innovation without changing software • This is how Intel has made billions of dollars. • Before ISAs, software was re-written/re-compiled for each new machine. ISA's, Compilers, and Assembly
A little ISA history • 1964: IBM System/360, the first computer family • IBM wanted to sell a range of machines that ran the same software • 1960’s, 1970’s: Complex Instruction Set Computer (CISC) era • Much assembly programming, compiler technology immature • Simple machine implementations • Complex instructions simplified programming, little impact on design • 1980’s: Reduced Instruction Set Computer (RISC) era • Most programming in high-level languages, mature compilers • Aggressive machine implementations • Simpler, cleaner ISA’s facilitated pipelining, high clock frequencies • 1990’s: Post-RISC era • ISA complexity largely relegated to non-issue • CISC and RISC chips use same techniques (pipelining, superscalar, ..) • ISA compatibility outweighs any RISC advantage in general purpose • Embedded processors prefer RISC for lower power, cost • 2000’s: Multi-core and Multithreading ISA's, Compilers, and Assembly
Comparing x86 and MIPS x86 is a typical CISC ISA, MIPS is a typical RISC ISA Much more is similar than different: Both use registers and have byte-addressable memories Same basic types of instructions (arithmetic, branches, memory) A few of the differences: Fewer registers: 8 (vs. 32 for MIPS) 2-register instruction formats (vs. 3-register format for MIPS) Additional, complex addressing modes Variable-length instruction encoding (vs. fixed 32-bit length for MIPS) 5
Why does x86 dominate PCs? x86 won because it was the first 16-bit chip by two years IBM put it in PCs because there was no competing choice The rest is inertia and “financial feedback” x86 is most difficult ISA to implement for high performance, but Because Intel sells the most processors ... It has a lot of money ... Which it uses to hire more and better engineers ... Which is uses to maintain competitive performance ... And given equal performance, compatibility wins ... So Intel sells the most processors! 6
The compilation process • To produce assembly code: gcc –S test.c • produces test.s • To produce object code: gcc –c test.c • produces test.o • To produce executable code: gcc test.c • produces a.out
The purpose of a linker • The linker is a program that takes one or more object files and assembles them into a single executable program. • The linker resolves references to undefined symbols by finding out which other object defines the symbol in question, and replaces placeholders with the symbol's address.
What the linker does ISA's, Compilers, and Assembly
Object File Formats ISA's, Compilers, and Assembly
Loader • Before we can start executing a program, the O/S must load it: • Loading involves 5 steps: • Allocates memory for the program's execution. • Copies the text and data segments from the executable into memory. • Copies program arguments (e.g., command line arguments) onto the stack. • Initializes registers: sets $sp to point to top of stack, clears the rest. • Jumps to start routine, which: 1) copies main's arguments off of the stack, and 2) jumps to main. ISA's, Compilers, and Assembly
MIPS memory image ISA's, Compilers, and Assembly
Structs • Structs are like arrays, but the elements can be different types. • Same with objects • Compiler/assembler inserts padding to “naturally align” data • Sometimes you can reorganize fields to eliminate padding. • Consider: ISA's, Compilers, and Assembly
Whither Assembly Language ISA's, Compilers, and Assembly
Inline assembly Example intadd(int a, int b) { /* return a + b */ int ret_val; __asm("add %2, %0, %1", a, b, ret_val); return(ret_val); } ISA's, Compilers, and Assembly