Computer Science 101 Assembly Language. Problems with Machine Language Uses binary - No English-like words to make it more readable Uses binary - No English-like.

Slides:



Advertisements
Similar presentations
Chapter 8 ICS 412. Code Generation Final phase of a compiler construction. It generates executable code for a target machine. A compiler may instead generate.
Advertisements

CHAPTER 2 GC101 Program’s algorithm 1. COMMUNICATING WITH A COMPUTER  Programming languages bridge the gap between human thought processes and computer.
2.3) Example of program execution 1. instruction  B25 8 Op-code B means to change the value of the program counter if the contents of the indicated register.
The assembler is the system program that translate source code written in assembly language to object code( Machine Language) and other information for.
PSEUDOCODE & FLOW CHART
The Little man computer
The CPU Revision Typical machine code instructions Using op-codes and operands Symbolic addressing. Conditional and unconditional branches.
ITEC113 Algorithms and Programming Techniques
19-1 Programming… The Pencil and Paper Computer The Pencil & Paper Instruction Set: (table on p148) The Operand specifies a memory location.
Chapter 6: An Introduction to System Software and Virtual Machines Invitation to Computer Science, C++ Version, Third Edition.
Chapter 6 In introduction to System Software and Virtual Machine ***Assembly Language.
Chapter 6: An Introduction to System Software and Virtual Machines Invitation to Computer Science, C++ Version, Third Edition.
1 Lab Session-IV CSIT-120 Spring 2001 Lab 3 Revision and Exercises Rev: Precedence Rules Lab Exercise 4-A Machine Language Programming The “Micro” Machine.
Assembly Language Programming. CPU The CPU contains a Control Unit, Arithmetic Logic Unit (ALU) and a small number of memory locations called Registers.
Programming and Problem Solving
Dr Verbrugge Simulated Machine Simulated Machine Problem: Find the Average of the following three numbers: 5, 7, 10 Average = 7 with a remainder of 1.
Chapter 7 Low-Level Programming Languages. 2 Chapter Goals List the operations that a computer can perform Discuss the relationship between levels of.
Programming Logic and Design, Introductory, Fourth Edition1 Understanding Computer Components and Operations (continued) A program must be free of syntax.
Chapter 6: An Introduction to System Software and Virtual Machines
Chapter 6: An Introduction to System Software and Virtual Machines Invitation to Computer Science, C++ Version, Fourth Edition ** Re-ordered, Updated 4/14/09.
1 CS Programming Languages Random Access Machines Jeremy R. Johnson.
Writing an Assembly-language program Atmel assembly language CS-280 Dr. Mark L. Hornick 1.
Machine level architecture Computer Architecture Basic units of a Simple Computer.
Computer Science 101 Introduction to Programming.
GCSE Computing#BristolMet Session Objectives#11 MUST identify what program instructions consist of SHOULD describe how instructions are coded as bit patterns.
Invitation to Computer Science 5 th Edition Chapter 6 An Introduction to System Software and Virtual Machine s.
Computer Science 101 How the Assembler Works. Assembly Language Programming.
Lecture 15 Today’s lecture MARIE programming Assembler
Problem Solving Techniques. Compiler n Is a computer program whose purpose is to take a description of a desired program coded in a programming language.
Chapter 1 Introduction Chapter 1 Introduction 1 st Semester 2015 CSC 1101 Computer Programming-1.
Computer Science/Ch. 5 System Softwares 5-1 Chapter 5 System Softwares.
Computer Science 210 Computer Organization More on Assembler.
CHAPTER 1 INTRODUCTION 1 st Semester H King Saud University College Of Applied Studies and Community Services CSC 1101 Computer Programming-1.
1 Ethics of Computing MONT 113G, Spring 2012 Session 7 Computer Architecture The Internet.
Computer Science 101 Computer Systems Organization ALU, Control Unit, Instruction Set.
CMSC 150 PROGRAM EXECUTION CS 150: Wed 1 Feb 2012.
1 Program Planning and Design Important stages before actual program is written.
CHAPTER 1 INTRODUCTION 2 nd Semester H King Saud University College Of Applied Studies and Community Services CSC 1101 Computer Programming-1.
Computer Science 101 Computer Systems Organization Machine Language Examples Entire machine.
1 3. Computing System Fundamentals 3.1 Language Translators.
Computer Architecture CSE 3322 Lecture 3 Assignment: 2.4.1, 2.4.4, 2.6.1, , Due 2/3/09 Read 2.8.
Represents different voltage levels High: 5 Volts Low: 0 Volts At this raw level a digital computer is instructed to carry out instructions.
ICC Module 3 Lesson 1 – Computer Architecture 1 / 26 © 2015 Ph. Janson Information, Computing & Communication Computer Architecture Clip 1 – Assembler.
An Example Architecture. A Paper Computer - Woody Woody's characteristics Word size – 8 bits One word.
Algorithm Discovery and Design Objectives: Interpret pseudocode Write pseudocode, using the three types of operations: * sequential (steps in order written)
Flowchart. a diagram of the sequence of movements or actions of people or things involved in a complex system or activity. a graphical representation.
Translating Assembly Language to Machine Language.
Introduction to Computer Programming Concepts M. Uyguroğlu R. Uyguroğlu.
Low-Level Programming Languages, Pseudocode and Testing Chapter 6.
Instruction Memory value Description ADD1xx Add the value stored at memory address xx to the value in the accumulator register SUB2xx Subtract the value.
Invitation to Computer Science 6th Edition
The Little man computer
Computer Science 210 Computer Organization
Computer Programming.
Assembly Language Programming of 8085
COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE
Assembly Language Assembly Language
Starter Read the Feedback Click on Add new Feedback Open Realsmart
The Processor and Machine Language
Computer Science 210 Computer Organization
Computer Programming Machine and Assembly.
Assembler CASE Tool.
Lesson 2 Programming constructs – Algorithms – Scratch – Variables Intro.
Making Programming Friendlier
Sequencing, Selection, and Loops in Machine Language
Chapter 7 Assembly Language
8 Code Generation Topics A simple code generator algorithm
CPSC 171 Introduction to Computer Science
Algoritmos y Programacion
Presentation transcript:

Computer Science 101 Assembly Language

Problems with Machine Language Uses binary - No English-like words to make it more readable Uses binary - No English-like words to make it more readable Only numeric memory addresses - Can not name an instruction or data location Only numeric memory addresses - Can not name an instruction or data location Difficult to change - If we leave out one instruction, all addresses from that point on will be incorrect. Difficult to change - If we leave out one instruction, all addresses from that point on will be incorrect. Difficult to create data - Must use internal binary representation Difficult to create data - Must use internal binary representation

Assembly Language to the Rescue! Symbolic operation codes: Load, Store, Jump, Compare, etc. Symbolic operation codes: Load, Store, Jump, Compare, etc. Symbolic names (user defined) for memory addresses Load Pay Symbolic names (user defined) for memory addresses Load Pay Pseudo-operations provide services such as data generation. Pseudo-operations provide services such as data generation.

Assembler An assembler is a program that takes a source code program written in assembly language and converts it to a machine language object file. An assembler is a program that takes a source code program written in assembly language and converts it to a machine language object file. Essentially a line by line translation. Essentially a line by line translation. Assembly lang Source file Assembler Machine lang Object file

Labels: Giving names to locations. We can attach a symbolic name to any instruction or data location by beginning the line with a label with that name. We can attach a symbolic name to any instruction or data location by beginning the line with a label with that name. A label consists of the name followed by a colon. A label consists of the name followed by a colon. You use labels in all of the places that addresses would occur in machine language; i.e. you no longer use numeric addresses. You use labels in all of the places that addresses would occur in machine language; i.e. you no longer use numeric addresses. –Address fields in instructions  Operands of computations  Targets of branch instructions

Pseudo-operations Pseudo-operations are not statements that are converted to machine code. They are used to request services of the assembler. Performed only when program assembled. Pseudo-operations are not statements that are converted to machine code. They are used to request services of the assembler. Performed only when program assembled. Hypothetical Machine Pseudo-Ops: Hypothetical Machine Pseudo-Ops: All of the pseudo-ops begin with a period..begin -- required to mark beginning.begin -- required to mark beginning.end -- required to mark end.end -- required to mark end.data puts a value at the memory location; value in decimal assembler converts to binary.data puts a value at the memory location; value in decimal assembler converts to binary

Example: Add X to Y and Store in Z Z = X + Y.begin load X add Y store Z halt X:.data 33 Y:.data 40 Z:.data 0.end

Developing Assembly Programs First write your algorithm in pseudocode. First write your algorithm in pseudocode. Then convert to assembly. Then convert to assembly. Convert computations using labeled memory locations and the register for variables - document these. Convert computations using labeled memory locations and the register for variables - document these. We’ll look at techniques for converting common control flow constructs to assembly language. We’ll look at techniques for converting common control flow constructs to assembly language.

Converting Set (Assignment) Statements Set to Set to Semantics: Compute value of the expression Give this value to the variable Semantics: Compute value of the expression Give this value to the variable Assembly language: Accumulate value of expression in R Store the value in the variable’s location Assembly language: Accumulate value of expression in R Store the value in the variable’s location

Example Set X to 2Y + Z – 5 Set X to 2Y + Z – 5 load Y add Y add Z subtract FIVE store X … X:.data 0 Y:.data 20 Z:.data 30 FIVE:.data 5 … load Y add Y add Z subtract FIVE store X … X:.data 0 Y:.data 20 Z:.data 30 FIVE:.data 5 …

Converting If-statements If X  Y then Statements A Statements B If X  Y then Statements A Statements B load X load X compare Y compare Y jumpgt BSpot jumpgt BSpot … Translation of A... … Translation of A... BSpot: … Translation of B A Code B Code T F Cond

If-statement example User inputs number. If number is greater than 5 we output the number. User inputs number. If number is greater than 5 we output the number. Pseudocode: Get N If N>5 then Print N Stop Pseudocode: Get N If N>5 then Print N Stop.begin.begin in N in N load N load N compare FIVE compare FIVE jumpgt DONE jumpgt DONE jumpeq DONE jumpeq DONE out N out N DONE: halt N:.data 0 FIVE:.data 5.end

Converting If-else-statements If X  Y then Statements A If X  Y then Statements A else Statements B else Statements B Statements C Statements C load X load X compare Y compare Y jumpgt Else jumpgt Else … Translation of A... … Translation of A... Else: … Translation of B … … Translation of C … Translation of C jump CSpot CSpot: Cond A Code C Code TF BCode

Converting While-statements While X  Y Do Statements A While X  Y Do Statements A Statements B Statements B load X load X compare Y compare Y jumpgt BSpot jumpgt BSpot … Translation of A... … Translation of A... BSpot: … Translation of B … jump WHILE WHILE: B Code A Code T F Cond

While-statement example Program outputs sum of 10 numbers entered by the user. Program outputs sum of 10 numbers entered by the user. Pseudocode: Set Ct to 10 Set Sum to 0 While Ct>0 Get Num Set Sum to Sum+Num Set Ct to Ct-1 Print Sum Stop Pseudocode: Set Ct to 10 Set Sum to 0 While Ct>0 Get Num Set Sum to Sum+Num Set Ct to Ct-1 Print Sum Stop.begin.begin load TEN store CT load TEN store CT clear SUM clear SUM WHILE: load CT compare ZERO compare ZERO jumpeq PRNT jumpeq PRNT in NUM in NUM load NUM load NUM add SUM add SUM store SUM store SUM decrement CT decrement CT jump WHILE jump WHILE PRNT: out SUM PRNT: out SUM halt halt

While-statement example (cont.).begin load TEN store CT load TEN store CT clear Sum clear Sum WHILE: load CT compare ZERO compare ZERO jumpeq PRNT jumpeq PRNT in NUM in NUM load NUM load NUM add SUM add SUM store SUM store SUM decrement CT decrement CT jump WHILE jump WHILE PRNT: out SUM PRNT: out SUM halt halt TEN:.data 10 CT:.data 0 SUM:.data 0 NUM:.data 0 ZERO:.data 0.end