680xx program examples
Skip this Video
Download Presentation
680XX Program Examples

Loading in 2 Seconds...

play fullscreen
1 / 13

680XX Program Examples - PowerPoint PPT Presentation

  • Uploaded on

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. 680XX Program Examples. D0.B contains binary value D0.W contains 3-digit BCD result

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
Download Presentation

PowerPoint Slideshow about ' 680XX Program Examples' - hyman

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
680xx program examples

Binary to BCD

Matrix Addition

Ones Count

String Compare

Sector Map

Raster Graphics

Subroutine Calls


Understand instruction usage


Microprocessor Systems Design, Clements, Ch. 2-3

680XX Program Examples
binary to bcd conversion
D0.B contains binary value

D0.W contains 3-digit BCD result

CLR.L D1 Clear D1 for 32-bit dividend

MOVE.B D0,D1 Copy source to D1

DIVU.W #&100,D1 Get 100s digit in D1(0:15)

MOVE.W D1,D0 Save digit in D0(0:3)

SWAP D1 Move remainder to D1(0:15)

AND.L #$FFFF,D1 Clear MSW of D1

DIVU #&10,D1 Get 10s digit in D1(0:15)

LSL.W #&4,D0 Shift 100s digit one place

OR.W D1,D0 Insert 10s digit in D0

LSL.W #&4,D0 Shift digits one place

SWAP D1 Move remainder to D1(0:15)

OR.W D1,D0 Insert 1s digit into LSN

Binary to BCD Conversion
conversion example
11001100 (204) to 0010 0000 0100

CLR.L D1 D0 = 000000CC, D1 = 00000000

MOVE.B D0,D1 D0 = 000000CC, D1 = 000000CC

DIVU.W #&100,D1 D0 = 000000CC, D1 = 00040002

MOVE.W D1,D0 D0 = 00000002, D1 = 00040002

SWAP D1 D0 = 00000002, D1 = 00020004

AND.L #$FFFF,D1 D0 = 00000002, D1 = 00000004

DIVU #&10,D1 D0 = 00000002, D1 = 00040000

LSL.W #&4,D0 D0 = 00000020, D1 = 00040000

OR.W D1,D0 D0 = 00000020, D1 = 00040000

LSL.W #&4,D0 D0 = 00000200, D1 = 00040000

SWAP D1 D0 = 00000200, D1 = 00000004

OR.W D1,D0 D0 = 00000204, D1 = 00000004

Conversion Example
matrix addition
C = A + B, A, B, C are m x n matrices

store matrix by rows - row order

a1,1 stored at A, ai,j stored at A+(i-1)n+j-1

MOVEA.L #A,A0 A0 is base of matrix A

MOVEA.L #B,A1 A1 is base of matrix B

MOVEA.L #C,A2 A2 is base of matrix C

CLR.W D2 Clear element offset

MOVE.W #m,D0 D0 is row counter

L2 MOVE.W $n,D1 D1 is column counter

L1 MOVE.B (A0,D2.W),D6 Get element from A

ADD.B (A1,D2.W),D6 Add element from B

MOVE.B D6,(A2,D2.W) Store sum in C

ADDQ.W #&1,D2 Increment element pointer

SUB.W #&1,D1 Repeat for n columns


SUB.W #&1,D0 Repeat for m rows


Matrix Addition
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_CNT MOVEM.L D1-D2,-(A7) Save D1 and D2

CLR.B D1 Clear 1’s counter

MOVEQ #$7,D2 D2 points to MSB

NXT_BIT BTST D2,D0 Test D2th bit of D0

BEQ.S LP_TST Do nothing if 0

ADDQ.B #$1,D1 Else incr 1’s cnt

LP_TST SUBQ.B #$1,D2 Decr bit pointer

BGE NXT_BIT Repeat until done

MOVE.B D1,D0 Put count in D0

MOVEM.L (A7)+,D1-D2 Restore D1 and D2

RTS Return

One’s Count
one s count1

MOVE.B <data>,D0 Avoid by having data in D0

JSR ONE_CNT Jump to subroutine

MOVE.B D0,<dest> Avoid by using result in D0

note that D1 and D2 are saved and restored by subroutine

to/from stack


use BSR, let assembler compute offset

use global register allocation to avoid stack save/restore

use register windows to avoid stack save/restore - SPARC

One’s Count
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,D0 D0 is byte counter

L1 CMPM.B (A0)+,(A1)+ Compare characters

BLT LT S1 < S2

BGT GT S1 > S2

DBRA D0,L1 Repeat until done

CLR.L D0 D0 = 0

RTS Return

LT MOVEQ #$-1,D0 D0 = -1

RTS Return

GT MOVEQ #$1,D0 D0 = 1

RTS Return

DBRA == DBF - condition always false, so loop

String Compare
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.L D0 Initial bit offset D0 = 0

LEA MAP,A0 A0 points to sector bitmap

MOVE.W #&63,D7 Up to 64 fields to test

L1 BFFFO (A0){D0:32},D0 If free sector found, Z=0

and D0 = offset from A0

DBNE D7,L1 Decr D7 until Z=0 or end

BEQ FULL Disk full

BFCLR (A0){D0:1} Claim sector, D0 = sector

Sector Map
raster graphics
Copy 15x15 block from (x1,y1) to (x2,y2)

e.g. bitmapped character set

Raster Graphics


Store display in row order




raster graphics1
A - origin of bitmap

D0 - x1, D1 - y1, D2 - x2, D3 - y2

MV LEA A,A0 A0 = base address of bitmap

MULU.L #&128,D1 D1 = src row offset

MULU.L #&128,D3 D3 = dest row offset

MOVEQ #&14,D4 15 lines to move

L1 BFEXTU (A0,D1.L){D0.L:15},D5 Copy line to D5

BFINS D5,(A0,D3.L){D2.L:15} Copy into image

LEA 128(A0),A0 Update pointer by a line

DBRA D4,L1 Repeat until all lines moved

RTS Return

Raster Graphics
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



MOVE.L <ea>,D0


Pass parameters by reference

put address in address registers

save previous addresses on stack if necessary



LEA $002000,A0


Subroutine Calls
subroutine calls1
Pass via stack

data and references


PEA TEXT_ST Push text starting addr

PEA TEXT_END Push text ending addr

PEA STR_ST Push string starting addr

PEA STR_END Push string ending addr

BSR STR_MT Call subroutine

LEA 16(SP),SP Pop stack


STR_MT LEA 4(SP),A0 Parameter ptr in A0

MOVEM.L A3-A6,-(SP) Save registers

MOVEM.L (A0)+,A3-A6 Get params off stack


MOVEM.L (SP)+,A3-A6 Restore registers

RTS Return

Subroutine Calls
subroutine calls2
Subroutine Calls


Return Address

SP after BSR


SP before BSR

A0 after LEA 4(SP),A0


STR_ST ptr

A0 after MOVEM





SP initial value