680XX Program Examples Outline –Binary to BCD –Matrix Addition –Ones Count –String Compare –Sector Map –Raster Graphics –Subroutine Calls Goal –Understand.

Slides:



Advertisements
Similar presentations
Ch. 7 Local Variables and Parameter Passing From the text by Valvano: Introduction to Embedded Systems: Interfacing to the Freescale 9S12.
Advertisements

1 Lecture 3: MIPS Instruction Set Today’s topic:  More MIPS instructions  Procedure call/return Reminder: Assignment 1 is on the class web-page (due.
Chapter 3 Introduction to the 68000
The University of Adelaide, School of Computer Science
 Instructor: Rob Nash  Readings: Chap 7-9  Midterm next Monday! ◦ Review this Wednesday ◦ You will see code again…
EECC250 - Shaaban #1 Lec # 2 Winter Addressing Modes  Addressing modes are concerned with the way data is accessed  Addressing can be.
The family.
MIPS ISA-II: Procedure Calls & Program Assembly. (2) Module Outline Review ISA and understand instruction encodings Arithmetic and Logical Instructions.
1 Procedure Calls, Linking & Launching Applications Lecture 15 Digital Design and Computer Architecture Harris & Harris Morgan Kaufmann / Elsevier, 2007.
9/20/6Lecture 3 - Instruction Set - Al Instruction Set.
Computer Architecture CSCE 350
CPS3340 COMPUTER ARCHITECTURE Fall Semester, /17/2013 Lecture 12: Procedures Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER SCIENCE CENTRAL.
Ch. 8 Functions.
The University of Adelaide, School of Computer Science
The University of Adelaide, School of Computer Science
EECC250 - Shaaban #1 Lec # 6 Winter Stack-Related Instructions PEA Push Effective Address Calculates an effective address and pushes it.
Functions Functions and Parameters. History A function call needs to save the registers in use The called function will use the registers The registers.
ECE 353 Introduction to Microprocessor Systems Michael G. Morrow, P.E. Week 6.
LC-3 Computer LC-3 Instructions
EECC250 - Shaaban #1 Lec # 5 Winter Stacks A stack is a First In Last Out (FILO) buffer containing a number of data items usually implemented.
EECC250 - Shaaban #1 lec #16 Winter Estimation of Assembly Programs Execution Time For a CPU running at a constant clock rate: clock rate =
Overview C programming Environment C Global Variables C Local Variables Memory Map for a C Function C Activation Records Example Compilation.
M68K Assembly Language Programming Bob Britton Chapter 6 Efficient Algorithm Development Notice: Slides in this series originally, provided by B.Britton,
EECC250 - Shaaban #1 lec #7 Winter Local workspace of a subroutine: A number of temporary memory locations required by the subroutine for temporary.
Chapter 9 Trap Routines TRAP number (go to service routine) & RET (return from service routine) Subroutines (or Functions) JSR offset or JSRR rn (go to.
Chapters 4 & 5: LC-3 Computer Architecture Machine Instructions Assembly language Programming in Machine and Assembly Language.
Computer Architecture Lecture 13 – part 2 by Engineer A. Lecturer Aymen Hasan AlAwady 7/4/2014 University of Kufa - Information Technology Research and.
9/20/6Lecture 3 - Instruction Set - Al Instruction Set (2)
CS41B MACHINE David Kauchak CS 52 – Fall Admin  Midterm Thursday  Review question sessions tonight and Wednesday  Assignment 3?  Assignment.
9-1 EE 319K Introduction to Microcontrollers Lecture 9:I/O Synchronization; LCD Interfacing; Implementing Local Variables using a Stack Frame; Parameter.
Natawut NupairojAssembly Language1 Memory and Stack.
Adapted from Computer Organization and Design, Patterson & Hennessy, UCB ECE232: Hardware Organization and Design Part 7: MIPS Instructions III
Passing Parameters using Stack Calling program pushes parameters on the stack one element at a time before calling subroutine. Subroutine Call (jsr, bsr)
Runtime Stack Computer Organization I 1 November 2009 © McQuain, Feng & Ribbens MIPS Memory Organization In addition to memory for static.
Lecture 4: MIPS Instruction Set
V 1.01 Arrays and Pointers in C A pointer variable is a variable that contains the address of another variable. An array is a collection of like elements,
by Richard P. Paul, 2nd edition, 2000.
1 Stacks, Subroutines, I/O Routines Today: First Hour: Stacks, Subroutines –Section 3.9,3.10 of Huang’s Textbook –In-class Activity #1 Second Hour: I/O.
Arrays and Strings in Assembly
Chapter 2 — Instructions: Language of the Computer — 1 Conditional Operations Branch to a labeled instruction if a condition is true – Otherwise, continue.
CPS 4150 Computer Organization Chapter 2-2 Fall 2006 Ching-Song Don Wei.
F28HS Hardware-Software Interface Lecture 11: ARM Assembly Language 5.
Function Calls in Assembly MIPS R3000 Language (extensive use of stack) Updated 7/11/2013.
Lecture 5: Procedure Calls
Figure 8.1 of course package
e. g. Write a program to count the spaces in a string
Chapter 9 TRAP Routines and Subroutines
Computer Science 210 Computer Organization
The Stack Chapter 5 Lecture notes for SPARC Architecture, Assembly Language Programming and C, Richard P. Paul by Anu G. Bourgeois.
Subroutines … passing data
Stack Frames Stack frame = block of memory located in the system stack that contains: return address input parameters (from calling program to subroutine)
Chapter 9 TRAP Routines and Subroutines
Lecture 3 - Instruction Set - Al
Chapter 9 TRAP Routines and Subroutines
Computer Science 210 Computer Organization
ECE232: Hardware Organization and Design
Passing Parameters Data passed to a subroutine is called a parameter.
Chapter 8 Central Processing Unit
The University of Adelaide, School of Computer Science
Chapter 9 TRAP Routines and Subroutines
Lecture 5: Procedure Calls
The MOVE Multiple: MOVEM Instruction
Chapter 9 TRAP Routines and Subroutines
Subroutines … passing data
Some Assembly (Part 2) set.html.
Chapter 9 TRAP Routines and Subroutines
Chapter 9 TRAP Routines and Subroutines
Lecture 3 - Instruction Set - Al
ECE511: Digital System & Microprocessor
Lecture 3 - Instruction Set - Al
Presentation transcript:

680XX Program Examples Outline –Binary to BCD –Matrix Addition –Ones Count –String Compare –Sector Map –Raster Graphics –Subroutine Calls Goal –Understand instruction usage Reading –Microprocessor Systems Design, Clements, Ch. 2-3

Binary to BCD Conversion D0.B contains binary value D0.W contains 3-digit BCD result CLR.LD1Clear D1 for 32-bit dividend MOVE.BD0,D1Copy source to D1 DIVU.W#&100,D1Get 100s digit in D1(0:15) MOVE.WD1,D0Save digit in D0(0:3) SWAPD1Move remainder to D1(0:15) AND.L#$FFFF,D1Clear MSW of D1 DIVU#&10,D1Get 10s digit in D1(0:15) LSL.W#&4,D0Shift 100s digit one place OR.WD1,D0Insert 10s digit in D0 LSL.W#&4,D0Shift digits one place SWAPD1Move remainder to D1(0:15) OR.WD1,D0Insert 1s digit into LSN

Conversion Example (204) to CLR.LD1D0 = CC, D1 = MOVE.BD0,D1D0 = CC, D1 = CC DIVU.W#&100,D1D0 = CC, D1 = MOVE.WD1,D0D0 = , D1 = SWAPD1D0 = , D1 = AND.L#$FFFF,D1D0 = , D1 = DIVU#&10,D1D0 = , D1 = LSL.W#&4,D0D0 = , D1 = OR.WD1,D0D0 = , D1 = LSL.W#&4,D0D0 = , D1 = SWAPD1D0 = , D1 = OR.WD1,D0D0 = , D1 =

Matrix Addition C = A + B, A, B, C are m x n matrices –store matrix by rows - row order –a 1,1 stored at A, a i,j stored at A+(i-1)n+j-1 MOVEA.L#A,A0A0 is base of matrix A MOVEA.L#B,A1A1 is base of matrix B MOVEA.L#C,A2A2 is base of matrix C CLR.WD2Clear element offset MOVE.W#m,D0D0 is row counter L2MOVE.W$n,D1D1 is column counter L1MOVE.B(A0,D2.W),D6Get element from A ADD.B(A1,D2.W),D6Add element from B MOVE.BD6,(A2,D2.W)Store sum in C ADDQ.W#&1,D2Increment element pointer SUB.W#&1,D1Repeat for n columns BNEL1 SUB.W#&1,D0Repeat for m rows BNEL2

One’s Count Subroutine to count number of 1s in byte –D0.B - input/output register –D1 - one’s counter (not modified) –D2 - pointer to bit of D0 to be tested (not modified) ONE_CNTMOVEM.L D1-D2,-(A7)Save D1 and D2 CLR.B D1Clear 1’s counter MOVEQ #$7,D2D2 points to MSB NXT_BITBTST D2,D0Test D2th bit of D0 BEQ.S LP_TSTDo nothing if 0 ADDQ.B #$1,D1Else incr 1’s cnt LP_TSTSUBQ.B #$1,D2Decr bit pointer BGE NXT_BITRepeat until done MOVE.B D1,D0Put count in D0 MOVEM.L (A7)+,D1-D2Restore D1 and D2 RTSReturn

One’s Count Usage MOVE.B,D0Avoid by having data in D0 JSRONE_CNTJump to subroutine MOVE.BD0, Avoid by using result in D0 –note that D1 and D2 are saved and restored by subroutine »to/from stack Alternative –use BSR, let assembler compute offset –use global register allocation to avoid stack save/restore –use register windows to avoid stack save/restore - SPARC

String Compare Compare strings S1 and S2 of length n –return 1 if S1 > S2, 0 if S1 == S2, -1 if S1 < S2 –A0 points to S1, A1 points to S2, n in D0, result in D0 SUBQ#$1,D0D0 is byte counter L1CMPM.B(A0)+,(A1)+Compare characters BLTLTS1 < S2 BGTGTS1 > S2 DBRAD0,L1Repeat until done CLR.LD0D0 = 0 RTSReturn LTMOVEQ#$-1,D0D0 = -1 RTSReturn GTMOVEQ#$1,D0D0 = 1 RTSReturn –DBRA == DBF - condition always false, so loop

Sector Map Disk of byte sectors (512KB) –sector map - vector of 2048 bits (64 longwords) »1 bit per sector »bit is 1 if sector is free, 0 if sector is used –find first free sector and claim it CLR.LD0Initial bit offset D0 = 0 LEAMAP,A0A0 points to sector bitmap MOVE.W#&63,D7Up to 64 fields to test L1BFFFO (A0){D0:32},D0If free sector found, Z=0 and D0 = offset from A0 DBNED7,L1Decr D7 until Z=0 or end BEQ FULLDisk full BFCLR(A0){D0:1}Claim sector, D0 = sector

Raster Graphics Copy 15x15 block from (x1,y1) to (x2,y2) –e.g. bitmapped character set 0,0 1023,767 Store display in row order x1,y1 x2,y2

Raster Graphics A - origin of bitmap D0 - x1, D1 - y1, D2 - x2, D3 - y2 MVLEAA,A0A0 = base address of bitmap MULU.L#&128,D1D1 = src row offset MULU.L #&128,D3D3 = dest row offset MOVEQ #&14,D415 lines to move L1BFEXTU(A0,D1.L){D0.L:15},D5Copy line to D5 BFINSD5,(A0,D3.L){D2.L:15}Copy into image LEA128(A0),A0Update pointer by a line DBRAD4,L1Repeat until all lines moved RTSReturn

Subroutine Calls Call with BSR, JSR, return with RTS, RTD, RTR –RTD if deallocating stack frame, RTR if restoring CCR Pass parameters by value –put data in data registers »save previous data on stack if necessary –example MOVE.L D0,-(SP) MOVE.L,D0 BSR SUBR Pass parameters by reference –put address in address registers »save previous addresses on stack if necessary –example MOVE.L A0,-(SP) LEA $002000,A0 BSR SUBR

Subroutine Calls Pass via stack –data and references –example PEA TEXT_STPush text starting addr PEA TEXT_ENDPush text ending addr PEA STR_STPush string starting addr PEA STR_ENDPush string ending addr BSR STR_MTCall subroutine LEA 16(SP),SPPop stack... STR_MTLEA4(SP),A0Parameter ptr in A0 MOVEM.L A3-A6,-(SP)Save registers MOVEM.L (A0)+,A3-A6Get params off stack... MOVEM.L (SP)+,A3-A6Restore registers RTSReturn

Subroutine Calls Return Address STR_END ptr STR_ST ptr TEXT_END ptr TEXT_ST ptr Stack SP after BSR SP before BSR SP initial value A0 after LEA 4(SP),A0 A0 after MOVEM A3 A5 A6 A4 Memory String Text...