EE357 Lecture 7

EE357 Lecture 7 - Recap:Branch Instructions Operation: (PC)...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
EE 357 Lecture 7 Rotate and Shift Instructions Subroutines Stacks Recap:Branch Instructions • Operation: (PC) + disp. ĺ PC • Branches allow us to jump backward or forward in our code label ---- ---- ---- ---- branch ---- ---- branch ---- ---- ---- label ---- Recap: Condition Codes (Flags) • 5 tests w/ results stored as 1=true/0=false – X = eXtended Flag • Used for Extended Precision Arithmetic • Usually set the same as the C flag – N = Negative Flag • Tests if the result is negative • Just a copy of the MSB of result –Z = Ze ro F lag • Tests if the result is equal to 0 – V = 2’s complement oVerflow Flag • Set if p+p=n or n+n=p – C = Carry Flag (Unsigned Overflow Flag) • Set if (Cout=1 and Add op.) or (Cout=0 and Sub. Op) DEFAULT SETTINGS Recap: Compare Instruction • Format – CMP.s <ea>,Dn •2 nd operand must be a data register – CMPI.s #imm,<ea> • CMP instruction subtracts src2 – src1, sets the condition codes, but discards result – Note that to compare A w/ B the order of your operands should be CMP.s B,A
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Recap: Conditional Branches • After a CMP instruction subtracts A-B the Bcc instruction will check for the specified condition Cond. Test EQ = Z NE ¡ Z LT < N•V + N •V LE ¢ N•V + N •V + Z GT > (N •V + N•V) • Z’ GE £ (N •V + N•V) Cond. Test EQ = Z NE ¡ Z LS ¢ C + Z HI > C •Z Cond. Test MI N PL N VS V VC V CS C CC C Signed Unsigned Flag Check Recap: Branch Format 0110 • Branch Instructions: (PC) + disp. ĺ PC •Fo rma t : • Displacement is the value that should be added to the PC so that it now points to the desired branch target location • Displacement is a signed value (pos. or neg.) Cond. 16-bit disp. (if needed) 8-bit disp. Recap: Calculating Displacements • A displacement of $0006 can fit in the 8-bit displacement field • 16-bit displacement is not needed and thus the next instruction is stored after the 1-word BLE 0110 1111 = LE next instruction 0000 0110 • If the displacement doesn’t fit, then the 8-bit disp is 00 • And a 16-bit displacement is stored in extended word after BLE Another Example • Disp. = (Address of Label) (Address of Branch + 2) • Disp. = $8004 ($8014 + 2) = $8004 - $8016 = $FFEE ORG $8000 MOVE.W #0,D0 LOOP CMP.W $7002,D0 BEQ ELSE ADD.L #5,D1 ADD.W #1,D0 BRA LOOP NEXT ---- ---- ---- CMP MOVE 0000 ADD 7002 BEQ ADD 0000 0005 ---- 0001 $8004 $8000 $8002 $800A $8006 $8008 $8010 $800C $800E $8016 $8012 BRA $8014
Background image of page 2
Calculating Displacements • With displacement of $FFEE it can fit in the 8-bit displacement field • Can remove leading 0’s from positive numbers and leading 1’s from negative number (need to retain at least one copy of the sign bit…can’t remove all the 1’s) 0110 0000=BRA next instruction 1110 1110 FFEE 1111 1111 1110 1110 1111 1111 1110 1110 10 1110 More Displacements • If a displacement is found to be $FF00 • Must leave at least one copy of the MSB, and thus this requires 9-bits and will use the 16-bit displacement field 0110 0000=BRA 1111 1111 0000 0000 0000 0000 FF00 1111 1111 0000 0000 1111 1111 0000 0000 1 0000 0000 More Displacements • If a displacement is found to be $00FF • Must leave at least one copy of the MSB, and thus this requires 9-bits and will use the 16-bit displacement field 0110 0000=BRA 0000 0000 1111 1111 0000 0000 00FF 0000 0000 1111 1111 0000 0000 1111 1111
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 10

EE357 Lecture 7 - Recap:Branch Instructions Operation: (PC)...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online