GCSE COMPUTER SCIENCE Computers 1.5 Assembly Language.

Slides:



Advertisements
Similar presentations
GCSE Computing Lesson 5.
Advertisements

Slides created by: Professor Ian G. Harris Efficient C Code  Your C program is not exactly what is executed  Machine code is specific to each ucontroller.
Dr. Ken Hoganson, © August 2014 Programming in R COURSE NOTES 2 Hoganson Language Translation.
Week 3. Assembly Language Programming  Difficult when starting assembly programming  Have to work at low level  Use processor instructions >Requires.
Chapter 10- Instruction set architectures
Machine Instructions Operations 1 ITCS 3181 Logic and Computer Systems 2015 B. Wilkinson Slides4-1.ppt Modification date: March 18, 2015.
 Suppose for a moment that you were asked to perform a task and were given the following list of instructions to perform:
The CPU Revision Typical machine code instructions Using op-codes and operands Symbolic addressing. Conditional and unconditional branches.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design First Edition by Tony Gaddis.
Assembly Language Programming. CPU The CPU contains a Control Unit, Arithmetic Logic Unit (ALU) and a small number of memory locations called Registers.
Assembly & Machine Languages
Activity 1 - WBs 5 mins Go online and spend a moment trying to find out the difference between: HIGH LEVEL programming languages and LOW LEVEL programming.
1 I.Introduction to Algorithm and Programming Algoritma dan Pemrograman – Teknik Informatika UK Petra 2009.
Topic 8: Data Transfer Instructions CSE 30: Computer Organization and Systems Programming Winter 2010 Prof. Ryan Kastner Dept. of Computer Science and.
Assembly Programming on the TI-89 Created By: Adrian Anderson Trevor Swanson.
The CPU The Central Presentation Unit Main Memory and Addresses Address bus and Address Space Data Bus Control Bus The Instructions set Mnemonics Opcodes.
Lecture 2: Basic Instructions CS 2011 Fall 2014, Dr. Rozier.
Lecture 2: Basic Instructions EEN 312: Processors: Hardware, Software, and Interfacing Department of Electrical and Computer Engineering Spring 2014, Dr.
Basic of Programming Language Skill Area Computer System Computer Program Programming Language Programmer Translators.
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.
Arrays and Strings in Assembly
Computer Systems – Machine & Assembly code. Objectives Machine Code Assembly Language Op-code Operand Instruction Set.
CMSC 104, Lecture 061 Stored Programs A look at how programs are executed.
The Functions and Purposes of Translators Translators, Interpreters and Compilers - High Level Languages.
Digital Computer Concept and Practice Copyright ©2012 by Jaejin Lee Control Unit.
Representation of Data Binary Representation of Instructions teachwithict.weebly.com.
Assembly Variables: Registers Unlike HLL like C or Java, assembly cannot use variables – Why not? Keep Hardware Simple Assembly Operands are registers.
Programming Languages
Lecture 6: Decision and Control CS 2011 Spring 2016, Dr. Rozier.
Computer Basics.
Why don’t programmers have to program in machine code?
Component 1.6.
central heating system
Unit 2.5 Translators and Facilities of Languages – Lesson 1
High and low level languages
Assembly Language (CSW 353)
Introduction to programming
Operating System Interface between a user and the computer hardware
CSCI-235 Micro-Computer Applications
Assembly Language Programming of 8085
Microprocessor T. Y. B. Sc..
Assembly Language Assembly Language
The Cortex-M3/m4 Embedded Systems: Cortex-M3/M4 Instruction Sets
Microprocessor and Assembly Language
Machine code Recall that all a computer recognises is binary code.
1. Introduction A microprocessor executes instructions given by the user Instructions should be in a language known to the microprocessor Microprocessor.
A451 Theory – 7 Programming 7A, B - Algorithms.
Processor Instructions set. Learning Objectives
Teaching Computing to GCSE
TRANSLATORS AND IDEs Key Revision Points.
Teaching Computing to GCSE
Translators & Facilities of Languages
Assembler, Compiler, Interpreter
CSCE Fall 2013 Prof. Jennifer L. Welch.
Lesson Objectives Aims Key Words Compiler, interpreter, assembler
Fundamentals of Computer Organisation & Architecture
CSCE 121: Simple Computer Model Spring 2015
Autumn Term Year 10 Slides
Programming Languages
Assembler, Compiler, Interpreter
CSCE Fall 2012 Prof. Jennifer L. Welch.
Mastering Memory Modes
ICT Programming Lesson 1:
Understand the interaction between computer hardware and software
What is Programming Language
1.3.7 High- and low-level languages and their translators
WJEC GCSE Computer Science
Branch & Call Chapter 4 Sepehr Naimi
Algoritmos y Programacion
Presentation transcript:

GCSE COMPUTER SCIENCE Computers 1.5 Assembly Language

Processor Families There are two families of processor, each family has a different instruction set. X86 Family ARM Family Use in most laptops, desktop and servers. Use in most smartphones and tablets. Watch this video to find out more about the ARM family of processors.

Machine Code Each type of CPU is designed to carry out a set of specific instructions. Each instruction is represented by binary number. This is called machines code. Machine Code Assembly Language 1110 0011 1010 0000 0000 0000 0000 0010 MOV R0, #2 1110 0010 0100 0011 0001 0000 0000 1010 SUB R1, R3, #10 1110 0000 1000 0000 0000 0000 0000 0001 ADD R0, R0, R1 1110 0000 0000 0011 0000 0101 1001 0100 MUL R3, R4, R5 It is hard for humans to read and write machines code so assembly language was developed to make it easier.

Python Assembly language is an example of a low-level language. An advantage of low-level languages is it allows you to have direct control of the CPU. Python is an example of a high-level language. An advantage of high level language is that it is closely resembles natural language. High-level language instructions represent several CPU instructions, unlike machine code and assembly language.

Assembly Language (Low-level) Activity 1 Draw and match the phrase to the correct part of the diagram. sum1 = num1 + num2 sum2 = num1 * num2 Compiler Assembler ADD R0, R0, R1 MUL R3, R4, R5 Machine Code Assembly Language (Low-level) Python (High-level) 1111000011110000 0101110100110010

Activity 2 Copy and match each assembly instruction with the correct action: ADD Load from memory address into a register SUB Branch to a marked position in the program MUL Move data to a register MOV Store data in a register CMP Subtract data in a register LDR Compare values in a register B Multiply data in a register STR Add data in a register

Instruction Format ADD R0, R1, #5 MOV R0, #5 SUB R2, R2, R4 This is the standard format for writing instructions in assembly language. opcode operand ADD R0, R1, #5 MOV R0, #5 SUB R2, R2, R4 operation destination input input

Example MOV R3, #5 SUB R1, R1, #2 MUL R0, R1, R3 ADD R1, R1, R0 Moves the value 5 into register location 3. MOV R3, #5 Register R0 30 R1 8 R2 R3 5 R4 6 36 Subtracts 2 from the value in R1 and stores the result in R1. SUB R1, R1, #2 Multiplies the values in R1 and R3 and stores the result in R0. MUL R0, R1, R3 Add the value in R1 to the value in R0 and stores the result in R1. ADD R1, R1, R0

What does this instruction ask the processor to do? Activity 3 Label the assembly language instruction to show the opcode, destination and two input operands. opcode SUB R0 R1 R2 destination Input(s) QUESTION What does this instruction ask the processor to do?

Moves the value 1 into Register 5. Activity 4 Test what you have learnt so far by answering these questions: Question Answer Write the instruction to add the value 8 to the contents of register R2 and store the result in register R4. ADD R4, R2, #8 Write the instruction to multiply the contents of register R1 by the contents of register R2 and store the result in register R0. MUL Ro, R1, R2 What does this instructions ask the processor to do? MOV R5, #1 Moves the value 1 into Register 5.

Show the contents of the registers as each instruction is executed: Activity 5 Show the contents of the registers as each instruction is executed: Hint: the MOV command actually puts a copy of the data in the specified register. The original stays where it is. R0 R1 R2 5 3 MOV R0, R1 MOV R1, R2

Activity 6 Show the contents of the registers as each instruction is executed: Show the contents of the registers as each instruction is executed: Hint: the MOV command actually puts a copy of the data in the specified register. The original stays where it is. R0 R1 R2 9 5 3 MOV R0, #0 ADD R0, R0, R1 SUB R0, R0, R2 2 MUL R0, R1, R2 15

Show the contents of the registers as each instruction is executed: Activity 7 Show the contents of the registers as each instruction is executed: R0 R1 R2 4 2 MUL R0, R1, R2 MUL R1, R0, R2 8 16 v

Show the contents of the registers as each instruction is executed: Activity 8 Show the contents of the registers as each instruction is executed: R0 R1 R2 7 5 SUB R0, R1, #3 4 ADD R2, R2, #1 6 SUB R0, R1, R2 1

Conditions CMP R0, R1 ADD EQ R0, R0, #5, This is the standard format for writing instructions in assembly language. CMP R0, R1 Codes EQ equal NE not equal GT greater than LT less than GE greater or equal to LE less than or equal to ADD EQ R0, R0, #5, opcode operands condition These instructions compare the values in R0 and R1, if they are equal the value 5 will added be to the value in R0 and the result will be stored in R0.

Activity 9 Explain what this piece of code does: CMP R0, R1 MOVGT R2, R0 Compares the values in R0 and R1. Moves R0 into R2 if R0 is Greater Than R2. Explain what each line of this code does: MOV R0, #5 Moves the value 5 into R0. MOV R2, #6 Moves the value 6 into R2. CMP R0, R2 Compares the values in R0 and R1. MOVEQ R3, R0 Moves R0 in R3 if they are equal. MOVNE R3, R2 Moves R2 into R3 if the values are not equal.

Activity 10 What will be the outcome of executing this piece of code if register R0 holds the value 9 and register R1 holds the value 15? CMP R0, R1 SUBGT R0, R1, R0 SUBLT R0, R1, R0 Compares the value of R1 (15) with R0 (9). If R0 is > R1 subtract R0 from R1 and stores in R0. False. If R0 is < R1 subtract R0 from R1 and store in R1. True, so 15-9 = 6. What will be the outcome of executing this piece of code if register R0 held the value 3 and register R1 held the value 3? CMP R0, R1 ADDGT R0, R0, R1 ADDLT R1, R1, R0 Compares the value of R0 (3) with R1 (3). If R1 is > R0 Add R1 to R0 and store in R0. False. If R0 is < R1 Add R0 to R1 and store in R1. False.

Activity 11 There are two methods of converting high-level code to machine code. Carry out some research and find a definition for each one. Compiler A compiler translates the whole program into machine code before the program is run. It can be difficult to test individual lines of compiled code compared to interpreted languages as all bugs are reported after the program has been compiled. Java and C++ are compiled programming languages. Interpreter An interpreter translates code into machine code, instruction by instruction - the CPU executes each instruction one at a time. Interpreted code will show an error as soon as it hits a problem, so it is easier to debug than compiled code. Interpreted code is slower to execute than compiled code. Interpreted languages include JavaScript, PHP, Python and Ruby.

Why Bother? Most software is NOT written in assembly language because: It’s time-consuming to develop; It’s not portable across different types of processors. BUT, assembly language is useful because: It enables programmers to write very efficient, performance-critical code; It gives you a better insight into how the processor works; It can be used to debug code that isn’t working as expected.