Download presentation

Presentation is loading. Please wait.

Published byJaniya Cornish Modified over 2 years ago

1
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

2
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

3
Conversion Example 11001100 (204) to 0010 0000 0100 CLR.LD1D0 = 000000CC, D1 = 00000000 MOVE.BD0,D1D0 = 000000CC, D1 = 000000CC DIVU.W#&100,D1D0 = 000000CC, D1 = 00040002 MOVE.WD1,D0D0 = 00000002, D1 = 00040002 SWAPD1D0 = 00000002, D1 = 00020004 AND.L#$FFFF,D1D0 = 00000002, D1 = 00000004 DIVU#&10,D1D0 = 00000002, D1 = 00040000 LSL.W#&4,D0D0 = 00000020, D1 = 00040000 OR.WD1,D0D0 = 00000020, D1 = 00040000 LSL.W#&4,D0D0 = 00000200, D1 = 00040000 SWAPD1D0 = 00000200, D1 = 00000004 OR.WD1,D0D0 = 00000204, D1 = 00000004

4
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

5
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

6
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

7
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

8
Sector Map Disk of 2048 256-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

9
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

10
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

11
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

12
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

13
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...

Similar presentations

OK

Passing Parameters using Stack Calling program pushes parameters on the stack one element at a time before calling subroutine. Subroutine Call (jsr, bsr)

Passing Parameters using Stack Calling program pushes parameters on the stack one element at a time before calling subroutine. Subroutine Call (jsr, bsr)

© 2018 SlidePlayer.com Inc.

All rights reserved.

Ads by Google

Ppt on body mass index Ppt on coalition government of kenya Download seminar ppt on android Ppt on art of war author Ppt on computer graphics applications Body systems for kids ppt on batteries Ppt on email etiquettes presentation ideas Ppt on synthesis and degradation of purines and pyrimidines are components Ppt on time management skills Ppt on low level language goals