Control structures Hot to translate high level control structures to assembler.

Slides:



Advertisements
Similar presentations
振動スイッチを活用 振動(傾き)を検出 ボールが移動 a)オン時 b)オフ時 オンからオフ時の観察.
Advertisements

Java Control Statements
Instruction formats for the PIC series. ROM encoding Instructions are encoded in binary in ROM. The instructions are fixed format, each occupying 14 bits.
Electronics Design Lab TUTORIAL PIC Microcontrollers Francesco Tenore 2/10/2006.
1 Patt and Patel Ch. 7 LC-3 Assembly Language. 2 LC-3 is a load/store RISC architecture Has 8 general registersHas 8 general registers Has a flat 16-bit.
Control Structures Ranga Rodrigo. Control Structures in Brief C++ or JavaEiffel if-elseif-elseif-else-end caseinspect for, while, do-whilefrom-until-loop-end.
1 CDA 3101 Discussion Section 03.  Problem The following problems deal with translating from C to MIPS. Assume that the variables f, g, h, i and.
1 Today’s lecture  Last lecture we started talking about control flow in MIPS (branches)  Finish up control-flow (branches) in MIPS —if/then —loops —case/switch.
Railway Foundation Electronic, Electrical and Processor Engineering.
Microprocessor and Microcontroller Based Systems Instructor: Eng.Moayed N. EL Mobaied The Islamic University of Gaza Faculty of Engineering Electrical.
Lecture – 5 Assembly Language Programming
Chapter 4 Starting to Program – an Introduction to Assembler The aims of this chapter are to introduce: the essentials of Assembler programming; the Microchip.
9/20/6Lecture 21 -PIC Architecture1 PIC Architecture Instruction Set.
Microcontroller Programming How to make something almost do something else Raffi Krikorian MAS November 2003.
9/20/6Lecture 21 -PIC Architecture1 PIC Architecture Programmers Model and Instruction Set.
Two’s Complement Number wheel for 4 bit numbers
Building Assembler Programs Chapter Five Dr. Gheith Abandah1.
Microprocessor and Interfacing PIC Code Execution
Embedded System Spring, 2011 Lecture 5: The PIC Microcontrollers Eng. Wazen M. Shbair.
11/02/2009CA&O Lecture 03 by Engr. Umbreen Sabir Computer Architecture & Organization Instructions: Language of Computer Engr. Umbreen Sabir Computer Engineering.
Lecture 4: C/C++ Control Structures Computer Programming Control Structures Lecture No. 4.
Embedded System Spring, 2011 Lecture 11: Bank Switching Eng. Wazen M. Shbair.
I Power Higher Computing Software Development High Level Language Constructs.
ITCS 3181 Logic and Computer Systems 2015 B. Wilkinson Slides4-2.ppt Modification date: March 23, Procedures Essential ingredient of high level.
9/20/6Lecture 3 - Instruction Set - Al1 Program Design Examples.
EEE237 Introduction to Microprocessors Week x. SFRs.
Recursion Pepper. Another way to loop Call yourself repeatedly until you say to stop. Example: add up 10 numbers using addUp. -- Input – number to count.
Eng. Husam Alzaq The Islamic Uni. Of Gaza
Computer Architecture CSE 3322 Lecture 3 Assignment: 2.4.1, 2.4.4, 2.6.1, , Due 2/3/09 Read 2.8.
PIC Code Execution How does the CPU executes this simple program? void main() { int i; i = 1; i++; }
Computer Systems – Machine & Assembly code. Objectives Machine Code Assembly Language Op-code Operand Instruction Set.
Department of Electronic & Electrical Engineering Lecture 2 ● Introduction to IO ● Using a subroutine ● Driving a 7seg display.
Working with Time: Interrupts, Counters and Timers
Embedded System Spring, 2011 Lecture 11: Bank Switching Eng. Wazen M. Shbair.
Department of Electronic & Electrical Engineering Lecture 4. ➢ Loops ➢ Delays ➢ Conditional instructions ➢ Simple clock example.
Programming PIC 16F84A in Assembly. PIC16F84 pin-out and required external components.
Applications examples. A binary count : stepped manually and reset with push buttons. Define ports Reset portd Reset =0? INCF portd no Step =0? yes.
1.  List all addressing modes of PIC18 uCs  Contrast and compare the addressing modes  Code PIC18 instructions to manipulate a lookup table.  Access.
1. University of Energy and Natural Resources, Sunyani Institute of Distance Learning Dept. of Comp. & Elect. Eng. CENG 365 – Microprocessor DR. NANA.
Microprocessor Systems Design I
Lecture – 5 Assembly Language Programming
Microprocessor Systems Design I
Microprocessor Systems Design I
Micro-processor vs. Micro-controller
Microprocessor Systems Design I
HTP Programme: Assembler
PIC – ch. 2b Md. Atiqur Rahman Ahad.
16.317: Microprocessor System Design I
Morgan Kaufmann Publishers Computer Organization and Assembly Language
EECE.3170 Microprocessor Systems Design I
CS 301 Fall 2002 Control Structures
EECE.3170 Microprocessor Systems Design I
Structured Program
Passing Parameters Data passed to a subroutine is called a parameter.
EECE.3170 Microprocessor Systems Design I
EECE.3170 Microprocessor Systems Design I
EECE.3170 Microprocessor Systems Design I
EECE.3170 Microprocessor Systems Design I
EECE.3170 Microprocessor Systems Design I
EECE.3170 Microprocessor Systems Design I
EECE.3170 Microprocessor Systems Design I
EECE.3170 Microprocessor Systems Design I
The structure of programming
EECE.3170 Microprocessor Systems Design I
EECE.3170 Microprocessor Systems Design I
EECE.3170 Microprocessor Systems Design I
EECE.3170 Microprocessor Systems Design I
EECE.3170 Microprocessor Systems Design I
Md. Atiqur Rahman Ahad PIC18… Ch. 3.1 Md. Atiqur Rahman Ahad
Part VI Looping Structures
Presentation transcript:

Control structures Hot to translate high level control structures to assembler

If a then b else c endif Note that if a then b endif is a special case of the above. In PIC assembler this takes the general form: Assume a is a bit flag in a register 1. btfss a ; if a then skip next instr 2. goto l1 ; if a false goto l1 3. ;code to do b 4. goto l2 5. l1 6. ;code to do c 7. l2

while a do b endwhile On a PIC you do the following 1. l1 ; start label 2. btfss a ; test condition a 3. goto l2 ; if a is false we go to end 4. ; code for action b 5. goto l1 ; try again 6. l2 ; end while label

Repeat loop High Level Code Repeat A Until b; Assembler 1. Startlabel 2. ; code for A 3. btfss b ; test b 4. goto exitlabel 5. goto startlabel 6. exitlabel

For Loops For i:=20 downto 1 do A Movlw 20 ; set i:=20 Movwf regi Startlabel ; code for A DECFSZ regi,1 ; decrement skip zero goto startlabel ; repeat if >0

Upward for loops For i:=1 to 10 do A Movlw 10 ; set count:=10 Movwf count clrf regi ; initialise i to 0 Startlabel incf regi,1 ; increment I, thus =1 first time ; code for A DECFSZ count,1 ; decrement skip zero goto startlabel ; repeat if >0

Switch statement This is explained in the last lecture on state machines.

Call subroutine A simple parameter- less subroutine can be done as follows Foo() Call foo Foo ; code for foo return

Subroutines with parameters In assembler one normally writes routines to pass parameters in registers, If you are calling routines written in High level language from an assembler program on a big CISC processor like a Pentium, then you have to follow the high level language calling convention. On RISC machines registers are used for parameters even on big processors

Passing Parameters Suppose we want to call a simple function foo which takes 2 byte integer parameters. Suppose that it just adds the two bytes for now. We want the effect of calling foo(1,2)

Register passing of params Suppose the C definition of foo was foo(char a, char b){ return a+b;} We may choose to pass parameter a in the W register and assign another register ( say 7f ) to pass B in.

Example call code ; foo(1,2); MOVLW 02 ; w:=2 MOVWF 07Fh; reg7f:=w MOVLW 0x01 ; w:=1 CALL foo

Called code ; char foo(char a, char b) ; { return (char)(a+b);} foo ADDWF 07fh,W RETURN On entry a is in W and b is in reg7f, we return the result in W

Nested calls If foo were to call another routine then the w and 7f registers would be corrupted, thus you need to save the parameters in other registers at the start of foo foo MOVWF 24h ; save w in reg 24 MOVF 07Fh,W MOVWF 25h ; save reg7f in reg25 ; rest of code for foo