Algorithm vs. Assembler - basics. Algorithm vs. Assembler 2/15 Developing software in assembler The best way of developing program in machine language.

Slides:



Advertisements
Similar presentations
The 8051 Microcontroller and Embedded Systems
Advertisements

Deeper Assembly: Addressing, Conditions, Branching, and Loops
Fall EE 333 Lillevik 333f06-l4 University of Portland School of Engineering Computer Organization Lecture 4 Assembly language programming ALU and.
1 Chapter 3 Jump, Loop, and Call Instructions. 2 Sections 3.1 Loop and Jump Instructions 3.2 Call Instructions 3.3 Time Delay Generation and Calculation.
The Assembly Language Level
Microprocessors. Microprocessor Buses Address Bus Address Bus One way street over which microprocessor sends an address code to memory or other external.
Chapter 2- Visual Basic Schneider1 Chapter 2 Problem Solving.
The Little man computer
Day 20 Memory Management. Assumptions A process need not be stored as one contiguous block. The entire process must reside in main memory.
1 ICS 51 Introductory Computer Organization Fall 2006 updated: Oct. 2, 2006.
8051 ASSEMBLY LANGUAGE PROGRAMMING
1 Sec (2.3) Program Execution. 2 In the CPU we have CU and ALU, in CU there are two special purpose registers: 1. Instruction Register 2. Program Counter.
Introduction to Programming (in C++) Introduction Jordi Cortadella, Ricard Gavaldà, Fernando Orejas Dept. of Computer Science, UPC.
1 I.Introduction to Algorithm and Programming Algoritma dan Pemrograman – Teknik Informatika UK Petra 2009.
CIS Computer Programming Logic
A Simple Tour of the MSP430. Light LEDs in C LEDs can be connected in two standard ways. Active high circuit, the LED illuminates if the pin is driven.
INTRODUCTION TO COMPUTING CHAPTER NO. 06. Compilers and Language Translation Introduction The Compilation Process Phase 1 – Lexical Analysis Phase 2 –
Algorithmic Problem Solving CMSC 201 Adapted from slides by Marie desJardins (Spring 2015 Prof Chang version)
MIPS coding. SPIM Some links can be found such as:
Low Level Programming Lecturer: Duncan Smeed Low Level Program Control Structures.
8.4 paging Paging is a memory-management scheme that permits the physical address space of a process to be non-contiguous. The basic method for implementation.
Computer Science 101 How the Assembler Works. Assembly Language Programming.
S2008Final_part1.ppt CS11 Introduction to Programming Final Exam Part 1 S A computer is a mechanical or electrical device which stores, retrieves,
1 Problem Solving with C++ The Object of Programming Walter Savitch Chapter 1 Introduction to Computers and C++ Programming Slides by David B. Teague,
Dr. José M. Reyes Álamo 1.  Review: ◦ Statement Labels ◦ Unconditional Jumps ◦ Conditional Jumps.
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.
Problem Solving using the Science of Computing MSE 2400 EaLiCaRA Spring 2015 Dr. Tom Way.
Chapter 1 Introduction Chapter 1 Introduction 1 st Semester 2015 CSC 1101 Computer Programming-1.
Assembler MCS51 - machine language. Structure of programme In general a single assembler programme line has following structure: for example: go_here:adda,r0.
Execution of an instruction
Today’s topics Procedures Procedures Passing values to/from procedures Passing values to/from procedures Saving registers Saving registers Documenting.
CHAPTER 1 INTRODUCTION 1 st Semester H King Saud University College Of Applied Studies and Community Services CSC 1101 Computer Programming-1.
CHAPTER 1 INTRODUCTION 1 st semester H King Saud University College Of Applied Studies and Community Services CSC 1101 Computer Programming-1.
The 8051 Microcontroller and Embedded Systems
Tuesday, 8 st of Aban 2 nd TA Session.  In last session, we did:  Met with Memory and CPU  Met with C++ and compared it, somehow, w/ C and Java  Met.
Chapter 1 Introduction Study Goals: Master: the phases of a compiler Understand: what is a compiler Know: interpreter,compiler structure.
Lecture Set 4 Programming the 8051.
© GCSE Computing Candidates should be able to:  describe the characteristics of an assembler Slide 1.
Assembly Language. Symbol Table Variables.DATA var DW 0 sum DD 0 array TIMES 10 DW 0 message DB ’ Welcome ’,0 char1 DB ? Symbol Table Name Offset var.
Computer Organization 1 Instruction Fetch and Execute.
Programming in C++ Dale/Weems/Headington Chapter 1 Overview of Programming and Problem Solving.
תרגול 5 תכנות באסמבלי, המשך
Assembly Language Programming of 8085 BY Prof. U. V. THETE Dept. of Computer Science YMA.
Elements of Computing Systems, Nisan & Schocken, MIT Press, Chapter 6: Assembler slide 1www.nand2tetris.org Building a Modern Computer.
8086/8088 Instruction Set, Machine Codes and Addressing Modes.
The Assembly Process Computer Organization and Assembly Language: Module 10.
JUMP, LOOP, AND CALL INSTRUCTIONS
CMSC 104, Lecture 061 Stored Programs A look at how programs are executed.
1 EKT 225 MICROCONTROLLER I CHAPTER ASSEMBLY LANGUAGE PROGRAMMING.
Computer Organization Instructions Language of The Computer (MIPS) 2.
ALGORITHMS AND FLOWCHARTS. Why Algorithm is needed? 2 Computer Program ? Set of instructions to perform some specific task Is Program itself a Software.
Microprocessor & Assembly Language
Introduction to Computer Programming using Fortran 77.
LECTURE 3 Translation. PROCESS MEMORY There are four general areas of memory in a process. The text area contains the instructions for the application.
Software Engineering Algorithms, Compilers, & Lifecycle.
Computing Science Computer Structure: Lesson 1: Processor Structure
The Little man computer
Introduction to Computers and C++ Programming
Instruction sets : Addressing modes and Formats
Assembler Directives Code generation flow
Assembly Language Programming of 8085
Microprocessor T. Y. B. Sc..
COMBINED PAGING AND SEGMENTATION
ALGORITHMS AND FLOWCHARTS
1. Introduction A microprocessor executes instructions given by the user Instructions should be in a language known to the microprocessor Microprocessor.
Assembler Directives Code generation flow
Lecture 6 Assembler Directives.
Practice Six Chapter Eight.
Chapter 5: Control Structure
CS334: MIPS language _Mars simulator Lab 2_1
Presentation transcript:

Algorithm vs. Assembler - basics

Algorithm vs. Assembler 2/15 Developing software in assembler The best way of developing program in machine language is working according to the following scheme: 1.Analyzing the task 2.Defining needed data structures 3.Developing algorithm by: developing own, original ideas; applying already known solution. 3.Describing algorithm in chosen form (text form, decision tree, high-level language syntax, block diagrams) 4.Implementing in target device language.

Algorithm vs. Assembler 3/15 … av:=(var1+var2)/2 … A  M[var1] A:=A+ M[var2] CyA:=CyA>>1 M[av]  A … R0:= var1 A  M[R0] R1:= var2 A:=A+ M[R1] CyA:=CyA>>1 R1:=av M[R1]  A …

; variables located inside internal indirectly addressed ; data memory (IM) isegat0x90 var1:ds1;’var1’ in IM[90h] var2:ds1;’var2’ in IM[91h] av:idatavar2+1;’av’ in IM[92h]... MOVR0,#var1;R0->var1 var1 to A MOVR1,#var2;R1->var2 RRCA;shift right by 1 bit (dividing by 2) MOVR1,#av;R1->av result to av Algorithm vs. Assembler 4/15

; variables located inside internal directly addressed ; data memory (DM) dsegat0x30 var1:ds1;’var1’ in DM[30h] var2:ds1;’var2’ in DM[31h] av:datavar2+1;’av’ in DM[32h]... MOVA,var1;copying var1 to A ADDA,var2;adding RRCA;shift right by 1 bit (dividing by 2) MOVav,A;storing result to av Algorithm vs. Assembler 5/15

; variables located inside external data memory (XM) xsegat0x8090 var1:ds1;’var1’ in XM[8090h] var2:ds1;’var2’ in XM[8091h] av:xdatavar2+1;’av’ in XM[8092h]... MOVDPTR,#var1;DPTR->var1 var1 to A MOVB,A;and to register B MOVDPTR,#var2;DPTR->var2 var2 to A ADDA,B;adding RRCA;shift right by 1 bit (dividing by 2) MOVDPTR,#av;DPTR->av result to av Algorithm vs. Assembler 6/15

Algorithm vs. Assembler 7/15 var1 < var2 ? F T A < var2 ? FT A  M[var1] MOVA,var1;copying variable var1 to A CJNEA,var2,neq;comparing with var2 neq:JClessthan;jump if A<var2 MOVA,var1;copying variable var1 to A CLRC;clearing CY SUBBA,var2 JClessthan; jump if A<var2

Algorithm vs. Assembler 8/15 MOVA,var1;copying variable var1 to A CJNEA,var2,neq;comparing to var2 ;no jump if var1=var2... SJMPcont neq:JClessthan;jump if A<var2 ;here if var1>var2... SJMPcont lessthan:... cont: var1-var2 >0<0 =0

Determining whether two multi-byte variables are identical can be achieved in the following way: ; assumption: var1, var2 – start addresses of 2 variables ; located in internal data memory MOVA,var1;A<-1st byte of var1 XRLA,var2;A:=A xor var2 JNZdiff;jump if byte differ MOVA,var1+1;A<-2nd byte of var1 XRLA,var2+1;A:=A xor var2 JNZdiff;jump if byte differ... MOVA,var1+k-1;A<-last byte of var1 XRLA,var2+k-1;A:=A xor var2 JNZdiff;jump if byte differ equal: ;here if var1=var2 Algorithm vs. Assembler 9/15

The zero value of multi-byte variable can be detecting in one another way. Suggested solution is to calculate logical sum of all bytes of the variable and check whether it is equal zero: LDA,var4;A<-1st byte of var4 ORLA,var4+1;logical sum with following bytes ORLA,var4+2 ORLA,var4+3 JRNZ,nozero;jump if var4 is not equal zero ; here if var4=0 Algorithm vs. Assembler 10/15

„Direct” translation to assembler: MOVR3,#0;lc in R3 cleared rep:;loop label ;... other repeated operations INCR3;incrementing lc counter CJNER3,#rn,rep;comparing lc with rn Algorithm vs. Assembler 11/15 … lc:=lc+1 lc < rn ? T F … lc:= 0 lc – loop counter rn – number of repetitions

or: MOVR1,#lp;R1->lc in internal data memory lc rep:;loop label ;... other repeated operations lc counter lc with rn or: MOVlp,#0;clearing lc rep:;loop label ;... other repeated operations INClp;incrementing lc counter MOVA,#rn;A:=rn CJNEA,lp,rep;comparing A=rn with lc Algorithm vs. Assembler 12/15

Better solution is the usage of DJNZ instruction: MOVR6,#rn;initialisation lc in R6 to rn rep:;loop label ;... other repeated operations DJNZR6,rep;lc:=lc-1 & jump if lc>0 or: MOVlc,#rn ;initialisation lc in RAM to rn rep:;loop label ;... other repeated operations DJNZlc,rep;lc:=lc-1 & jump if lc>0 If the value of rn is greater than 256: MOVR7,#(rn-1)/256;external loop counter in R7 MOVR6,#rn MOD 256;internal loop counter in R6 rep:;loop label ;... other repeated operations DJNZR6,rep DJNZR7,rep Algorithm vs. Assembler 13/15

Algorithm vs. Assembler 14/15 … A  tab[i,j] … j := j + 1 j < col_nmbr ? T F j := 0 i := i + 1 i < row_nmbr ? T F i := 0 Nested loops:

Algorithm vs. Assembler 15/15 Exemplary implementation: col_nmbrequ20 row_nmbrequ33 XSEG ORG0x2000 table:dscol_nmbr*row_nmbr ;allocation of 660 bytes for ;‘table’ inside XDATA ;starting from 2000h in external data memory CSEG;back to CODE segment ;... MOVDPTR,#table MOVR7,#row_nmbr;row counter initialization nxt_row: MOVR6,#col_nmbr;column counter initialization nxt_el: ;... ; access to element of the table, for example: ;... INCDPTR;next element of the table DJNZR6,nxt_el DJNZR7,nxt_row