Lecture16 - 0306-250 Assembly Language Programming Lecture...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 0306-250 Assembly Language Programming Lecture Sixteen: Multiplication and Division • • • • Multiply and Divide Instructions Test Instructions Load Effective Address Instructions Subroutine Example: Matrix Scale Multiply and Divide Instructions S12CPUV2 Reference Manual, p. 64 2 MUL Instruction S12CPUV2 Reference Manual, p. 238 3 Test Instructions S12CPUV2 Reference Manual, p. 62 4 TSTA Instruction S12CPUV2 Reference Manual, p. 300 5 Load Effective Address Instructions S12CPUV2 Reference Manual, p. 83 6 LEAS Instruction S12CPUV2 Reference Manual, p. 220 7 Matrix Scale Subroutine Example • Integer scale of integer matrix— multiplies each element in matrix by a scalar value é1 ê0 ê 3 ê0 ê ê1 ê5 ë 2 5 3 3 0 3 1 0 5 2 4 4 3 2 1 5ù é 3 6 9 12 15ù 3ú ê 0 15 3 12 9 ú ú ê ú 0ú = ê 0 9 0 9 0 ú ú ê ú 4ú ê 3 9 15 6 12ú 3ú ê15 0 6 3 9 ú û ë û 8 Matrix Scale Subroutine Parameters Register usage “agreement” for design • Inputs – Stack: scale factor (signed word)—value – X: matrix to scale (signed words)—pointer – A: number of rows in matrix (unsigned byte)—value – B: number of columns in matrix (unsigned byte)—value • Outputs – – Y: result (scaled) matrix (signed words)—pointer C: result condition (set if good)—CCR bit value 9 Matrix Scale Subroutine Algorithm Save parameter registers Calculate size of matrix Initialize loop counter Loop Multiply source matrix element by scalar If (overflow) Goto Over Store scaled value in result matrix Decrement counter and BNE Loop Set condition code for correct result Goto Done Over—set condition code for wrong result Done—Restore parameter registers Return 10 Matrix Scale Subroutine: MatrixScale MatrixScale: ; Save registers psha pshb pshx pshy pshy ; Second copy for loop ; to modify ; Calculate size of matrix mul ; A*B = rows*cols ; Setup loop control variable on stack pshd ; Scale each element in the matrix MtxSclLoop: ldy 12,sp ; scale factor ldd 2,x+ ; matrix element emuls ; Check for overflow (word) cpy #0 bne MtxSclNeg tsta bmi MtxSclOver bra MtxSclStore MtxSclNeg: cpy #$FFFF bne MtxSclOver tsta bpl MtxSclOver MtxSclStore: ; Store scaled value in result matrix ldy 2,sp std 2,y+ sty 2,sp ; Update counter and loop if not 0 dec 0,sp bne MtxsclLoop ; Reflect success in CCR orcc #%00000001 bra MtxSclDone MtxSclOver: ; Reflect failure from overflow andcc #%11111110 MtxSclDone: ; Restore registers and stack leas 4,sp ; deallocate temp puly pulx pulb pula rts 11 ...
View Full Document

This note was uploaded on 05/06/2010 for the course EECC 0306-250 taught by Professor Roymelton during the Fall '10 term at RIT.

Ask a homework question - tutors are online