Lecture_06 - Mathematics & Logic operations

Lecture_06 - Mathematics & Logic operations -...

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

View Full Document Right Arrow Icon
Faculty of Science and Technology Lecture 6 Mathematics & Logic operations SEE103
Background image of page 1

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

View Full DocumentRight Arrow Icon
Basic & Arithmetic & Logic operations The AVR has a basic set of Arithmetic & Logic instructions. These operations are performed on either one or two of the registers R0-R31 in the ALU ( Arithmetic & Logic Unit) ALU can perform - 8 bit AND, OR & XOR -8 bit ADD & SUBTRACT - 8 x 8 bit MULTIPLY - 8 bit COMPLEMENT
Background image of page 2
More advanced Logic NAND & XNOR have to be implemented by using compound statements. Implementing NAND function and Rd,Rs com Rd Implementing XNOR or Rd,Rs com Rd Other then NAND & XNOR, there are no further advanced logic operations!
Background image of page 3

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

View Full DocumentRight Arrow Icon
More advanced Arithmetic There are many more advanced mathematic operations required Eg. -basic division, square roots, powers, logs, trigonometry etc. - all the operations must be able to be done on numbers greater the 8 bits (multiple precision) - numbers may be unsigned or signed. All these operation are possible using the native instructions of the AVR and using compound instructions to perform these tasks. ATMEL provide much of the code to do this in their application notes. We will examine a few of these.
Background image of page 4
unsigned 16 bit addition. We have already seen this in the bin2toascii routine. Eg. R17:R16 <= R17:R16 + R19:18 It is straight forward to add R16 & R18 add16: add R16,R18 ; 8 bit add (no carry) of low bytes ;there possibility an carry (overflow) occurring this is ; indicated by the C (carry) bit set. ;The carry needs to be added to the high order add adc R17,R19 ; 8 bit add with carry of high bytes ret This addition could be carried out to any required precision, as long as the higher order carries are added in!
Background image of page 5

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

View Full DocumentRight Arrow Icon
unsigned 16 bit subtraction We have already seen this in the bin2toascii routine. Eg. R17:R16 <= R17:R16 - R19:18 It is straight forward to subtract R18 from R16 sub16: sub R16,R18 ; 8 bit subtract (no carry) of low order bytes ;there possibility an carry (underflow) occurring this is indicated by ;the C (carry) bit set. ;The carry needs to be subtracted as well from high order btes sbc R17,R19 ; 8 bit subtract with carry ret This subtraction could be carried out to any required precision, as long as the higher order carries are subtracted !
Background image of page 6
Code directly from the box! The following code has been directly provided by ATMEL, along with documentation including flowcharts. Yes, even ATMEL use flowcharts! You will find the ATMEL Application notes AVR200, AVR202 on the ATMEL website http://www.atmel.com/dyn/products/app_note s.asp?family_id=607
Background image of page 7

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

View Full DocumentRight Arrow Icon
16 bit unsigned addition ;*************************************************************************** ;* ;* "add16" - Adding 16-bit registers ;* ;* Courtesy of ATMEL Corporation - AVR202 16 bit arithmetic ;* This example adds the two pairs of register variables (add1l,add1h) ;* and (add2l,add2h) The result is placed in (add1l, add1h). ;* ;* Number of words :2 ;* Number of cycles :2 ;* Low registers used :None ;* High registers used:4 ;* ;* Note: The sum and the addend share the same register. This causes the ;* addend to be overwritten by the sum.
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 / 26

Lecture_06 - Mathematics &amp;amp; Logic operations -...

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