Programming and Problem Solving

Slides:



Advertisements
Similar presentations
Code Composer Department of Electrical and Computer Engineering
Advertisements

Week 3. Assembly Language Programming  Difficult when starting assembly programming  Have to work at low level  Use processor instructions >Requires.
The 8051 Microcontroller and Embedded Systems
Princess Sumaya Univ. Computer Engineering Dept. Chapter 2: IT Students.
IT253: Computer Organization Lecture 6: Assembly Language and MIPS: Programming Tonga Institute of Higher Education.
Utilizing the GDB debugger to analyze programs Background and application.
Assembly 01. Outline Binary vs. Text Files Compiler vs. Assembler Mnemonic Assembly Process Development Process Debugging Example 1 this analogy will.
The assembler is the system program that translate source code written in assembly language to object code( Machine Language) and other information for.
Chapter 2- Visual Basic Schneider1 Chapter 2 Problem Solving.
Introduction to MPLAB IDE. What is IDE? Integrated Development Environment (IDE) Collection of integrated programs (tools) to write assembly programs,
Microprocessor and Microcontroller Based Systems Instructor: Eng.Moayed N. EL Mobaied The Islamic University of Gaza Faculty of Engineering Electrical.
Lab6 – Debug Assembly Language Lab
Chih-Hung Wang Chapter 2: Assembler (Part-1) 參考書目 Leland L. Beck, System Software: An Introduction to Systems Programming (3rd), Addison-Wesley, 1997.
Chapter 3 Assembly Language: Part 1. Machine language program (in hex notation) from Chapter 2.
TK 2633 Microprocessor & Interfacing Lecture 3: Introduction to 8085 Assembly Language Programming (2) 1 Prepared By: Associate Prof. Dr Masri Ayob.
Low-Level Programming Languages
Chapter 2: Input, Processing, and Output
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.
Chapter 4 H1 Assembly Language: Part 2. Direct instruction Contains the absolute address of the memory location it accesses. ld instruction:
Chapter 7 Low-Level Programming Languages Nell Dale John Lewis.
1-1 Embedded Software Development Tools and Processes Hardware & Software Hardware – Host development system Software – Compilers, simulators etc. Target.
8051 ASSEMBLY LANGUAGE PROGRAMMING
ECE 265 – LECTURE 9 PROGRAM DESIGN 8/12/ ECE265.
Assembly & Machine Languages
Chapter 2 Software Tools and Assembly Language Syntax.
Writing an Assembly-language program Atmel assembly language CS-280 Dr. Mark L. Hornick 1.
Chapter Seven Advanced Shell Programming. 2 Lesson A Developing a Fully Featured Program.
Lab 1 – Assembly Language and Interfacing Start date: Week 3 Due date: Week 4 1.
CPS120: Introduction to Computer Science
P.1ECE 331, Prof. A. Mason Professor Andrew Mason Michigan State University Spring 2013 ECE 331: PC Lab 1: Using HC12 ASM Simulators.
Dr Masri Ayob TK 2633: Microprocessor & Interfacing Lecture 7: Assembly Language.
CSC141 Introduction to Computer Programming
1/2002JNM1 Basic Elements of Assembly Language Integer Constants –If no radix is given, the integer is assumed to be decimal. Int 21h  Int 21 –A hexadecimal.
Chapter 3 Elements of Assembly Language. 3.1 Assembly Language Statements.
Programming and Problem Solving ELEC 330 Digital Systems Engineering Dr. Ron Hayne Images Courtesy of Ramesh Gaonkar and Delmar Learning.
Debug and Assembler By, B.R.Chandavarkar Lect. COMP Department NITK, Surathkal.
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.
Assemblers.
Ass. Prof. Dr Masri Ayob TK 6123 Lecture 13: Assembly Language Level (Level 4)
Computer Architecture and Operating Systems CS 3230 :Assembly Section Lecture 3 Department of Computer Science and Software Engineering University of Wisconsin-Platteville.
Computer Operations A computer is a programmable electronic device that can store, retrieve, and process data Data and instructions to manipulate the data.
PIC – ch. 2c. 2.5 PIC Data formats Numbers can be – Hex – Binary – Decimal – ASCII formats.
Introduction to MPLAB IDE
Assembly Language ELEC 330 Digital Systems Engineering Dr. Ron Hayne.
Chapter 7 Low-Level Programming Languages (slides modified by Erin Chambers)
Chapter 7 Low-Level Programming Languages Nell Dale John Lewis.
S YSTEMS P ROGRAMMING CHAPTER 2 PROGRAMMING IN ASSEMBLY LANGUAGE Er. Bharadwaj Choudhury.
Represents different voltage levels High: 5 Volts Low: 0 Volts At this raw level a digital computer is instructed to carry out instructions.
Chapter 7 Low-Level Programming Languages Nell Dale John Lewis.
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?
2/22/20161 Assembly Language (continue). 2/22/20162 Assembly Language Format LabelOpcodeOperandComment Start:LXISP,3FF0H;Initialize stack pointer DelimiterPlacement.
1 EKT 225 MICROCONTROLLER I CHAPTER ASSEMBLY LANGUAGE PROGRAMMING.
Digital Computer Concept and Practice Copyright ©2012 by Jaejin Lee Control Unit.
First Foray into Programming (the hard way). A reminder from last lesson: A machine code instruction has two parts:  Op-code  Operand An instruction.
Some of the utilities associated with the development of programs. These program development tools allow users to write and construct programs that the.
CS501 Advanced Computer Architecture Lecture 29 Dr.Noor Muhammad Sheikh.
Writing an Assembly-language program MIPS assembly language using MARS: MIPS Assembler and Runtime Simulator CS-2710 Dr. Mark L. Hornick 1.
Compsci 210 Tutorial Five.
Assembly Language (continue)
Assembly Language Programming of 8085
ACOE301: Computer Architecture II Labs
The 8051 Microcontroller and Embedded Systems
Assembler CASE Tool.
Sequencing, Selection, and Loops in Machine Language
MARIE: An Introduction to a Simple Computer
Microprocessor and Assembly Language
8051 ASSEMBLY LANGUAGE PROGRAMMING
Chapter 6 Programming the basic computer
Presentation transcript:

Programming and Problem Solving Chapter 4 Programming and Problem Solving

Flowcharting Flowchart A graphical representation of processes (tasks) to be performed and the sequence to be followed in solving computational problem

Example 4.1 (1 of 2) Write instructions to load two bytes (37H and 92H) in data registers REG0 and REG1. Add the bytes and store the sum in REG2. Steps Load the two bytes in data registers REG0 and REG1. Add the bytes. Save the sum in data register REG2.

Example 4.1 (2 of 2) Start ORG 0x20 Process REG0 EQU 0x00 MOVLW 0x37 MOVWF REG0,0 MOVLW 0x92 MOVWF REG1,0 ADDWF REG0,0 MOVWF REG2, 0 SLEEP Process Change the program: if the sum is larger than 50H then the result should be in REG3 AND REG2=0; OTHERWISE, the result should be in REG2 AND REG3=0;

What is wrong with this? ORG 0x20 REG0 EQU 0x00 REG1 EQU 0x01 COMPREG EQU 0x10 CONST EQU 0x50 MOVLW CONST MOVWF COMPREG,0 MOVLW 0x37 MOVWF REG0,0 MOVLW 0x92 MOVWF REG1,0 ADDWF REG0,0 ;the result is in W CPFSLT COMPREG,0 BRA WR_REG3 BRA WR_REG2 WR_REG3: MOVWF REG3, 0 BRA DONE_PROG WR_REG2: MOVWF REG2, 0 DONE_PROG: SLEEP

Steps in Writing and Executing Assembly Language Program Analyze the problem. Draw a flowchart. Convert the flowchart in mnemonics. Look up Hex code and assign memory addresses. Enter the Hex code into memory of a lab training board. Execute the program. Debug the program if necessary.

Illustrative Program: Addition With Carry Check Write instructions to load two bytes, Byte1 (F2H) and Byte2 (32H), in data registers REG0 and REG1 respectively and add the bytes. If the sum generates a carry, clear the data register REG2; otherwise, save the sum in REG2.

Illustrative Program: Addition With Carry Check (1 of 2) Write instructions to load two bytes, Byte1 (F2H) and Byte2 (32H), in data registers REG0 and REG1 respectively and add the bytes. If the sum generates a carry, clear the data register REG2; otherwise, save the sum in REG2. 8

Integrated Development Environment (IDE) Steps in using IDE Editing – generating the source code Assembling – Converting mnemonics into hex and binary; generates the object file Linking – uses the object file and generates the binary code Downloading – transfers the binary code (instructions) to the memory of the target device Executing – perform the tasks specified by instruction codes Simulation – Execute the program on PC (also called the simulator) Debugging – Going through the program step-by-step to find logical problems in the instruction set

Writing a Program Using an Assembler The assembly language program includes: Program in mnemonics Assembler directives Comments

Assembly Language Format (1 of 2) Typical statement of an assembly language source code has four fields: Label Opcode (operation code) Operand (data, register, or memory address to be operated on) Comment

Assembly Language Format (2 of 2) Format example Label Opcode Operand Comment START: MOVLW 0xF2 ;Load F2H in W ↑ ↑ ↑ ↑ Space Space Space Semicolon Or Colon

Assembler Directives ORG Origin END End of assembly EQU Equate SET Defines an assembler variable #INCLUDE Include resources from available library RADIX Number format DB Define byte DW Define word CBLOCK Define a block of constants ENDC End of block of constants RES Reserve memory

View Registers and Source Program in MPLAB Simulator Data bytes Define labels and const Starting memory address Label

Format of Radixes Hexadecimal Decimal Binary ASCII 0x0F H`4F` 4F 4FH `This stuff are interesting!`

Using MPLAB IDE to Write, Assemble, and Build Project (1 of 6) Write source code using MPLAB editor. Create a new project. Select language tool suite. Name your project. Add files to assemble. Build the project.

Using MPLAB IDE (2 of 6) To create a new project Step 1: Open MPLAB IDE Select Project  Project Wizard  Select Device PIC18F452 Next

Using MPLAB IDE (3 of 6) Step 2: Select a Language Toolsuite: Microchip MPASM Toolsuite Next

Using MPLAB IDE (4 of 6) Step 3. Name Your Project: Illust4-4 Addition with Carry Check Browse  MyProj\Ch04  Next

Using MPLAB IDE (5 of 6) Step 4: Add  Add Source Files  Next

Using MPLAB IDE (6 of 6) Summary  Finish

Project Window

List of Files Generated by MPLAB Assembler

Understanding the List File List file generated primarily for documentation Includes seven columns Memory addresses where binary code is stored Hex code Line numbers Contents of source file Labels Opcode Operands Comments

Executing a Program Using Simulator Steps in setting up MPLAB simulator Select Debugger  Select tool MPLABSIM Select Debugger  Settings  Change frequency if necessary Select View  Watch  Add registers to observe

View Registers and Source Program in MPLAB Simulator

View Registers, Source Program, and Program Memory in MPLAB Simulator

Debugging a Program Single-step technique Breakpoint technique Enables user to execute one instruction at a time and observe registers for expected results Breakpoint technique Enables user to execute a group of instructions at a time and observe registers for expected results Tracing code MPLAB can track execution of each instruction and display data which can be examined for errors

Single-Step Technique

Breakpoint Technique

Tracing Code

Assembler Directive Pseudo-code instructions Define constants, labels, where to assemble a program, reserves memory for data Directives do not translate to machine language  do not require memory assignment (come for free!) Example BYTE EQU 0x02 Label BYTE is being equated to value 2Hex Example ORG 20H Assemble the program starting at location 20H

Number Representation