Chapter7 Arithmetic

Chapter7 Arithmetic - Arithmetic Operations Chapter 7,...

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

View Full Document Right Arrow Icon
Arithmetic Operations Chapter 7, Section 7.11
Background image of page 1

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

View Full DocumentRight Arrow Icon
Binary Addition C examples int i, j, k; // 16-bit integers char m,n; // 8-bit integers float w,y,z; // 32-bit floating-point * i = j + k; // add 16-bit integers m = n + 5; // add 8-bit integers w = y + z; // add 32-bit numbers * * floating-point not directly supported by 68HC12
Background image of page 2
Simple addition in 68HC12 Sum = Addend + Augend Addend (left-hand source operand) must be in a register Augend (right-hand operand may be immediate or memory Sum replaces the addend in its register 8-bit add instructions: ADDA op ; A + op => A (op = immediate or memory) ADDB op ; B + op => B (op = immediate or memory) ABA ; A + B => A (only register+register form) 16-bit add instruction: ADDD op ; D + op => D (D = A:B)
Background image of page 3

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

View Full DocumentRight Arrow Icon
Addition examples adda #50 A = A + 50 10 addb #$50 A = A + 50 16 = A + 80 10 addd #$2fa3 D = D + 2fa3 16 (D = A:B) adda data A = A + M[data] adda data+1 A = A + M[data+1] addd data D = D + M[data,data+1] ldx #data adda 0,x A = A + M[data]
Background image of page 4
Condition codes Five ALU outputs signal different “conditions” related to the result of an operation Z => the result was Z ero (all 0’s) C => there was a C arry out of the most significant bit of the result N => the result was N egative V => there was a 2’s complement oV erflow H => “H alf” carry – there was a carry out of bit 3 of the result (used in BCD arithmetic) The 5 “condition codes” are saved in the “Condition Code Register”
Background image of page 5

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

View Full DocumentRight Arrow Icon
Condition code examples 00100110 + 10111101 0 11100011 Carry (C = 0) Sign (N = 1) Result is non-zero (Z = 0) No 2’s complement overflow (V = 0) Unsigned Signed interpretation: interpretation: 38 +38 + 189 +(-67) 227 -29
Background image of page 6
Testing an arithmetic result Conditional branch jumps to a designated location if some condition is true Examples: adda data ;add instruction beq Zero ;branch if result=0 bne Nonzero ;branch if result <> 0 bmi Minus ;branch if result minus bpl Plus ;branch if result positive bcc NoCY ;branch if carry flag clear (0) bcs CY ;branch if carry flag set (1) bvs Overflow ;branch if overflow flag set (1) bvc NoOver ;branch if overflow flag clear (0)
Background image of page 7

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

View Full DocumentRight Arrow Icon
Testing signed results Signed examples: suba #5 ;A = A – 5 bge
Background image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 29

Chapter7 Arithmetic - Arithmetic Operations Chapter 7,...

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

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