Assembly Language Programming. CPU The CPU contains a Control Unit, Arithmetic Logic Unit (ALU) and a small number of memory locations called Registers.

Slides:



Advertisements
Similar presentations
Chapter 2: Data Manipulation
Advertisements

 Suppose for a moment that you were asked to perform a task and were given the following list of instructions to perform:
Low-Level Programming Languages and Pseudocode Chapter 6.
The Little man computer
The CPU Revision Typical machine code instructions Using op-codes and operands Symbolic addressing. Conditional and unconditional branches.
19-1 Programming… The Pencil and Paper Computer The Pencil & Paper Instruction Set: (table on p148) The Operand specifies a memory location.
Computer Systems. Computer System Components Computer Networks.
TK 2633 Microprocessor & Interfacing Lecture 3: Introduction to 8085 Assembly Language Programming (2) 1 Prepared By: Associate Prof. Dr Masri Ayob.
Assembly Language Programming CS208. Assembly Language Assembly language allows us to use convenient abbreviations (called mnemonics) for machine language.
Low-Level Programming Languages
CSCE 121, Sec 200, 507, 508 Fall 2010 Prof. Jennifer L. Welch.
Stored Program Concept: The Hardware View
Room: E-3-31 Phone: Dr Masri Ayob TK 2633 Microprocessor & Interfacing Lecture 1: Introduction to 8085 Assembly Language.
Chapter 7 Low-Level Programming Languages. 2 Chapter Goals List the operations that a computer can perform Discuss the relationship between levels of.
Introduction to computer: executes instructions. Overview Topics discussed in this webnote: –Structure and operation of the CPU –Program flow –Types of.
Lecture 13 - Introduction to the Central Processing Unit (CPU)
Assembly & Machine Languages
Machine Instruction Characteristics
Low Level Programming Lecturer: Duncan Smeed Low Level Program Control Structures.
Stack Stack Pointer A stack is a means of storing data that works on a ‘Last in first out’ (LIFO) basis. It reverses the order that data arrives and is.
CSC 3210 Computer Organization and Programming Chapter 1 THE COMPUTER D.M. Rasanjalee Himali.
Chapter 10 The Assembly Process. What Assemblers Do Translates assembly language into machine code. Assigns addresses to all symbolic labels (variables.
The Central Processing Unit (CPU) and the Machine Cycle.
Model Computer CPU Arithmetic Logic Unit Control Unit Memory Unit
Module : Algorithmic state machines. Machine language Machine language is built up from discrete statements or instructions. On the processing architecture,
Lecture 14 Today’s topics MARIE Architecture Registers Buses
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 Operations A computer is a programmable electronic device that can store, retrieve, and process data Data and instructions to manipulate the data.
Programming, an introduction to Pascal
Computer Organization CSC 405 (VSC) Very Simple Computer.
A summary of TOY. 4 Main Components Data Processor Control Processor Memory Input/Output Device.
D75P 34 – HNC Computer Architecture
Chapter 7 Low-Level Programming Languages (slides modified by Erin Chambers)
Chapter 7 Low-Level Programming Languages Nell Dale John Lewis.
© 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.
COMPILERS CLASS 22/7,23/7. Introduction Compiler: A Compiler is a program that can read a program in one language (Source) and translate it into an equivalent.
An Example Architecture. A Paper Computer - Woody Woody's characteristics Word size – 8 bits One word.
Digital Computer Concept and Practice Copyright ©2012 by Jaejin Lee Control Unit.
Question What technology differentiates the different stages a computer had gone through from generation 1 to present?
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.
CMSC 104, Lecture 061 Stored Programs A look at how programs are executed.
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.
Review A program is… a set of instructions that tell a computer what to do. Programs can also be called… software. Hardware refers to… the physical components.
Lec 4-2 Five operations of the machine cycle Fetch- fetch the next program instruction from memory. (PC+1); instruction to IR Decode- decode the instruction.
Program to multiply 2 numbers 500-Input x 291-Store acc. as x 500-Input y 292-Store acc. as y 193-Load y in to acc. (0 on 1 st parse) 391-Add x to acc.
CPS4200 System Programming Spring 1 Systems Programming Chapter 1 Background I.
Low-Level Programming Languages, Pseudocode and Testing Chapter 6.
Little Man Computer Task 1 Last lesson you were asked to write a program to multiply two numbers together. The next slide has a working program to do this.
F453 Module 8: Low Level Languages 8.1: Use of Computer Architecture.
3.1.4 Hardware a. describe the function and purpose of the control unit, memory unit and ALU (arithmetic logic unit) as individual parts of a computer;
1 What we want: execute High Level Language (HLL) programs What we have: computer hardware (a glorified calculator)
The Little man computer
GCSE COMPUTER SCIENCE Computers 1.5 Assembly Language.
Control Unit Lecture 6.
Assembly Language Programming of 8085
Assembly Language Assembly Language
Processor Instructions set. Learning Objectives
Chapter 4 The Von Neumann Model
Starter Read the Feedback Click on Add new Feedback Open Realsmart
The Processor and Machine Language
CSCE Fall 2013 Prof. Jennifer L. Welch.
CSC 3210 Computer Organization and Programming
Computer Architecture
CSCE Fall 2012 Prof. Jennifer L. Welch.
Chapter 6 Programming the basic computer
Hmmm Assembly Language
COMPUTING.
Little Man Computer.
Presentation transcript:

Assembly Language Programming

CPU

The CPU contains a Control Unit, Arithmetic Logic Unit (ALU) and a small number of memory locations called Registers. Different registers perform different tasks such: –as manipulating data, –keeping track of the results of decision making operations, –and pointing to the next instruction to be executed.

CPU Registers The Instruction Register (IR) contains the actual instruction which is currently being executed by the CPU. The Status Register records the result of comparing the contents of register A with the contents of register B. The Program Counter (PC) contains the address of the next instruction to be executed by the program.

CPU Registers Registers A & B hold the operands for each arithmetic operation (ie. the values on which the operation will be performed). After the operation has been carried out, the result is always stored in Register B. Therefore, after an arithmetic operation has been performed, the second operand is no longer stored in Register B, because it has been overwritten by the result of the operation.

CPU Registers The computer also has a Compare instruction that can be used to compare the contents of register A with those of register B. The comparison can have three possible outcomes: –the contents of register A < B; –the contents of the register A = B; –the contents of the register A > B.

CPU Registers After a comparison has been done, the Status Register will hold a code that stores the results of the comparison. The results are coded as follows: -1 if (A < B); 0if (A = B); 1if (A > B).

Assembly language. Assembly language allows us to use convenient abbreviations (called mnemonics) for machine language operations and memory locations. Each assembly language is specific to a particular hardware architecture, and can only be used on a machine of that architecture. An assembly language program must be translated into machine code before it can be executed. The program that tells the computer how to perform the translation is called an assembler.

Assembly language. When a processor chip is designed, it is designed to understand and execute a set of machine code instructions (OpCodes) unique to that chip. One step up from machine code is assembly code. Each machine code instruction is given a mnemonic (name), so that it is easier for human beings to write code. There is a one-to-one correspondence between the assembly languages mnemonic instructions and the machine language numeric instructions. A list of assembly code instructions that will perform a task is called an assembly program.

Assembly language. OperationWhat it means to the CPU STP Stop the program LDA Load register A with contents of a specified memory location LDB Load register B with contents of a specified memory location STR Store register B contents to a specified memory location INP Store data input by user to a specified memory location PNT Print the contents of a specified memory location to the screen

Assembly language. OperationWhat it means to the CPU JLT Jump if less than (Status register = -1) to a specified memory location JGT Jump if greater than (Status register = 1) to a specified memory location JEQ Jump if equal (Status register = 0) to a specified memory location JMP Unconditional jump to a specified memory location CMP Compare register A to register B and set Status Register value

Assembly language. OperationWhat it means to the CPU ADD Add (register A + register B) and store sum in register B SUB Subtract (register A - register B)and store difference in register B MUL Multiply (register A * register B) and store product in register B DIV Divide for quotient (register A / register B) and store quotient in register B MOD Divide for remainder (register A / register B) and store remainder in register B

Steps to write Assembly Programs Create Pascal Program translate each Pascal statement to the equivalent assembly statement(s) Number the assembly language program starting from 0 Replace Memory names by number of empty memory cell Resolve jumps ( replace with number of memory cell jumping to)

Pascal to Assembly language. StatementAssembly equivalent programnone constput value in memory cell varput address of memory cell readlnINP writelnPNT assignment (:=) val3 = val1 + val2LDA Val1 LDB Val2 ADD STR Val3 End.STP

Assembly language. Program #1. Write an assembly language program that will get a number as input from the user, and output its square to the user.

Assembly language. step 1: algorithm to describe the steps needed to solve our problem.

Assembly language. step 1: algorithm to describe the steps needed to solve our problem. 1. Input a number and store it in memory. 2. Compute the square by multiplying the number times itself. 3. Output the results.

Assembly language. Step 2: write Pascal code

Assembly language. Step 2: write Pascal code Var number, square: integer; begin readln ( number); square := number * number ; writeln (square); end.

Assembly Language begin readln ( number); square := number*number; writeln (square); end. INP number LDA number LDB number MUL STR square PNT square STP

Assembly language. Step 4: Number assembly code lines starting from 0 0INP number 1LDA number 2LDB number 3MUL 4STR square 5PNT square 6STP

Assembly language. Step 5: Replace memory names by cell numbers after STP 0INP number 7 1LDA number 7 2LDB number 7 3MUL 4STR square 8 5PNT square8 6STP

Assembly language. Step 6: Final Assembly code INP 07 LDA 07 LDB 07 MUL STR 08 PNT 08 STP

Pascal to Assembly language. StatementAssembly equivalent if ( N < 10 ) thenLDA N (condition expression) writeln (N)LDB Ten CMP JOP (operation) (Then Block) JMP to statement after then block PNT N ( then block)

Pascal to Assembly language. StatementAssembly equivalent if ( N < 10 ) thenLDA N (condition expression) writeln (N)LDB Ten else writeln (‘0’); CMP JOP (operation) (Then Block) PNT Zero ( else Block) JMP to statement after then block PNT N ( then block)

Assembly language. Program #2. Write an assembly program that will get a number from the user, and determine if the number is evenly divisible by 5. Output zero (false) if the number is NOT evenly divisible by 5 or one (true) if the number IS evenly divisible.

Assembly language. step 1: algorithm to describe the steps needed to solve our problem.

Assembly language. step 1: algorithm to describe the steps needed to solve our problem. 1. Input a number and store it in memory. 2. Determine if the input number is evenly divisible by Divide the input number by 5 to get the remainder. 2.2 Compare the remainder to 0. If remainder equals 0, the number is evenly divisible. If the remainder does not equal 0, the number NOT evenly divisible. 3. Output the results 3.1 If evenly divisible, output If NOT evenly divisible, output 0.

Assembly language. Step 2: write Pascal code

Assembly language. Step 2: write Pascal code Const Zero = 0; One =1; Five = 5; Var number, rem: integer; begin readln ( number); rem := number MOD Five ; if (rem = Zero) then writeln (One); else writeln (Zero) end.

Assembly language. Step 3: translate Pascal code to assembly Const Zero = 0; One =1; Five = 5; Var number, rem: integer; begin readln ( number);INP number rem := number MOD Five ;LDA number LDB Five MOD STR rem

Assembly language. Step 3: translate Pascal code to assembly if (rem = Zero) thencondition expLDA Zero writeln (One);LDB rem else writeln (Zero)CMP end.JEQ then block else blockPNT Zero JMP after then then blockPNT One STP

Assembly language. Step 4: Number assembly code lines starting from 0 0 INP number 1 LDA number 2 LDB Five 3 MOD 4 STR rem condition exp5 LDA Zero 6 LDB rem 7 CMP 8 JEQ then block else block9 PNT Zero 10 JMP after then then block11 PNT One 12 STP

Assembly language. Step 5: Replace memory names by cell numbers after STP 0 INP number 16 1 LDA number 16 2 LDB Five 13 3 MOD 4 STR rem 17 condition exp5 LDA Zero 14 6 LDB rem 17 7 CMP 8 JEQ then block else block9 PNT Zero JMP after then then block11 PNT One STP

Assembly language. Step 5: Replace jumps by instruction numbers 0 INP 16 1 LDA 16 2 LDB 13 3 MOD 4 STR 17 5 LDA 14 6 LDB 17 7 CMP 8 JEQ then block 11 else block9 PNT JMP after then 12 then block11 PNT STP

Assembly language. Step 6: Final Assembly code INP 16 LDA 16 LDB 13 MOD STR 17 LDA 14 LDB 17 CMP JEQ 11 PNT 14 JMP 12 PNT 15 STP 5 0 1

Assembly language. StatementAssembly equivalent While (N < 10 ) doLDA N (condition expression) beginLDB Ten writeln (N)CMP end; JOP (operation) (While Block) JMP to statement after while block PNT N ( while block statements) JMP Condition

Assembly language. Program #3. Write an assembly program that will add up a series of positive numbers entered by the user, until the user enters a negative number, then display the total.

Assembly language. step 1: algorithm to describe the steps needed to solve our problem.

Assembly language. step 1: algorithm to describe the steps needed to solve our problem. 1.Input a value and store it in memory. 2.While the Input Value is not a negative number: –2.1 Add the Input Value to the Running Total and store – the sum back into the Running Total. –2.2 Input another value and store it in memory. 3.Output the contents of the Running Total.

Assembly language. Step 2: write Pascal code

Assembly language. Step 2: write Pascal code Const Zero = 0; Var sum, number: integer; begin sum := zero; readln ( number); While ( number >= Zero) do begin sum := sum + number; readln (number); end; writeln (sum) end.

Assembly language. Step 3: translate Pascal code to assembly begin sum := zero; readln ( number); While ( number >= Zero) do LDB Zero STR sum INP number condition LDA number LDB Zero CMP JGT (While Block) JEQ (While Block) JMP after while block

Assembly language. Step 3: translate Pascal code to assembly begin sum := sum + number; readln (number); end; writeln (sum) end. LDA sum LDB number ADD STR sum INP number JMP Condition PNT sum STP

Assembly language. Step 4: Number assembly code lines starting from 0 0 LDB Zero 1 STR sum 2 INP number condition 3 LDA number 4 LDB Zero 5 CMP 6 JGT (While Block) 7 JEQ (While Block) 8 JMP after while block 9 LDA sum 10 LDB number 11 ADD 12 STR sum 13 INP number 14 JMP Condition 15 PNT sum 16 STP

Assembly language. Step 5: Replace memory names by cell numbers after STP 0 LDB Zero 17 1 STR sum 18 2 INP number 19 condition 3 LDA number 19 4 LDB Zero 17 5 CMP 6 JGT (While Block) 7 JEQ (While Block) 8 JMP after while block while body 9 LDA sum LDB number ADD 12 STR sum INP number 19 end while 14 JMP Condition 15 PNT sum STP 17 0

Assembly language. Step 5: Replace jumps by cell numbers 0 LDB 17 1 STR 18 2 INP 19 condition 3 LDA 19 4 LDB 17 5 CMP 6 JGT (While Block) 9 7 JEQ (While Block) 9 8 JMP after while block 15 while body 9 LDA LDB ADD 12 STR INP 19 end while 14 JMP Condition 3 15 PNT STP 17 0

Assembly language. Step 6: Final Assembly code LDB 17 STR 18 INP 19 LDA 19 LDB 17 CMP JGT 9 JEQ 9 JMP 15 LDA 18 LDB 19 ADD STR 18 INP 19 JMP 3 PNT 18 STP 0