introduction to machine/assembler language
DESCRIPTION
COMP 40: Machine Structure and Assembly Language Programming – Fall 2014. Introduction to Machine/Assembler Language. Noah Mendelsohn Tufts University Email: [email protected] Web: http://www.cs.tufts.edu/~noah. COMP 40 term roadmap. Building Useful Applications in your Language. - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: Introduction to Machine/Assembler Language](https://reader036.vdocuments.site/reader036/viewer/2022081514/56813697550346895d9e26c2/html5/thumbnails/1.jpg)
Introduction toMachine/Assembler Language
Noah MendelsohnTufts UniversityEmail: [email protected]: http://www.cs.tufts.edu/~noah
COMP 40: Machine Structure and
Assembly Language Programming – Fall 2014
![Page 2: Introduction to Machine/Assembler Language](https://reader036.vdocuments.site/reader036/viewer/2022081514/56813697550346895d9e26c2/html5/thumbnails/2.jpg)
© 2010 Noah Mendelsohn
COMP 40 term roadmap
2
Ramp up your Programming Skills
Big programs that teach you abstraction, pointers, locality,
machine representations of data
Building a Language Processor on your Emulator
Emulating your own hardware in software
Intel Assembler ProgrammingThe Bomb!
Building Useful Applications in your Language
![Page 3: Introduction to Machine/Assembler Language](https://reader036.vdocuments.site/reader036/viewer/2022081514/56813697550346895d9e26c2/html5/thumbnails/3.jpg)
© 2010 Noah Mendelsohn
Goals for today – learn:
How do computers compute?
High level languages (C) vs. low-level (machine/ASM)
Assember vs. machine code: what’s the difference?
Registers vs. main memory
Why assembler programming is:
– Interesting– Important
– Fun!
3
![Page 4: Introduction to Machine/Assembler Language](https://reader036.vdocuments.site/reader036/viewer/2022081514/56813697550346895d9e26c2/html5/thumbnails/4.jpg)
© 2010 Noah Mendelsohn
Goals for today – learn (in this order actually):
Why assembler programming is important & fun!
Registers vs. main memory
High level languages (C) vs. low-level (machine/ASM)
Assember vs. machine code: what’s the difference?
How do computers compute?
4
![Page 5: Introduction to Machine/Assembler Language](https://reader036.vdocuments.site/reader036/viewer/2022081514/56813697550346895d9e26c2/html5/thumbnails/5.jpg)
© 2010 Noah Mendelsohn
Introducing Assembler and Machine Language
![Page 6: Introduction to Machine/Assembler Language](https://reader036.vdocuments.site/reader036/viewer/2022081514/56813697550346895d9e26c2/html5/thumbnails/6.jpg)
© 2010 Noah Mendelsohn6
Why assembler / machine code matters
Necessary for understanding how computers work
Necessary for understanding– Compilers– Computer viruses– Anti-virus tools– CPU design– Device drivers
Essential for debugging and performance tuning
A wonderful art…lots of fun!
History: how all programs were written for decades
![Page 7: Introduction to Machine/Assembler Language](https://reader036.vdocuments.site/reader036/viewer/2022081514/56813697550346895d9e26c2/html5/thumbnails/7.jpg)
© 2010 Noah Mendelsohn
Registers, Memory and Cache
![Page 8: Introduction to Machine/Assembler Language](https://reader036.vdocuments.site/reader036/viewer/2022081514/56813697550346895d9e26c2/html5/thumbnails/8.jpg)
© 2010 Noah Mendelsohn
Why Registers?
Fastest storage – built into CPU
Compact addressing directly from instructions– How many bits does it take to choose one of 16 registers?
– The typical modern machine does most of its computing in registers!
– To compute on data in memory…first load it into a register!
Comparing to L1 cache– Both are fast: registers typically somewhat faster
– Cache used transparently when accessing memory
– Registers completely integrated with CPU
– Compiler directly controls placement of data in registers!
8
![Page 9: Introduction to Machine/Assembler Language](https://reader036.vdocuments.site/reader036/viewer/2022081514/56813697550346895d9e26c2/html5/thumbnails/9.jpg)
© 2010 Noah Mendelsohn
Simple view of a computer
9
Cach
e
ProgramsandData
Stored asBit Patterns
Memory
CPU
Registers
![Page 10: Introduction to Machine/Assembler Language](https://reader036.vdocuments.site/reader036/viewer/2022081514/56813697550346895d9e26c2/html5/thumbnails/10.jpg)
© 2010 Noah Mendelsohn
IA 32 General Purpose Registers
10
031
%eax
%ecx
%edx
%ebx
%esx
%edi
%esp
%ebp
The 32 bit Intel architecture has 8 registers of 32 bits
each
![Page 11: Introduction to Machine/Assembler Language](https://reader036.vdocuments.site/reader036/viewer/2022081514/56813697550346895d9e26c2/html5/thumbnails/11.jpg)
© 2010 Noah Mendelsohn
IA 32 General Purpose Registers
11
031
%eax
%ecx
%edx
%ebx
%esx
%edi
%esp
%ebp
Register names reflect traditional
uses…a few still do have special roles
![Page 12: Introduction to Machine/Assembler Language](https://reader036.vdocuments.site/reader036/viewer/2022081514/56813697550346895d9e26c2/html5/thumbnails/12.jpg)
© 2010 Noah Mendelsohn
IA 32 General Purpose Registers
12
031
%eax
%ecx
%edx
%ebx
%esx
%edi
%esp
%ebp
Register names reflect traditional
uses…a few still do have special roles
%esp typically used for stack pointer
![Page 13: Introduction to Machine/Assembler Language](https://reader036.vdocuments.site/reader036/viewer/2022081514/56813697550346895d9e26c2/html5/thumbnails/13.jpg)
© 2010 Noah Mendelsohn
IA 32 General Purpose Registers
13
031
%eax
%ecx
%edx
%ebx
%esx
%edi
%esp
%ebp
Register names reflect traditional
uses…a few still do have special roles
%eax typically used to accumlate and return
function results
![Page 14: Introduction to Machine/Assembler Language](https://reader036.vdocuments.site/reader036/viewer/2022081514/56813697550346895d9e26c2/html5/thumbnails/14.jpg)
© 2010 Noah Mendelsohn
IA 32 General Purpose Registers
14
031
%eax
%ecx
%edx
%ebx
%esx
%edi
%esp
%ebp
%ah $al%ax
Before there were IA32 machines, there were 16 bit machines….…the 16 bit registers are simulated within the 32 bit ones
![Page 15: Introduction to Machine/Assembler Language](https://reader036.vdocuments.site/reader036/viewer/2022081514/56813697550346895d9e26c2/html5/thumbnails/15.jpg)
© 2010 Noah Mendelsohn
IA 32 General Purpose Registers
15
031
%eax
%ecx
%edx
%ebx
%esx
%edi
%esp
%ebp
%ah $al%ax
And within that some instructions can update individual bytes
You want to read Bryant and O’Hallaron for the details!
![Page 16: Introduction to Machine/Assembler Language](https://reader036.vdocuments.site/reader036/viewer/2022081514/56813697550346895d9e26c2/html5/thumbnails/16.jpg)
© 2010 Noah Mendelsohn16
What we’ve seen so far – IA 32
8 registers with names like %eax
For IA32, each holds 32 bits
This is where data will be placed for:– Arithmetic– Shifting / masking– Calculating pointers for addressing
Smaller registers from 16 & 8 bit Intel architectures implemented as part of 32 bit registers
![Page 17: Introduction to Machine/Assembler Language](https://reader036.vdocuments.site/reader036/viewer/2022081514/56813697550346895d9e26c2/html5/thumbnails/17.jpg)
© 2010 Noah Mendelsohn17
What we’ve seen so far – IA 32
8 registers with names like %eax
For IA32, each holds 32 bits
This is where data will be placed for:– Arithmetic
– Shifting / masking
– Calculating pointers for addressing
Smaller registers from 16 bit Intel architectures implemented as part of 32 but registers
But…we run on IA-64 / AMD64 / x86-64 machines!
![Page 18: Introduction to Machine/Assembler Language](https://reader036.vdocuments.site/reader036/viewer/2022081514/56813697550346895d9e26c2/html5/thumbnails/18.jpg)
© 2010 Noah Mendelsohn
General Purpose Registers – 64 bit
18
%ah $al%ax%eax%rax
063
![Page 19: Introduction to Machine/Assembler Language](https://reader036.vdocuments.site/reader036/viewer/2022081514/56813697550346895d9e26c2/html5/thumbnails/19.jpg)
© 2010 Noah Mendelsohn
General Purpose Registers – addressing all 64 bits
19
%ah $al%ax%eax%rax
063
mov $123,%rax
![Page 20: Introduction to Machine/Assembler Language](https://reader036.vdocuments.site/reader036/viewer/2022081514/56813697550346895d9e26c2/html5/thumbnails/20.jpg)
© 2010 Noah Mendelsohn
General Purpose Registers – addressing 16 bits
20
%ah $al%ax%eax%rax
063
mov $123,%ax
![Page 21: Introduction to Machine/Assembler Language](https://reader036.vdocuments.site/reader036/viewer/2022081514/56813697550346895d9e26c2/html5/thumbnails/21.jpg)
© 2010 Noah Mendelsohn
General Purpose Registers – addressing 32 bits
21
$al%ah%ax%eax%rax
063
mov $123,%eax
![Page 22: Introduction to Machine/Assembler Language](https://reader036.vdocuments.site/reader036/viewer/2022081514/56813697550346895d9e26c2/html5/thumbnails/22.jpg)
© 2010 Noah Mendelsohn
X86-64 / AMD 64 / IA 64 General Purpose Registers
22
031
%eax
%ecx
%edx
%ebx
%esi
%edi
%esp
%ebp
%ah $al%ax
%ch $cl%cx
%dh $dl%dx
%bh $bl%bx
%si
%di
%sp
%bp
%rax
%rcx
%rdx
%rbx
%rsi
%rdi
%rsp
%rbp
63
%r8
%r9
%r10
%r11
%r12
%r13
%r14
%r15
063
![Page 23: Introduction to Machine/Assembler Language](https://reader036.vdocuments.site/reader036/viewer/2022081514/56813697550346895d9e26c2/html5/thumbnails/23.jpg)
© 2010 Noah Mendelsohn
Classes of AMD 64 registers
General purpose registers– 16 registers, 64 bits each– Used to compute integer and pointer values– Used for integer call/return values to functions
XMM registers– 16 Registers, 128 bits each – latest chips widen these to 256 bits (YMM)– Used to compute float/double values, and for parallel integer computation– Used to pass double/float call/return values
X87 Floating Point registers– 8 registers, 80 bits each– Used to compute, pass/return long double
23
![Page 24: Introduction to Machine/Assembler Language](https://reader036.vdocuments.site/reader036/viewer/2022081514/56813697550346895d9e26c2/html5/thumbnails/24.jpg)
© 2010 Noah Mendelsohn
Classes of AMD 64 registers
General purpose registers– 16 registers, 64 bits each– Used to compute integer and pointer values– Used for integer call/return values to functions
XMM registers– 16 Registers, 128 bits each – latest chips widen these to 256 bits (YMM)– Used to compute float/double values, and for parallel integer computation– Used to pass double/float call/return values
X87 Floating Point registers– 8 registers, 80 bits each– Used to compute, pass/return long double
24
We will focus mainly on integer, bitmap and pointer computation using the GPRs
![Page 25: Introduction to Machine/Assembler Language](https://reader036.vdocuments.site/reader036/viewer/2022081514/56813697550346895d9e26c2/html5/thumbnails/25.jpg)
© 2010 Noah Mendelsohn
History of Intel Architecture Machines
![Page 26: Introduction to Machine/Assembler Language](https://reader036.vdocuments.site/reader036/viewer/2022081514/56813697550346895d9e26c2/html5/thumbnails/26.jpg)
© 2010 Noah Mendelsohn26
Brief history of Intel Architecture milestones
1978: Intel 8086 – 16 bits 29K transistors
1985: Intel 80386 – 32 bits 275K transistors
1995: Intel Pentium Pro – new microarch 5.5M transistors
1999: Intel Pentium III – 32 bits + SSE/SIMD 8.2M transistors
2003: AMD Athlon– 64 bits ?? M transistors– New architecture known as x86-64 or AMD 64
– Backwards compatible with IA32
![Page 27: Introduction to Machine/Assembler Language](https://reader036.vdocuments.site/reader036/viewer/2022081514/56813697550346895d9e26c2/html5/thumbnails/27.jpg)
© 2010 Noah Mendelsohn27
Brief history of Intel Architecture milestones
1978: Intel 8086 – 16 bits 29K transistors
1985: Intel 80386 – 32 bits 275K transistors
1995: Intel Pentium Pro – new microarch 5.5M transistors
1999: Intel Pentium III – 32 bits + SSE/SIMD 8.2M transistors
2003: AMD Athlon– 64 bits ?? M transistors– New architecture known as x86-64 or AMD 64
– Backwards compatible with IA32
Intel distracted working on incompatible Itanium
…AMD grabs de-facto ownership
of “Intel” architeture instruction set evolution!
![Page 28: Introduction to Machine/Assembler Language](https://reader036.vdocuments.site/reader036/viewer/2022081514/56813697550346895d9e26c2/html5/thumbnails/28.jpg)
© 2010 Noah Mendelsohn28
Brief history of Intel Architecture milestones
1978: Intel 8086 – 16 bits 29K transistors
1985: Intel 80386 – 32 bits 275K transistors
1995: Intel Pentium Pro – new microarch 5.5M transistors
1999: Intel Pentium III – 32 bits + SSE/SIMD 8.2M transistors
2003: AMD Athlon– 64 bits ?? M transistors– New architecture known as x86-64 or AMD 64
– Backwards compatible with IA32
2004: Intel Pentium 4E – 64 bits 125M transistors– Intel caves and supports AMD 64 instruction set
![Page 29: Introduction to Machine/Assembler Language](https://reader036.vdocuments.site/reader036/viewer/2022081514/56813697550346895d9e26c2/html5/thumbnails/29.jpg)
© 2010 Noah Mendelsohn29
Brief history of Intel Architecture milestones
1978: Intel 8086 – 16 bits 29K transistors
1985: Intel 80386 – 32 bits 275K transistors
1995: Intel Pentium Pro – new microarch 5.5M transistors
1999: Intel Pentium III – 32 bits + SSE/SIMD 8.2M transistors
2003: AMD Athlon– 64 bits ?? M transistors– New architecture known as x86-64 or AMD 64
– Backwards compatible with IA32
2004: Intel Pentium 4E – 64 bits 125M transistors– Intel caves and supports AMD 64 instruction set
Today: Intel (Core I7) and AMD (e.g. Opteron) compete with same instruction set
![Page 30: Introduction to Machine/Assembler Language](https://reader036.vdocuments.site/reader036/viewer/2022081514/56813697550346895d9e26c2/html5/thumbnails/30.jpg)
© 2010 Noah Mendelsohn
How does the machine compute?
High Level Languagesvs.
Machine Instructions:
![Page 31: Introduction to Machine/Assembler Language](https://reader036.vdocuments.site/reader036/viewer/2022081514/56813697550346895d9e26c2/html5/thumbnails/31.jpg)
© 2010 Noah Mendelsohn31
Consider a simple function in C
int times16(int i){
return i * 16;}
Building a machine to execute this directly in hardware would be:
•Difficult•Slow•Expensive•Etc.
For the first few decades of computing, nobody programmed thisway at all!
All (almost all) digital computers from the earliest to modern execute very simple instructions encoded as bits.
![Page 32: Introduction to Machine/Assembler Language](https://reader036.vdocuments.site/reader036/viewer/2022081514/56813697550346895d9e26c2/html5/thumbnails/32.jpg)
© 2010 Noah Mendelsohn32
Machine code (typical)
Simple instructions – each does small unit of work
Stored in memory
Bitpacked into compact binary form
Directly executed by transistor/hardware logic*
* We’ll show later that some machines execute user-provided machine code directly, some convert it to an even lower level machine code and execute that.
![Page 33: Introduction to Machine/Assembler Language](https://reader036.vdocuments.site/reader036/viewer/2022081514/56813697550346895d9e26c2/html5/thumbnails/33.jpg)
© 2010 Noah Mendelsohn33
Here’s the machine code for our function
int times16(int i){
return i * 16;}
Remember:
This is what’s really in memory and what the machine executes!
89 f8c1 e0 04c3
![Page 34: Introduction to Machine/Assembler Language](https://reader036.vdocuments.site/reader036/viewer/2022081514/56813697550346895d9e26c2/html5/thumbnails/34.jpg)
© 2010 Noah Mendelsohn34
Here’s the machine code for our function
int times16(int i){
return i * 16;}
But what does it mean??
Does it really implement the times16 function?
89 f8c1 e0 04c3
![Page 35: Introduction to Machine/Assembler Language](https://reader036.vdocuments.site/reader036/viewer/2022081514/56813697550346895d9e26c2/html5/thumbnails/35.jpg)
© 2010 Noah Mendelsohn35
Consider a simple function in C
int times16(int i){
return i * 16;}
0: 89 f8 mov %edi,%eax 2: c1 e0 04 shl $0x4,%eax 5: c3 retq
![Page 36: Introduction to Machine/Assembler Language](https://reader036.vdocuments.site/reader036/viewer/2022081514/56813697550346895d9e26c2/html5/thumbnails/36.jpg)
© 2010 Noah Mendelsohn36
Consider a simple function in C
int times16(int i){
return i * 16;}
0: 89 f8 mov %edi,%eax 2: c1 e0 04 shl $0x4,%eax 5: c3 retq
Load i into result register %eax
![Page 37: Introduction to Machine/Assembler Language](https://reader036.vdocuments.site/reader036/viewer/2022081514/56813697550346895d9e26c2/html5/thumbnails/37.jpg)
© 2010 Noah Mendelsohn37
Consider a simple function in C
int times16(int i){
return i * 16;}
0: 89 f8 mov %edi,%eax 2: c1 e0 04 shl $0x4,%eax 5: c3 retq
Huh…
What language is this?
![Page 38: Introduction to Machine/Assembler Language](https://reader036.vdocuments.site/reader036/viewer/2022081514/56813697550346895d9e26c2/html5/thumbnails/38.jpg)
© 2010 Noah Mendelsohn38
Consider a simple function in C
int times16(int i){
return i * 16;}
0: 89 f8 mov %edi,%eax 2: c1 e0 04 shl $0x4,%eax 5: c3 retq
Huh…
What language is this?
ASSEMBLER LANGUAGE:
• Source code in ASCII, like C (typically written by people)• Assembled into machine code (bits) by the assembler – produces .o file• Remember, on our Linux systems the compiler actually produces
assembler and then assembles that to make a .o• You can see the generated assembler by using the –S option. DO IT!
![Page 39: Introduction to Machine/Assembler Language](https://reader036.vdocuments.site/reader036/viewer/2022081514/56813697550346895d9e26c2/html5/thumbnails/39.jpg)
© 2010 Noah Mendelsohn39
Assembler vs. machine code
int times16(int i){
return i * 16;}
0: 89 f8 mov %edi,%eax 2: c1 e0 04 shl $0x4,%eax 5: c3 retq
Assembler language
ASSEMBLER LANGUAGE:
• Source code in ASCII, like C (typically written by people)• Assembled into machine code (bits) by the assembler – produces .o file• Remember, on our Linux systems the compiler actually produces
assembler and then assembles that to make a .o• You can see the generated assembler by using the –S option. DO IT!
Machine code
![Page 40: Introduction to Machine/Assembler Language](https://reader036.vdocuments.site/reader036/viewer/2022081514/56813697550346895d9e26c2/html5/thumbnails/40.jpg)
© 2010 Noah Mendelsohn40
Consider a simple function in C
int times16(int i){
return i * 16;}
0: 89 f8 mov %edi,%eax 2: c1 e0 04 shl $0x4,%eax 5: c3 retq
Shifting left by 4 is quick way to multiply
by 16.
![Page 41: Introduction to Machine/Assembler Language](https://reader036.vdocuments.site/reader036/viewer/2022081514/56813697550346895d9e26c2/html5/thumbnails/41.jpg)
© 2010 Noah Mendelsohn41
Consider a simple function in C
int times16(int i){
return i * 16;}
0: 89 f8 mov %edi,%eax 2: c1 e0 04 shl $0x4,%eax 5: c3 retq
Return to caller, which will look for result in
%eax
REMEMBER: you can see the assembler code for any C program by running gcc with the –S flag. Do it!!
![Page 42: Introduction to Machine/Assembler Language](https://reader036.vdocuments.site/reader036/viewer/2022081514/56813697550346895d9e26c2/html5/thumbnails/42.jpg)
© 2010 Noah Mendelsohn
How do we build a chipthat does this calculation?
![Page 43: Introduction to Machine/Assembler Language](https://reader036.vdocuments.site/reader036/viewer/2022081514/56813697550346895d9e26c2/html5/thumbnails/43.jpg)
© 2010 Noah Mendelsohn
Very simplified view of computer
43
Cach
e
Memory
![Page 44: Introduction to Machine/Assembler Language](https://reader036.vdocuments.site/reader036/viewer/2022081514/56813697550346895d9e26c2/html5/thumbnails/44.jpg)
© 2010 Noah Mendelsohn
Very simplified view of computer
44
Cach
e
Memory
89 f8c1 e0 04c3
![Page 45: Introduction to Machine/Assembler Language](https://reader036.vdocuments.site/reader036/viewer/2022081514/56813697550346895d9e26c2/html5/thumbnails/45.jpg)
© 2010 Noah Mendelsohn
Instructions fetched and decoded
45
Cach
e
Memory
89 f8c1 e0 04c3
![Page 46: Introduction to Machine/Assembler Language](https://reader036.vdocuments.site/reader036/viewer/2022081514/56813697550346895d9e26c2/html5/thumbnails/46.jpg)
© 2010 Noah Mendelsohn
Instructions fetched and decoded
46
Cach
e
Memory
89 f8c1 e0 04c3
ALU
Arithmetic and Logic Unit executes instructions like add
and shiftupdating registers.
![Page 47: Introduction to Machine/Assembler Language](https://reader036.vdocuments.site/reader036/viewer/2022081514/56813697550346895d9e26c2/html5/thumbnails/47.jpg)
© 2010 Noah Mendelsohn47
The MIPS CPU Architecture
![Page 48: Introduction to Machine/Assembler Language](https://reader036.vdocuments.site/reader036/viewer/2022081514/56813697550346895d9e26c2/html5/thumbnails/48.jpg)
© 2010 Noah Mendelsohn
Interpreting vs. Compiling
![Page 49: Introduction to Machine/Assembler Language](https://reader036.vdocuments.site/reader036/viewer/2022081514/56813697550346895d9e26c2/html5/thumbnails/49.jpg)
© 2010 Noah Mendelsohn49
INTERPRETERSoftware or hardware that does what the instructions say
COMPILERSoftware that converts a program to another language
ASSEMBLERLike a compiler, but the input assembler language is (mostly)1-to-1 with machine instructions
![Page 50: Introduction to Machine/Assembler Language](https://reader036.vdocuments.site/reader036/viewer/2022081514/56813697550346895d9e26c2/html5/thumbnails/50.jpg)
© 2010 Noah Mendelsohn50
INTERPRETERSoftware or hardware that does what the instructions say
COMPILERSoftware that converts a program to another language
ASSEMBLERLike a compiler, but the input assembler language is (mostly)1-to-1 with machine instructions
![Page 51: Introduction to Machine/Assembler Language](https://reader036.vdocuments.site/reader036/viewer/2022081514/56813697550346895d9e26c2/html5/thumbnails/51.jpg)
© 2010 Noah Mendelsohn51
INTERPRETERSoftware or hardware that does what the instructions say
COMPILERSoftware that converts a program to another language
ASSEMBLERLike a compiler, but the input assembler language is (mostly)1-to-1 with machine instructions
![Page 52: Introduction to Machine/Assembler Language](https://reader036.vdocuments.site/reader036/viewer/2022081514/56813697550346895d9e26c2/html5/thumbnails/52.jpg)
© 2010 Noah Mendelsohn52
What a computer is
A computer is a hardware interpreter for machine language programs
Simple machines (RISC):– Hardware directly interprets machine instructions
![Page 53: Introduction to Machine/Assembler Language](https://reader036.vdocuments.site/reader036/viewer/2022081514/56813697550346895d9e26c2/html5/thumbnails/53.jpg)
© 2010 Noah Mendelsohn53
What a computer is
A computer is a hardware interpreter for machine language programs
Simple machines (RISC):– Hardware directly interprets machine instructions
Complex machines (CISC):*– The real computer handles only simple instructions
– Hardware converts user’s complex machine instructions to simple instructions on the fly – then interprets
![Page 54: Introduction to Machine/Assembler Language](https://reader036.vdocuments.site/reader036/viewer/2022081514/56813697550346895d9e26c2/html5/thumbnails/54.jpg)
© 2010 Noah Mendelsohn54
What a computer is
A computer is a hardware interpreter for machine language programs
Simple machines (RISC):– Hardware directly interprets machine instructions
Complex machines (CISC):*– The real computer handles only simple instructions
– Hardware converts user’s complex machine instructions to simple instructions on the fly – then interprets
Almost like compiling on the fly!
* The true difference between RISC and CISC is a bit more subtle, but the spirit of this explanation is right
![Page 55: Introduction to Machine/Assembler Language](https://reader036.vdocuments.site/reader036/viewer/2022081514/56813697550346895d9e26c2/html5/thumbnails/55.jpg)
© 2010 Noah Mendelsohn55
What a computer is
A computer is a hardware interpreter for machine language programs
Simple machines (RISC):– Hardware directly interprets machine instructions
Complex machines (CISC):*– The real computer handles only simple instructions
– Hardware converts user’s complex machine instructions to simple instructions on the fly – then interprets
Software interpreters - emulators– You can write software programs that do the same thing as hardware computers
– Example: http://bellard.org/jslinux/
– You will be writing an emulator for a simple CPU later in COMP 40!
* The true difference between RISC and CISC is a bit more subtle, but the spirit of this explanation is right
![Page 56: Introduction to Machine/Assembler Language](https://reader036.vdocuments.site/reader036/viewer/2022081514/56813697550346895d9e26c2/html5/thumbnails/56.jpg)
© 2010 Noah Mendelsohn56
Virtual Machines
The C Language Virtual MachineUsually compiled to assembler – occasionally interpreted
Or Python, Java, Ruby, etc.
![Page 57: Introduction to Machine/Assembler Language](https://reader036.vdocuments.site/reader036/viewer/2022081514/56813697550346895d9e26c2/html5/thumbnails/57.jpg)
© 2010 Noah Mendelsohn57
Virtual Machines
The C Language Virtual MachineUsually compiled to assembler – occasionally interpreted
The Intel IA64 Virtual MachineThe machine code a user gets to run
![Page 58: Introduction to Machine/Assembler Language](https://reader036.vdocuments.site/reader036/viewer/2022081514/56813697550346895d9e26c2/html5/thumbnails/58.jpg)
© 2010 Noah Mendelsohn58
Virtual Machines
The C Language Virtual MachineUsually compiled to assembler – occasionally interpreted
The Intel IA64 User-mode Virtual MachineThe machine code a user gets to run
MicrocodeLow level code underneath a CISC machine
![Page 59: Introduction to Machine/Assembler Language](https://reader036.vdocuments.site/reader036/viewer/2022081514/56813697550346895d9e26c2/html5/thumbnails/59.jpg)
© 2010 Noah Mendelsohn59
Virtual Machines
The C Language Virtual MachineUsually compiled to assembler – occasionally interpreted
The Intel IA64 User-mode Virtual MachineThe machine code a user gets to run
Software emulator or hypervisorPretend to be a different machine or multiple machines
Hypervisors like VMWare and VM/370 create the illusion of multiple hardware
machines on a single CPU
![Page 60: Introduction to Machine/Assembler Language](https://reader036.vdocuments.site/reader036/viewer/2022081514/56813697550346895d9e26c2/html5/thumbnails/60.jpg)
© 2010 Noah Mendelsohn60