Presentation is loading. Please wait.

Presentation is loading. Please wait.

CMSC 313, F ‘09 1 Introduction to Assembly TopicsTopics –Assembly Overview –Instructions –Hardware.

Similar presentations


Presentation on theme: "CMSC 313, F ‘09 1 Introduction to Assembly TopicsTopics –Assembly Overview –Instructions –Hardware."— Presentation transcript:

1 CMSC 313, F ‘09 1 Introduction to Assembly TopicsTopics –Assembly Overview –Instructions –Hardware

2 CMSC 313, F ‘09 2 Assembly overview Some terminology and concepts A peek at what we will spend the rest of the semester talking about. A peek at what we will spend the rest of the semester talking about. A chance to talk about things at a high-level A chance to talk about things at a high-level – we will spend the rest of the course worrying about details!

3 CMSC 313, F ‘09 3 Programs and Processes Program: a file (an executable image or set of instructions that can be interpreted).Program: a file (an executable image or set of instructions that can be interpreted). Process: an instance of a program that is running.Process: an instance of a program that is running. A process is alive, a program is just a file.A process is alive, a program is just a file.

4 CMSC 313, F ‘09 4 hello.c #include #include int main( ) { printf(“%s\n”, “Hello World”); return 0; }

5 CMSC 313, F ‘09 5 Text vs. Binary The original C program (and some of the intermediate representations) are text. Typically ASCII encoded. The object code and executable are binary. – anything that is not text is binary! – The actual program representation depends on the machine language (instruction set) supported by the computer.

6 CMSC 313, F ‘09 6 Machine Language A sequence of bits.A sequence of bits. Organized in to words.Organized in to words. – different architectures use different length words typical sizes are 16, 32 or 64 bits. The bits are an encoding of some operations that should take place in the CPU.The bits are an encoding of some operations that should take place in the CPU.

7 CMSC 313, F ‘09 7 Instructions Each instruction does something relatively simple. Each instruction does something relatively simple. move some bits around treat some bits as base 2 numbers and apply arithmetic operations. send/read some bits to/from I/O devices. select the group of bits that will make up the next instruction

8 CMSC 313, F ‘09 8 Example Machine Language Each instruction is 4 bits long.Each instruction is 4 bits long. There are 2 4 =16 possible unique instructions.There are 2 4 =16 possible unique instructions. We can organize the bits to make it easy to design a machine that can execute the instructions.We can organize the bits to make it easy to design a machine that can execute the instructions. –first 2 bits represent an operation. –last 2 bits represent what to operate on.

9 CMSC 313, F ‘09 9 A Student’s Machine Language The first 2 bit determine the operation –00: Eat –01: Play –10: Study –11: Watch MTV The last 2 bits depend on the operation

10 CMSC 313, F ‘09 10 00xy - EAT Instructions The last 2 bits specify what we eat: –00 Pizza –01 Burger –10 Macaroni and Cheese –11 Softshell Crab We have 4 different eat instructions. –0000 eat pizza –0001 eat burger –0010 eat mac and cheese –0011 eat softshell crab

11 CMSC 313, F ‘09 11 01xy - Play Instructions The last 2 bits specify what we play: –00 Surf the Web –01 Doom –10 Music –11 Pin-the-tail-on-the-donkey We have 4 different play instructions –0100 Surf the web –0101 Play Doom –0110 Play Music –0111 Play Pin-the-tail-on-the-donkey

12 CMSC 313, F ‘09 12 11xy MTV Instructions 4 possible codes: 1100, 1101, 1110, 11114 possible codes: 1100, 1101, 1110, 1111 All four mean the same thing (the last 2 bits don’t matter)All four mean the same thing (the last 2 bits don’t matter) It’s OK to waste 2 bits, after all – we’re already wasting our time with MTV, right?It’s OK to waste 2 bits, after all – we’re already wasting our time with MTV, right?

13 CMSC 313, F ‘09 13 10xy - Study Instructions The 3rd bit specifies what we study: –x specifies what we study 0 Comp. Org. 1 American History The 4th bit specifies how hard we study: –y specifies how hard we study 0 Holding book, but eyes closed 1 Cram session We have 4 different study instructions –10 00 - Study Comp Org Holding book with eyes closed –10 01 - Cram session for Am. History –10 10 - Study Am. History holding book with eyes close –10 11 - Cram session for Comp Org

14 CMSC 313, F ‘09 14 A Simple Program 0011Eat soft shell crab. 1010Study history with eyes closed. 0100Surf the web. 1101Watch MTV. 1001Cram for Comp. Org. 0101Play Doom

15 CMSC 313, F ‘09 15 GOBACK Instruction Let’s make things more interesting: Replace the MTV (11xy) instruction with Go back instruction Last 2 bits determine how far back we go: –00 Repeat previous instruction –01 Go back 1 instruction before previous –10 back 2 instructions before previous –11 back 3 instructions before previous

16 CMSC 313, F ‘09 16 Tomorrow’s Program 0011 Eat soft shell crab. 1010 Study history with eyes closed. 0100 Surf the web. 1001 Cram for Comp. Org. 0101 Play Doom 1110 Go back 2 before previous

17 CMSC 313, F ‘09 17 Von Neumann Computer Somehow put sequence of instructions (as well as the data) in memorySomehow put sequence of instructions (as well as the data) in memory A control unit sequences through the memory (instructions) one at a time.A control unit sequences through the memory (instructions) one at a time. It is also possible to put other stuff (data) in the memory.It is also possible to put other stuff (data) in the memory. See the von Neumann architecture entry in Wikipedia for moreSee the von Neumann architecture entry in Wikipedia for morevon Neumann architecturevon Neumann architecture

18 CMSC 313, F ‘09 18 Hardware Need memory to hold the sequence of instructions.Need memory to hold the sequence of instructions. Something to sequence through theSomething to sequence through the instructions.instructions. Something to execute one instruction.Something to execute one instruction. Something to interface to the outside world (I/O).Something to interface to the outside world (I/O).

19 CMSC 313, F ‘09 19 Typical System Organization Main memory I/O bridge Bus interface ALU Register file CPU System busMemory bus Disk controller Graphics adapter USB controller MouseKeyboardDisplay Disk I/O bus Expansion slots for other devices such as network adapters hello executable stored on disk PC

20 CMSC 313, F ‘09 20 Main memory I/O bridge Bus interface ALU Register file CPU System busMemory bus Disk controller Graphics adapter USB controller MouseKeyboardDisplay Disk I/O bus Expansion slots for other devices such as network adapters PC "hello" User types "hello" Reading hello command hello executable stored on disk

21 CMSC 313, F ‘09 21 Main memory I/O bridge Bus interface ALU Register file CPU System busMemory bus Disk controller Graphics adapter USB controller MouseKeyboardDisplay Disk I/O bus Expansion slots for other devices such as network adapters hello executable stored on disk PC hello code "hello,world\n" Loading hello executable

22 CMSC 313, F ‘09 22 Main memory I/O bridge Bus interface ALU Register file CPU System busMemory bus Disk controller Graphics adapter USB controller MouseKeyboardDisplay Disk I/O bus Expansion slots for other devices such as network adapters hello executable stored on disk PC hello code "hello,world\n" Displaying the output

23 CMSC 313, F ‘09 23 Instructions We will spend lots of time on real instruction sets (IA32 - Intel Architecture for 32 bit machines).We will spend lots of time on real instruction sets (IA32 - Intel Architecture for 32 bit machines). Data representation is determined by processor architecture.Data representation is determined by processor architecture. For now – we need to understand that each piece of data is just a bunch of bits (data looks just like instructions).For now – we need to understand that each piece of data is just a bunch of bits (data looks just like instructions).

24 CMSC 313, F ‘09 24 Interpreting Data It’s impossible to tell what a chunk of bits means without any other informationIt’s impossible to tell what a chunk of bits means without any other information01001000 –Could be the integer 72 – Could be an instruction. –Could be the character ‘H’ –Could be a floating point number.

25 CMSC 313, F ‘09 25 Context Determines Data Type A computer executes instructions sequentially – it just grabs the bits in the next memory location and assumes it’s an instruction.A computer executes instructions sequentially – it just grabs the bits in the next memory location and assumes it’s an instruction. Some instructions add integers – in this case the computer assumes the bits in memory represent integer numbers.Some instructions add integers – in this case the computer assumes the bits in memory represent integer numbers.

26 CMSC 313, F ‘09 26 Memory Cache Main memory (DRAM) Memory bridge Bus interface L2 cache (SRAM) ALU Register file CPU chip Cache busSystem busMemory bus L1 cache (SRAM)

27 CMSC 313, F ‘09 27 Memory Hierarchy Registers On-chip L1 cache (SRAM) Main memory (DRAM) Local secondary storage (local disks) Larger, slower, and cheaper (per byte) storage devices Remote secondary storage (distributed file systems, Web servers) Local disks hold files retrieved from disks on remote network servers. Main memory holds disk blocks retrieved from local disks. Off-chip L2 cache (SRAM) L1 cache holds cache lines retrieved from the L2 cache. CPU registers hold words retrieved from cache memory. L2 cache holds cache lines retrieved from memory. L0: L1: L2: L3: L4: L5: Smaller, faster, and costlier (per byte) storage devices

28 CMSC 313, F ‘09 28 Operating System One of the functions of the operating system (which is itself a running program) is to move programs in to memory and start them running.One of the functions of the operating system (which is itself a running program) is to move programs in to memory and start them running. The operating system must manage the memory of the computer (the OS itself must be in memory!).The operating system must manage the memory of the computer (the OS itself must be in memory!).

29 CMSC 313, F ‘09 29 Machine Code In the old days… humans would write programs in machine code (determine every 1 and 0).In the old days… humans would write programs in machine code (determine every 1 and 0). The 1s and 0s were put in to memory with a set of switches!The 1s and 0s were put in to memory with a set of switches!

30 CMSC 313, F ‘09 30 Assembly Language An assembly language program is a text file containing symbol descriptions of instructionsAn assembly language program is a text file containing symbol descriptions of instructions An assembler is a program that reads the assembly language program and outputs machine code (1s and 0s) An assembler is a program that reads the assembly language program and outputs machine code (1s and 0s)

31 CMSC 313, F ‘09 31 High Level Languages Many high-level languages translate program text to assembly language (and then run through an assembler).Many high-level languages translate program text to assembly language (and then run through an assembler). C compilers often do this, we will test this out by generating assembly language from C code.C compilers often do this, we will test this out by generating assembly language from C code.


Download ppt "CMSC 313, F ‘09 1 Introduction to Assembly TopicsTopics –Assembly Overview –Instructions –Hardware."

Similar presentations


Ads by Google