Hmmm Assembly Language

Slides:



Advertisements
Similar presentations
Chapter 2: Data Manipulation
Advertisements

Computer Architecture and the Fetch-Execute Cycle
Stored Program Architecture
Chapter 2 Data Manipulation Dr. Farzana Rahman Assistant Professor Department of Computer Science James Madison University 1 Some sldes are adapted from.
 Suppose for a moment that you were asked to perform a task and were given the following list of instructions to perform:
LC-3 Computer LC-3 Instructions
Execution of an instruction
Some thoughts: If it is too good to be true, it isn’t. Success is temporary. It is hard work to make it simple. Knowing you did it right is enough reward.
Chapter 5 The LC-3 LC-3 Computer Architecture Memory Map
Chapter 6 Programming in Machine Language The LC-3 Simulator
Chap 4 & 5 LC-3 Computer LC-3 Instructions Chap 4 Homework – due Monday October 27 Chap 5 Homework – due Wednesday October 29 Project 2 Designs (Working.
Overview The von Neumann Machine - the programmable digital computer Introducing the LC-3 Computer - A “toy” computer for us to learn from Computer machine.
Chapters 5 - The LC-3 LC-3 Computer Architecture Memory Map
Henry Hexmoor1 Chapter 10- Control units We introduced the basic structure of a control unit, and translated assembly instructions into a binary representation.
Chapters 4 & 5: LC-3 Computer Architecture Machine Instructions Assembly language Programming in Machine and Assembly Language.
Assembly & Machine Languages
Computer Science 210 Computer Organization The Instruction Execution Cycle.
The von Neumann Model – Chapter 4 COMP 2620 Dr. James Money COMP
Lecture 3. Diff b/w RAM and Registers Registers are used to hold data immediately applicable to the operation at hand Registers are used to hold data.
Computer Systems Organization CS 1428 Foundations of Computer Science.
Von Neumann Machine Objectives: Explain Von Neumann architecture:  Memory –Organization –Decoding memory addresses, MAR & MDR  ALU and Control Unit –Executing.
A Simple Computer Architecture Digital Logic Design Instructor: Kasım Sinan YILDIRIM.
CS 111 – Sept. 15 Chapter 2 – Manipulating data by performing instructions “What is going on in the CPU?” Commitment: –Please read through section 2.3.
1 Ethics of Computing MONT 113G, Spring 2012 Session 7 Computer Architecture The Internet.
CMSC 150 PROGRAM EXECUTION CS 150: Wed 1 Feb 2012.
© GCSE Computing Candidates should be able to:  describe the characteristics of an assembler Slide 1.
Represents different voltage levels High: 5 Volts Low: 0 Volts At this raw level a digital computer is instructed to carry out instructions.
1.4 Representation of data in computer systems Instructions.
The von Neumann Model – Chapter 4 COMP 2620 Dr. James Money COMP
Dale & Lewis Chapter 5 Computing components
Simple ALU How to perform this C language integer operation in the computer C=A+B; ? The arithmetic/logic unit (ALU) of a processor performs integer arithmetic.
Computer Organization Instructions Language of The Computer (MIPS) 2.
Digital Computer Concept and Practice Copyright ©2012 by Jaejin Lee Control Unit.
MIPS Processor.
Representation of Data - Instructions Start of the lesson: Open this PowerPoint from the A451 page – Representation of Data/ Instructions How confident.
The Little man computer
Machine and Assembly Language
Control Unit Lecture 6.
CPU Organisation & Operation
Edexcel GCSE Computer Science Topic 15 - The Processor (CPU)
von Neumann Architecture CPU
Prof. Sirer CS 316 Cornell University
Computer Architecture
MIPS Processor.
Computer Science 210 Computer Organization
Data Representation – Instructions
The Processor and Machine Language
Hmmm Assembly Language
Computer Science 210 Computer Organization
Sports: HMC CS Professor to coach 2020 U. S
Intro to Architecture & Organization
CSCE Fall 2013 Prof. Jennifer L. Welch.
MIPS Processor.
von Neumann Architecture CPU
Sequencing, Selection, and Loops in Machine Language
Functions in Hmmm Assembly
Computer Architecture
MARIE: An Introduction to a Simple Computer
CSCE Fall 2012 Prof. Jennifer L. Welch.
Prof. Sirer CS 316 Cornell University
GCSE OCR 1 The CPU Computer Science J276 Unit 1
Program Execution.
The Von Neumann Machine
Basic components Instruction processing
A Top-Level View Of Computer Function And Interconnection
Objectives Describe common CPU components and their function: ALU Arithmetic Logic Unit), CU (Control Unit), Cache Explain the function of the CPU as.
Instruction execution and ALU
Functions in Hmmm Assembly
Functions in Hmmm Assembly
MIPS Processor.
Presentation transcript:

Hmmm Assembly Language

A Quick OVERView of CPU

Hmmm CPU RAM … … Harvey Mudd Miniature Machine read r1 1 mul r2,r1,r1 Von Neumann bottleneck central processing unit random access memory Program Counter read r1 Holds address of the next instruction 1 mul r2,r1,r1 Instruction Register Holds the current instruction 2 add r2,r2,r1 3 write r2 r0 Stress Levels of abstraction! We want to think at a higher level. Assembly language! Hmmm the machine in text starting on page 76. 4 halt 16 registers, each 16 bits 5 r1 they can hold values from -32768 upto 32767 6 r2 … … 255 r15 255 memory locations of 16 bits

Fetch-Execution Cycle CPU execution repeats the Fetch-Execution Cycle, Fetch a instruction from memory Decode to determine what the instruction intends to do Execution the instruction as specified during which the PC is incremented properly.

Assembly Language add r2 r2 r2 sub r2 r1 r4 mul r7 r6 r2 div r1 r1 r2 register-level programming add r2 r2 r2 reg2 = reg2 + reg2 crazy, perhaps, but used ALL the time which is why it is written this way in python! sub r2 r1 r4 reg2 = reg1 - reg4 reg7 = reg6 * reg2 mul r7 r6 r2 div r1 r1 r2 reg1 = reg1 / reg2 INTEGER division - no remainders reg1 = 42 you can replace 42 with anything from -128 to 127 setn r1 42 I changed the div line from Brian's slide. Note first argument is the destination register. Consistency in design. Each of these instructions (and many more) get implemented for a particular processor and particular machine… . assembly code actual meaning reg1 = reg1 - 1 a shortcut addn r1 -1 read r1 write r1 read from keyboard and write to screen

the assembler a program that translates from human-readable assembly language into machine language (binary) 0000 0001 0000 0001 setn r1,6 setn r2,7 mul r3,r1,r2 write r3 1000 0010 0001 0001 0110 0010 0010 0001 0000 0010 0000 0010 0000 0000 0000 0000 executable machine code assembly code We use hmmmAssembler.py to assemble We use hmmmSimulator.py to execute the machine code

two of the Intel instructions (SSE4, 2008) Real Assembly Language Hmmm has a subset common to all real assembly languages. A few of the many basic processor instructions (Intel) two of the Intel instructions (SSE4, 2008)

Suppose your input is 42 when line 0 is executed What will this program output? (1) Suppose your input is 42 when line 0 is executed 42 read r1 r1 General-purpose register r1 setn r2 9 1 r2 2 sub r3 r1 r2 General-purpose register r2 3 div r3 r3 r2 ex2.hmmm Point out that we needed to load 9 into a register because there are no divide instructions that allow a constant operand Python: ((x-9)//9)-1 r3 addn r3 -1 4 General-purpose register r3 5 write r3 halt 6

Suppose your input is 42 when line 1 is executed What will this program output? (2) Suppose your input is 42 when line 1 is executed 42 read r1 r1 General-purpose register r1 setn r2 9 1 9 r2 2 sub r3 r1 r2 General-purpose register r2 3 div r3 r3 r2 ex2.hmmm Point out that we needed to load 9 into a register because there are no divide instructions that allow a constant operand Python: ((x-9)//9)-1 r3 addn r3 -1 4 General-purpose register r3 5 write r3 halt 6

Suppose your input is 42 when line 2 is executed What will this program output? (3) Suppose your input is 42 when line 2 is executed 42 read r1 r1 General-purpose register r1 setn r2 9 1 9 r2 (x-9) 2 sub r3 r1 r2 General-purpose register r2 3 div r3 r3 r2 ex2.hmmm Point out that we needed to load 9 into a register because there are no divide instructions that allow a constant operand Python: ((x-9)//9)-1 33 r3 addn r3 -1 4 General-purpose register r3 5 write r3 halt 6

Suppose your input is 42 when line 3 is executed What will this program output? (4) Suppose your input is 42 when line 3 is executed 42 read r1 r1 General-purpose register r1 setn r2 9 1 9 r2 (x-9) 2 sub r3 r1 r2 General-purpose register r2 (x-9) // 9 3 div r3 r3 r2 ex2.hmmm Point out that we needed to load 9 into a register because there are no divide instructions that allow a constant operand Python: ((x-9)//9)-1 3 r3 addn r3 -1 4 General-purpose register r3 5 write r3 halt 6

Suppose your input is 42 when line 4 is executed What will this program output? (5) Suppose your input is 42 when line 4 is executed 42 read r1 r1 General-purpose register r1 setn r2 9 1 9 r2 2 sub r3 r1 r2 General-purpose register r2 3 div r3 r3 r2 ex2.hmmm Point out that we needed to load 9 into a register because there are no divide instructions that allow a constant operand Python: ((x-9)//9)-1 2 r3 addn r3 -1 4 General-purpose register r3 5 write r3 halt 6

What will this program output? (6) Suppose your input is 42 when line 5 is executed 42 read r1 r1 General-purpose register r1 setn r2 9 1 9 r2 2 sub r3 r1 r2 General-purpose register r2 3 div r3 r3 r2 ex2.hmmm Point out that we needed to load 9 into a register because there are no divide instructions that allow a constant operand Python: ((x-9)//9)-1 2 r3 addn r3 -1 4 General-purpose register r3 What is the equivalent of Python? 5 write r3 halt 6

Write an Hmmm program to compute x + 3x – 4 HINT: Use the previous program as a model For your reference: ((x – 9) // 9) - 1 0 read r1 1 setn r2, 9 2 sub r3, r1, r2 3 div r3, r3, r2 4 addn r3, -1 write r3 halt 2 ex3.hmmm 0 read r1 # r1 = read x 1 mul r2, r1, r1 # r2 = x**2 2 loadn r3, 3 # Need 3 in reg 3 mul r3, r3, r1 # r3 = 3*x 4 add r2, r2, r3 # r2 = r2 + r3 5 addn r2,-4 # x**2 + 3*x - 4 6 write r2 # Output result 7 halt

x2 + 3x - 4 0 read r1 # r1 = read x 1 mul r2, r1, r1 # r2 = x**2 2 setn r3, 3 # Need 3 in reg 3 mul r3, r3, r1 # r3 = 3*x 4 add r2, r2, r3 # r2 = r2 + r3 5 addn r2,-4 # x**2 + 3*x - 4 6 write r2 # Output result 7 halt ex3.hmmm

Is this enough? What’s missing? read r1 mul r2 r1 r1 add r2 r2 r1 Why couldn't we implement Python using our Hmmm Assembly so far? read r1 mul r2 r1 r1 1 What’s missing? add r2 r2 r1 2 x**2 + x write r2 3 halt 4

Loops and ifs read r1 mul r2 r1 r1 add r2 r2 r1 write r2 jump! jumpn 1 We couldn't implement Python using our Hmmm Assembly Language so far... ! "straight-line code" It's too linear! read r1 mul r2 r1 r1 1 add r2 r2 r1 ex4.hmmm Computes x = r1**2 + r1 And, outputs x infinitely Discuss how "jump 1" works by placing a 1 in PC register. 2 write r2 3 jump! jumpn 1 4

Hmmm, Let's jump ! setn r1 42 write r1 addn r1 1 jumpn 1 halt CPU RAM central processing unit random access memory setn r1 42 write r1 1 r1 General-purpose register r1 addn r1 1 2 r2 Counts from 42 onward… Take a moment to demo this by typing it in, showing them how "easy" it is to assemble and run. Take a moment to show the –f option for the assembler so they don't need to keep retyping the file name! jumpn 1 3 General-purpose register r2 halt 4 What does this program do? What if we replace 1 with 2?

jumps jumpn 42 jeqzn r1 42 jgtzn r1 42 jltzn r1 42 jnezn r1 42 Unconditional jump jumpn 42 "jump to program line number 42" Conditional jumps jeqzn r1 42 IF r1 == 0 THEN jump to line number 42 jgtzn r1 42 IF r1 > 0 THEN jump to line number 42 jltzn r1 42 IF r1 < 0 THEN jump to line number 42 jnezn r1 42 IF r1 != 0 THEN jump to line number 42 Indirect jump jumpr r1 Jump to the line number stored in reg1!

jgtzn (A) -42 (B) -6 (C) -1 (D) 6 (E) 42 RAM CPU PollEv.com/xiannongmeng758 text: xiannongmeng758 to 37607 jgtzn screen RAM CPU central processing unit random access memory read r1 r1 1 jgtzn r1 7 2 setn r2 -1 General-purpose register r1 3 mul r1 r1 r2 r2 4 nop General-purpose register r2 5 nop ex5.hmmm This computes the absolute value of the input, so the output is 6 6 nop With an input of -6, what does this code write out? 7 write r1 8 halt What function is this? (A) -42 (B) -6 (C) -1 (D) 6 (E) 42