Lecture_06 - Mathematics &amp; Logic operations

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

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

Faculty of Science and Technology Lecture 6 Mathematics & Logic operations SEE103

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

View Full Document
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
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!

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

View Full Document
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.

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

View Full Document
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 !
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

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

View Full Document