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:
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.
Assembly Language Programming. CPU The CPU contains a Control Unit, Arithmetic Logic Unit (ALU) and a small number of memory locations called Registers.
Chapter 6 Programming in Machine Language The LC-3 Simulator
Computer Hardware What goes on inside?. Deeper.
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.
Choice for the rest of the semester New Plan –assembler and machine language –Operating systems Process scheduling Memory management File system Optimization.
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.
Assembly & Machine Languages
Computer Science 210 Computer Organization The Instruction Execution Cycle.
Computer Structure.
Levels of Architecture & Language CHAPTER 1 © copyright Bobby Hoggard / material may not be redistributed without permission.
IT253: Computer Organization Lecture 4: Instruction Set Architecture Tonga Institute of Higher Education.
Computer Systems Organization CS 1428 Foundations of Computer Science.
CSC 3210 Computer Organization and Programming Chapter 1 THE COMPUTER D.M. Rasanjalee Himali.
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.
Computer Science 101 Computer Systems Organization.
Computer Architecture Memory, Math and Logic. Basic Building Blocks Seen: – Memory – Logic & Math.
CMSC 150 PROGRAM EXECUTION CS 150: Wed 1 Feb 2012.
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
Digital Computer Concept and Practice Copyright ©2012 by Jaejin Lee Control Unit.
ICC Module 3 Lesson 1 – Computer Architecture 1 / 6 © 2015 Ph. Janson Information, Computing & Communication Computer Architecture Clip 3 – Instruction.
Computer Systems – Machine & Assembly code. Objectives Machine Code Assembly Language Op-code Operand Instruction Set.
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.
Computer Operation. Binary Codes CPU operates in binary codes Representation of values in binary codes Instructions to CPU in binary codes Addresses in.
Representation of Data - Instructions Start of the lesson: Open this PowerPoint from the A451 page – Representation of Data/ Instructions How confident.
Computers’ Basic Organization
CS 270: Mathematical Foundations of Computer Science
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
Instruction Format MIPS Instruction Set.
Computer Architecture
MIPS Processor.
Computer Science 210 Computer Organization
The Processor and Machine Language
Computer Science 210 Computer Organization
Sports: HMC CS Professor to coach 2020 U. S
MIPS Processor.
Data Transfers To be able to implement
Systems Architecture I (CS ) Lecture 2: A Simplified Computer
von Neumann Architecture CPU
Sequencing, Selection, and Loops in Machine Language
Functions in Hmmm Assembly
Branch instructions We’ll implement branch instructions for the eight different conditions shown here. Bits 11-9 of the opcode field will indicate the.
MARIE: An Introduction to a Simple Computer
Prof. Sirer CS 316 Cornell University
Instruction Format MIPS Instruction Set.
Control units In the last lecture, we introduced the basic structure of a control unit, and translated our assembly instructions into a binary representation.
Program Execution.
Basic components Instruction processing
Objectives Describe common CPU components and their function: ALU Arithmetic Logic Unit), CU (Control Unit), Cache Explain the function of the CPU as.
Hmmm Assembly Language
Functions in Hmmm Assembly
Functions in Hmmm Assembly
MIPS Processor.
Presentation transcript:

Hmmm Assembly Language

A Quick review of CPU

RAM CU ripple8 05 addn r3, 4 1 7+4 4 strobe for next instruction PC IR Reg3 1 The instruction Argument 1 Argument 2 the same Reg3 the register the constant 4 old value of Reg3 = 7 new value of Reg3 = 11 CU read enable RAM 8 data bits 8 address bits strobe for all IR bits D in Q out decode instruction strobe to finish instruction (to all bits) ripple8 7+4 8 output bits flip-flop strobe for next instruction Instruction Decoding Guide 2 3 5 05 addn r3, 4 Just explain the pieces. This is a SIMPLE model! Direct their attention to the bottom right table. It's a simple 4 instruction machine! More to come.... 00 = LOAD from memory 01 = STORE to memory 10 = add a constant to a reg. (addn) 11 = ADD a reg. to a reg.

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 Stress Levels of abstraction! We want to think at a higher level. Assembly language! Hmmm the machine in text starting on page 76. r0 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

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)

What will this program output? Suppose your input is 42 when line 0 is executed read r1 r1 General-purpose register r1 setn r2 9 1 r2 (x-9) 2 sub r3 r1 r2 General-purpose register 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 (x-9) // 9 3 div r3 r3 r2 r3 ((x-9) // 9) - 1 addn r3 -1 4 General-purpose register r3 What is the equivalent expression in 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 ex4.hmmm Computes x = r1**2 + r1 And, outputs x infinitely Discuss how "jump 1" works by placing a 1 in PC register. add r2 r2 r1 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 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 ex5.hmmm This computes the absolute value of the input, so the output is 6 5 nop With an input of -6, what does this code write out? 6 nop 7 write r1 8 halt What function is this? (A) -42 (B) -6 (C) -1 (D) 6 (E) 42