ECE 3561 - Lecture 1 1 L11-HLL to Assembler Department of Electrical and Computer Engineering The Ohio State University ECE 2560.

Slides:



Advertisements
Similar presentations
CS 101 Introductory Programming - Lecture 7: Loops In C & Good Coding Practices Presenter: Ankur Chattopadhyay.
Advertisements

Flow of Control Instruction/Control structure Looping structure Looping structure Branching structure Branching structure For assembly language program.
Code Composer Department of Electrical and Computer Engineering
ECE 447 Fall 2009 Lecture 2: TI MSP430 Software Development C and MSP430 Assembly.
ECE 382 Lesson 6 Lesson Outline Example Assembly Code In class programming Debugging Assembly Code Lesson 6, 7, and 8 notes Admin CompEx1CompEx1  due.
CSC 221 Computer Organization and Assembly Language Lecture 21: Conditional and Block Structures: Assembly Programs.
The Little man computer
The CPU Revision Typical machine code instructions Using op-codes and operands Symbolic addressing. Conditional and unconditional branches.
LAB Flow Control Instructions
Assembly Language for Intel-Based Computers
CS2422 Assembly Language & System Programming October 17, 2006.
Assembly Language Programming. CPU The CPU contains a Control Unit, Arithmetic Logic Unit (ALU) and a small number of memory locations called Registers.
ECE Lecture 1 1 L9: Subroutines Department of Electrical and Computer Engineering The Ohio State University ECE 2560.
Data Transfer & Decisions I (1) Fall 2005 Lecture 3: MIPS Assembly language Decisions I.
1 Homework Reading –PAL, pp Machine Projects –MP2 due at start of Class 12 Labs –Continue labs with your assigned section.
ALGORITHMS AND FLOW CHARTS 1 Adapted from the slides Prepared by Department of Preparatory year Prepared by: lec. Ghader Kurdi.
Computer Science 210 Computer Organization The Instruction Execution Cycle.
Algorithmic Problem Solving CMSC 201 Adapted from slides by Marie desJardins (Spring 2015 Prof Chang version)
Low Level Programming Lecturer: Duncan Smeed Low Level Program Control Structures.
L12-Computing Factorial
Chapter 4 - Implementing Standard Program Structures in 8086 Assembly Language from Microprocessors and Interfacing by Douglas Hall.
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.
The 8051 Assembly Language Branching & Subroutines
Lecture 8. MIPS Instructions #3 – Branch Instructions #1 Prof. Taeweon Suh Computer Science Education Korea University 2010 R&E Computer System Education.
PROBLEM SOLVING WITH LOOPS Chapter 7. Concept of Repetition Structure Logic It is a computer task, that is used for Repeating a series of instructions.
Introduction to Computer Engineering ECE/CS 252, Fall 2010 Prof. Mikko Lipasti Department of Electrical and Computer Engineering University of Wisconsin.
The LC-3. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 5-2 Instruction Set Architecture ISA = All of the.
Execution of an instruction
ECE Lecture 1 1 L7 – A First Program Department of Electrical and Computer Engineering The Ohio State University ECE 2560.
(Flow Control Instructions)
Natawut NupairojAssembly Language1 Control Structure.
ECE Lecture 1 1 L8:Flowcharting a program Department of Electrical and Computer Engineering The Ohio State University ECE 2560.
Computer Architecture and Operating Systems CS 3230 :Assembly Section Lecture 5 Department of Computer Science and Software Engineering University of Wisconsin-Platteville.
Pascal Programming Iteration (looping) Carl Smith National Certificate Unit 4.
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.
Chapter 5 Branching and Looping.
Assembly Language Programming of 8085 BY Prof. U. V. THETE Dept. of Computer Science YMA.
Problem-solving with Computers. 2Outline  Computer System  5 Steps for producing a computer program  Structured program and programming  3 types of.
Comments, Conditional Statements Continued, and Loops Engineering 1D04, Teaching Session 4.
ALGORITHMS AND FLOWCHARTS. Why Algorithm is needed? 2 Computer Program ? Set of instructions to perform some specific task Is Program itself a Software.
Jumps, Loops and Branching. Unconditional Jumps Transfer the control flow of the program to a specified instruction, other than the next instruction in.
Flow Control in Imperative Languages. Activity 1 What does the word: ‘Imperative’ mean? 5mins …having CONTROL and ORDER!
Digital Computer Concept and Practice Copyright ©2012 by Jaejin Lee Control Unit.
Computer Science 210 Computer Organization Machine Language Instructions: Control.
The Little man computer
Unit 1 Instruction set M.Brindha AP/EIE
CS2100 Computer Organisation
Assembly Language Programming of 8085
Homework Reading Labs PAL, pp
3.Instruction Set of 8085 Consists of 74 operation codes, e.g. MOV
CS1371 Introduction to Computing for Engineers
3.1 Algorithms (and real programming examples).
Microprocessor and Assembly Language
CS-401 Assembly Language Programming
Computer Science 210 Computer Organization
Chapter 5 The LC-3.
LC-3 Details and Examples
Computer Organization and Assembly Language
Software Programming J. Holvikivi 2014.
Computer Science 210 Computer Organization
Computer Science 210 Computer Organization
L13b – 32 bit multiply Department of Electrical and
Program Logic and Control
Program Logic and Control
Homework Reading Machine Projects Labs PAL, pp
Introduction to Micro Controllers & Embedded System Design
Computer Science Core Concepts
Some Assembly (Part 2) set.html.
Chapter 7 –Program Logic and Control
Chapter 7 –Program Logic and Control
Presentation transcript:

ECE Lecture 1 1 L11-HLL to Assembler Department of Electrical and Computer Engineering The Ohio State University ECE 2560

HLL to Assembler Pseudo HLL HLL structure Their flow chart HHL code Corresponding Assembler ECE Lecture 1 2

What is Pseudo HLL Pseudo HLL is a way of expressing an algorithm or procedure for performing a task. Very similar to modern High Level programming Languages Best illustrated with an example ECE Lecture 1 3

Pseudo HLL example Sum a list of 10 integers There are several methods The algorithm here Create sum and initialize to 0 Add first number Repeat adding number until done with list ECE Lecture 1 4

Pseudo HLL Sequence of Actions Do action A Do action B …. Do action Q ECE Lecture 1 5

Decisions Decision structures IF condition THEN action if true ELSE action if false END IF; Example: Remove front bike wheel TURN Bike over IF wheel-has-quick-release-skewer THEN flip level and remove wheel ELSE use wrench to remove nuts from axle remove wheel END IF ECE Lecture 1 6

Examples and demo Example and demo of decision structures IF THEN ELSE Set up Test condition Branch to after the code The action code ECE Lecture 1 7

Example Is a > b ? a and b are memory location labels.data a.word 0x00FF b.word 0x00FF The code if a>b THEN actions cmp a,b ;computes b-a but what jump? after ECE Lecture 1 8

The jumps Jump Instructions JC,Jump if carry set JHS,Jump if high or same The C bit is tested If set (i.e. 1) then the branch is taken If clear, the next instruction is executed JEQ, JZ Jump if equal, Jump if zero The Z bit is tested If set (i.e. 1) then the branch is taken If clear, the next instruction is executed ECE Lecture 1 9

The Jumps (2) JGEJump if greater or equal The N and V bits are used – If N and V are set or reset (both 0 or both 1) the branch is taken JLJump if less The N and V bits are used If only one of N or V is set then the branch is taken JMP Jump unconditionally ECE Lecture 1 10

Jumps (3) JNJump is negative The N bit is tested If N is set (i.e. 1) the branch is taken JNC Jump if carry not set JLOJump is lower The carry bit C is tested. If C is 0 the branch is taken JNE Jump not equal JNZ Jump if not zero The Z bit is tested If Z = 0 the branch is taken ECE Lecture 1 11

A test program Write and compile a test program that sets up two values, uses cmp to compare them, and then runs through the branches. Have values that are both positive, both negative, and one positive-one negative. ECE Lecture 1 12

Adding the ELSE condition If you have an else condition, set up the branch such that when the condition is not met, you have a label to branch to this code section. cmpa,b jgeelsecond ;THEN condition actions jmp ifendpt elsecond ;ELSE condition actions Ifendpt;following code ECE Lecture 1 13

Repeat structures - Do Loops Finite number of times – DO LOOP Set up any values for loop FOR counter = start TO end [STEP x] LOOP actions of loop END FOR; Example: Sum = 0; FOR i = 1 to 10 LOOP Sum = Sum + element(i); END FOR; ECE Lecture 1 14

A fix number of times For I in 1 to 10 loop action in loop End loop; Assembler Use a register for the current value of the loop counter In data area have stval – the starting value, endval – the ending value.data stval.word 0x0001 endval.word 0x000F ;loop 15 times ECE Lecture 1 15

The structure ;start of loop – setup mov &stval,R8 ;i to R8 tol cmp R8,&endval jeqdone ;actions of loop incR8 jmptol done;code after loop ECE Lecture 1 16

Demo Want to do loop 4 times Setup – stval of 1, endval of 4 But only execute the loop 3 times Could you solve this with the type of branch? Difficult Easy – endval is number of times through the loop + 1 OR i is one less than the iteration through the loop at compare, i.e. initial value is 0 – move inc instruction to just after the jump ECE Lecture 1 17

New material - TA New material starts here ECE Lecture 1 18

Repeat structures Indeterminate number of times – Repeat loop or decision loop – action inside the loop causes condition to occur that ends the loop. 2 structures One has code that executes at least once One has code that may or may not execute at all ECE Lecture 1 19

While condition While loop – may or may not execute code WHILE condition LOOP SEQUENCE_of_ACTIONS END loop; Example: WHILE not EOF LOOP Read line from file Process line END LOOP; ECE Lecture 1 20

Repeat Repeat Until structure REPEAT Sequence_of_statements UNITL condition; Example - attempt to read will be done at least once REPEAT Read line from file UNTIL EOF; ECE Lecture 1 21

Now what is the assembler? For each of these Pseudo HLL structures what is the corresponding assembler. Each will have assumption as to were data to be tested is. ECE Lecture 1 22

Straight line code - Sequence Straight line Pseudo HLL – little modification is needed. A = m*x + b in Pseudo HLL Where are values – say in memory locations labeled by the same name Code becomes mov m,R8 pushR8 pushx callsmult popR8 addb,R8 movR8,A ECE Lecture 1 23

Decision Decision structure IF condition THEN action if true ELSE action if false END IF; Example: IF (A<B) THEN temp=A; A=B; B=temp END IF; ECE Lecture 1 24

Assembler for example A and B are in memory Will use a register for temp. cmpA,B ;B-A is positive if A<B jlnoexch ;jump if B<A movA,R6 movB,A movR6,B noexch ECE Lecture 1 25

A more efficient coding Could be made a little more efficient Previous code also exchanges when A=B cmpB,A ;A-B is negative if A<B jgenoexch ;jump if B<=A movA,R6 movB,A movR6,B noexch ECE Lecture 1 26

When there is an else Else is similar to the previous code IF (A<B) THEN temp=A; A=B; B=temp; ELSE A = 0; END IF; Much like previous cmpB,A ;A-B is negative if A<B jgeelse ;jump if B<=A movA,R6 movB,A movR6,B jmpafter elseclrA after ECE Lecture 1 27

Repeat structures Finite number of times – DO LOOP Set up any values for loop FOR counter = start TO end [STEP x] LOOP actions of loop END FOR; Example: Sum = 0; FOR i = 1 to 10 LOOP Sum = Sum + element(i); END FOR; How would this example be coded? ECE Lecture 1 28

Coding for Do Loop Where are control values? i – the current index value – use R9 startval – the starting value for i – memory loc endval – the ending value for i – memory sum – in memory element – label of list of values in memory mov i,R9 tolcmpendval,R9 ;R9-endval jgelpexit movR9,R8 decR8 clrc rolcR8 add#element,R8 incR9 jmptol lpexit ECE Lecture 1 29

The repeat and while loops The coding of the repeat and while loops is very similar. Documents where variables are Need loop control and testing of loop control Which branch instruction to use takes some thought Need to remember what the cmp instruction does!! ECE Lecture 1 30

The while loop example i=0; flag=TRUE; WHILE flag LOOP increment i; Actions when value i; IF i = 5 THEN flag = False; END IF; END LOOP; Now translate this to assembler ECE Lecture 1 31

Assembler for while example mov#0,&i mov#1,&flag ;1=TRUE rptcmp&flag,#0 jeqdone inc&i nop;code to do actions cmp&i,#5 jnerpt mov#0,&flag jmprpt donenop;code after loop ECE Lecture 1 32

ECE Lecture 1 33 Demo Demo of loop code.