Introduction to Assembly Programming Computer Architecture.

Slides:



Advertisements
Similar presentations
Instruction Set Design
Advertisements

Microprocessors Typical microprocessor controlled devices: Camera, mobile phone, stereo, mp3 player, electronic toys… High-level microprocessor controlled.
Chapter 2 Data Manipulation Dr. Farzana Rahman Assistant Professor Department of Computer Science James Madison University 1 Some sldes are adapted from.
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
Assembly Language for Intel-Based Computers, 4 th Edition Chapter 1: Basic Concepts (c) Pearson Education, All rights reserved. You may modify and.
Instruction Set Architecture Classification According to the type of internal storage in a processor the basic types are Stack Accumulator General Purpose.
 Suppose for a moment that you were asked to perform a task and were given the following list of instructions to perform:
Lecture 1: Overview of Computers & Programming
Basic Input Output System
General information Course web page: html Office hours:- Prof. Eyal.
Chapter 9_3 Following Instructions: Principles of Computer Operation.
CSCE 121, Sec 200, 507, 508 Fall 2010 Prof. Jennifer L. Welch.
Introduction to Microprocessors Number Systems and Conversions No /6/00 Chapter 1: Introduction to 68HC11 The 68HC11 Microcontroller.
Recap – Our First Computer WR System Bus 8 ALU Carry output A B S C OUT F 8 8 To registers’ input/output and clock inputs Sequence of control signal combinations.
Henry Hexmoor1 Chapter 10- Control units We introduced the basic structure of a control unit, and translated assembly instructions into a binary representation.
IT Systems Memory EN230-1 Justin Champion C208 –
Topic 1: Introduction to Computers and Programming
CS102 Introduction to Computer Programming
Chapter 1: Introduction to Visual Basic.NET: Background and Perspective Visual Basic.NET Programming: From Problem Analysis to Program Design.
Operating Systems What do you have left on your computer after you strip away all of the games and application programs you bought and installed? Name.
Computer Organization
Basic Input Output System
Lesson 3 — How a Computer Processes Data
An Introduction Chapter Chapter 1 Introduction2 Computer Systems  Programmable machines  Hardware + Software (program) HardwareProgram.
Topics Introduction Hardware and Software How Computers Store Data
Computing Hardware Starter.
Learning Targets Identify the external parts of the computer Identify examples of input devices Identify examples of output devices Define basic computer.
CSU0014 Assembly Languages Homepage: Textbook: Kip R. Irvine, Assembly Language for Intel-Based Computers,
Summer 2014 Chapter 1: Basic Concepts. Irvine, Kip R. Assembly Language for Intel-Based Computers 6/e, Chapter Overview Welcome to Assembly Language.
 Design model for a computer  Named after John von Neuman  Instructions that tell the computer what to do are stored in memory  Stored program Memory.
COMP2011 Assembly Language Programming and Introduction to WRAMP.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 1 Introduction to Computers and Programming.
Computer Systems Organization CS 1428 Foundations of Computer Science.
Implementation of a Stored Program Computer ITCS 3181 Logic and Computer Systems 2014 B. Wilkinson Slides2.ppt Modification date: Oct 16,
Chapter 4 MARIE: An Introduction to a Simple Computer.
Lesson 3 — How a Computer Processes Data Unit 1 — Computer Basics.
Basic of Programming Language Skill Area Computer System Computer Program Programming Language Programmer Translators.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Memory: Relocation.
Introduction to Computer Application (IC) MH Room 517 Time : 7:00-9:30pm.
1 Text Reference: Warford. 2 Computer Architecture: The design of those aspects of a computer which are visible to the programmer. Architecture Organization.
Electronic Analog Computer Dr. Amin Danial Asham by.
Chapter 1 : Overview of Computer and Programming By Suraya Alias
ALU (Continued) Computer Architecture (Fall 2006).
Digital Computer Concept and Practice Copyright ©2012 by Jaejin Lee Control Unit.
Control units In the last lecture, we introduced the basic structure of a control unit, and translated our assembly instructions into a binary representation.
Digital Computer Concept and Practice Copyright ©2012 by Jaejin Lee Control Unit.
CC410: System Programming Dr. Manal Helal – Fall 2014 – Lecture 10 – Loaders.
IC 3 BASICS, Internet and Computing Core Certification Computing Fundamentals Lesson 2 How Does a Computer Process Data?
Some of the utilities associated with the development of programs. These program development tools allow users to write and construct programs that the.
F453 Module 8: Low Level Languages 8.1: Use of Computer Architecture.
Computer Basics.
Invitation to Computer Science 6th Edition
Topic 2: Hardware and Software
Today’s Agenda Exam 2 Part 2 (11:15am-12:30pm)
Topics Introduction Hardware and Software How Computers Store Data
Control Unit Lecture 6.
Overview of Computers and Programming Chapter 1
Microprocessor and Assembly Language
Review of computer processing and the basic of Operating system
TRANSLATORS AND IDEs Key Revision Points.
Computers: Hardware and Software
Chapter One: Introduction
Lesson Objectives Aims Key Words Compiler, interpreter, assembler
9.0 EMBEDDED SOFTWARE DEVELOPMENT TOOLS
Topics Introduction Hardware and Software How Computers Store Data
Embedded System Development Lecture 13 4/11/2007
MARIE: An Introduction to a Simple Computer
MARIE: An Introduction to a Simple Computer
A Discussion on Assemblers
Presentation transcript:

Introduction to Assembly Programming Computer Architecture

Von Newmann Architecture Von Newmann was the scientist to invent the “Stored Program” concept where data and instructions are stored in the same memory –There is no clear delineation between data and instructions in memory Same memory location can be data or instruction! –The distinction is made depending on how the microprocessor is instructed to interpret memory contents. Memory location is considered an instruction if microprocessor fetches it for processing as an instruction. Interpretation of memory content as data is performed using suitable instructions.

Storing programs Executable programs are typically stored directly in binary form With mix of data and instructions based on the von newmann stored program concept. Usually viewed as hexadecimal representation –Easy to load into memory and execute Negative is that without additional knowledge it is impossible to distinguish between data and instructions! –So how does a computer correctly execute a program?

Symbol Table Solution: Symbol Table –A table that specifies the list of symbols used in a program along with their addresses –An example symbol table is shown below: Symbol tables are embedded as a part of the binary file using special file organization (standards such as.EXE etc.) SymbolAddress (Hex) _start0F r24 elsePart20 done22

Need for Mnemonics A modern microprocessor has a large number of instructions Typically more than 100 different instructions –Developing bit patterns (series of 1s and 0s) and hex encodings for each instruction is too cumbersome Imagine writing a complex program in hex! –BTW people used to do it! –And they still do it in certain cases It is hard to develop, document, troubleshoot, and maintain

Mnemonics The issues with developing programs led to the use of mnemonics to describe instructions Mnemonic –Is a easier to remember word that corresponds to an operation –Rather than remembering bit patterns you remember words –Examples: OP CodeMnemonic Add Sub And Or

Tradeoffs with Mnemonics Advantages of mnemonics –The objective is ease representation and understanding of machine language programs. Use of mnemonics was a huge shift in programming paradigm Not comparable to high level programming languages –They are still prevalently used to describe instructions that can be processed by microprocessors Drawbacks –The drawback is that they require additional processing or manual translation to binary code. –Not standardized, even today Consequently different tools and processors use different conventions and notations! –Have to know specifics of microprocessor to use.

Commonly used mnemonics MnemonicDescription Mov/MoveCopy value from one location to another AddAdd two values together and store result in register. SubSubtract one value from another and store result in a register. CmpCompare two values and set flags to reflect result of operation. JmpBranch to a given address. JNZJump if Not Zero, conditionally branch if zero flag is 0.

Muddleheaded with Mnemonics For instance consider the following typical usage of the mov mnemonic: mov reg1, reg2 –How to interpret the above representation? Does it mean reg1 = reg2 or Does it mean reg2 = reg1 –There is no correct answer! Both conventions are used and different tools use different conventions You just have to know the specifics of the tool or manual to figure out the correct interpretation!

Addresses in Mnemonics Memory addresses are used in two different ways in programs –Used to load or store data Typically variables or symbols are associated with memory addresses in these cases –Used as target of branch or jump instructions Identifies location of next instruction to be executed

Extending to handle Variables Mnemonics were extended to ease representation and use of addresses for storing and retrieving data By associating variables or symbols with address locations –Example Let symbol sum be associated with address C3 16 To store constant value 31 into address C3 16 mnemonic could be written as: mov $31, sum

Extending to handle Branching Mnemonics were extended to ease representation and use of addresses for conditional and unconditional branching by using labels. A label is a symbols that points to a specified address where some instruction is stored. –Example Let label “end” be associated with address 1E 16 To jump to instruction stored at 1E 16, mnemonic could be written as: jmp end

A Program using Mnemonics ; Semicolon indicates start of comment ; Program does: if (r == 10) sum = 20 ; else sum = 30 _start: mov r, Reg1 ; Reg1 = r mov $10, Reg2 ; Reg2 = 10 sub Reg1, Reg2 ; Reg2 = Reg2 – Reg1 jnz elsePart ; Jump if Reg1 != Reg2 mov $20, Reg0 ; Reg0 = 20 jmp done ; Jmp to done elsePart: mov $30, Reg0 ; Reg0 = 30 done: mov Reg0, sum ; sum = Reg0

Symbol Table An example symbol table is shown below: –Addresses calculated assuming that Program is stored consecutively starting with address 0F 16 Each instruction occupies 2 bytes in memory. SymbolAddress (Hex) _start0F r24 elsePart20 done22

Assembly Language High level mnemonic representation using variables and labels is called assembly language Typically includes a few additional program constructs for defining variables and constants. –Commonly used for device level programming Developing operating systems Developing device drivers Ultra-optimizing programs for specific hardware Tapping into special features of the processor Developing embedded programs that don’t rely on OS or other environments (like JVM) For timing critical operations and for real time systems

Advantages of Assembly Maximum power & control on hardware Can’t get closer to hardware than this using software! –Enables development of ultra-optimized code Tailored for a specific microprocessor Code can be compacted –Can tap into special features of the microprocessor –Directly interface with devices and peripherals –Provides accurate control on timing Needed for interfacing with high speed devices like: network, hard disk, USB, CD-ROM, DVD-ROM, Video Card, FireWire

Disadvantages of Assembly Least portable –Typically tailored for specific microprocessor & operating system –However, x86 is most dominant these days. So portability issues are typically myths. Hard to develop, troubleshoot, and maintain –Depends on how you develop the code –You can spend long time troubleshooting Java Requires “Out of the Box” thinking –Most programmers have problems with this part.

Need for Assembler Ultimately the microprocessor requires instructions to be stored in binary format that can be easily processed. –Similar to the bits we used in our data path However, assembly language programs are not in binary! –Need a tool to convert assembly to pure binary

Assembler Assembler is a program that converts assembly code to binary It is essentially a compiler just like the Java compiler –Handles address allocation for variables and labels –Generates symbol table for the program –Includes other constructs to make program development easier Like including or importing other assembly source codes and libraries

Using an assembler Text Editor (Notepad) Assembly Source (Text file saved on disk) Assembler (Software) (Compile source to binary) Binary (Object code. File on disk) Linker (Software) (Combine object codes & libraries into a single binary ) Other binaries & libraries on disk Executable Binary (File on disk) Has a special file format (similar to GIF, JPEG etc.) to contain instructions, data, and the symbol table.

How does binary get into memory? The generated binary code needs to be placed in memory for the data path to process! This job is typically done by the operating system –A special piece of the operating system called the loader does the job. Loader requires the executable to be in a specific file format –Loader reads the executable, places it in memory, and changes the next instruction to refer to the first instruction in the loaded program! –The program then starts running The program typically uses the operating system services (via library calls) to ease performing specific operations (like input and output)

How does the OS get into memory? The OS is just another program that is run by the microprocessor. How does the OS get into memory? –It is loaded by another program called the Basic Input Output System or BIOS BIOS actually loads only a small program called the boot loader. The boot loader then loads the whole OS into memory. How does the BIOS get into memory? –It is hardwired to the data path using non-volatile Read-Only Memory (ROM)

What is ROM ROM or Read Only Memory Can be programmed to hold fixed data Writing to it is reserved or restricted –Has similar configuration to Read-Write Memory Uses address bus to randomly select location to read –So it is a Random Access Memory (RAM) Places the byte requested on the data bus. –Manufactured using a different processes A variety of ROM modules are available but most commonly used ones are called Flash memory –Flash is an EEPROM (Electrically Erasable and Programmable Read Only Memory) –Flash enables updating of BIOS without removing the ROM chip out of the computer using software

Example ROM & RAM Layout ROM (BIOS) Read Write Memory Address Bus Data Bus EN 8 8 Most significant bit of address Bus. If this bit is 1, the ROM is enabled. For reading. Otherwise the Read-Write Memory is enabled!

BIOS Microprocessor Interface Microprocessors are designed to generate a specific initial starting address –The first instruction to be executed when the processor is turned on by applying power to it –The logic circuit is designed to map this address into the ROM BIOS’s first instruction The BIOS runs and loads the boot loader from disk into specific memory locations in read-write memory The BIOS then jumps to the first instruction in the boot loader program which causes boot loader to run. Boot loader is a software that further loads the actual OS into read-write memory