Evgenii Legotckoi
Evgenii LegotckoiAug. 24, 2015, 9 p.m.

MUL - multiplication operation in AVR Attiny

MUL - multiplication instruction in microcontrollers, is present, for example, microcontrollers Atmega. But not all AVR microcontrollers there is hardware support multiplication of functions. For example, in microcontrollers Attiny MUL team simply does not exist, so the solution to this problem lies with the program code.

The main point to be taken into account in the implementation of the multiplication function is that to save the multiplication result will need two registers. In one of the registers will be kept low byte of the result, and in the second case bude saved significant byte result.


Software implementation MUL

Below is a function of multiplication, which works with 8-bit numbers and the output provides a 16-bit number.

 ;======= Software multiplication function (implementing mul) ============================
 ; r16    ; multiplicand
 ; r17    ; multiplier
 ; r0     ; the low byte of the result
 ; r1     ; the high byte of result
 ; r19    ; cycle counter
 ;-----------------------------------------------------------------------------------
 mpy8u_c:   
     clr    r1      ; clear the register to store the result of the high byte
     ldi    r19,8   ; We set the starting value of the loop counter
     lsr    r17     ; right shift multiplier
 m8u_1:   
     brcc   m8u_2   ; We make a transition if С = 0
     add    r1,r16  ; to the high byte of the result we add the multiplicand
 m8u_2:   
     ror    r1      ; high byte of the result is shifted to the right
     ror    r0      ; low byte result is shifted to the right
     dec    r19     ; We produce a decrement counter
     brne   m8u_1   ; We make a transition if С != 0
     ret

Note. This software function used arithmetic operations, control of execution of which is assigned to the SREG - AVR Status register.

SREG - AVR Status Register

  • Bit 7 - Bit globally enable interrupts;
    Bit 6 - Bit copying and downloading instructions;
    Bit 5 - Carry flag. Exhibited after some arithmetic operations;
    Bit 4 - Flag of the sign;
    Bit 3 - additions flag to two. Exhibited overflow registers;
    Bit 2 - Flag negative result of arithmetic or logic operations;
    Bit 1 - zero result flag. Exhibited, if the result of arithmetic or logic operation is zero.
    Bit 0 - Carry flag. Indicates transfer in the arithmetic and logic operations.
We recommend hosting TIMEWEB
We recommend hosting TIMEWEB
Stable hosting, on which the social network EVILEG is located. For projects on Django we recommend VDS hosting.

Do you like it? Share on social networks!

Comments

Only authorized users can post comments.
Please, Log in or Sign up
OI

C++ - Test 001. The first program and data types

  • Result:40points,
  • Rating points-8
AD

C ++ - Test 004. Pointers, Arrays and Loops

  • Result:50points,
  • Rating points-4
m

C ++ - Test 004. Pointers, Arrays and Loops

  • Result:80points,
  • Rating points4
Last comments
ИМ
Игорь МаксимовNov. 22, 2024, 11:51 a.m.
Django - Tutorial 017. Customize the login page to Django Добрый вечер Евгений! Я сделал себе авторизацию аналогичную вашей, все работает, кроме возврата к предидущей странице. Редеректит всегда на главную, хотя в логах сервера вижу запросы на правильн…
Evgenii Legotckoi
Evgenii LegotckoiOct. 31, 2024, 2:37 p.m.
Django - Lesson 064. How to write a Python Markdown extension Добрый день. Да, можно. Либо через такие же плагины, либо с постобработкой через python библиотеку Beautiful Soup
A
ALO1ZEOct. 19, 2024, 8:19 a.m.
Fb3 file reader on Qt Creator Подскажите как это запустить? Я не шарю в программировании и кодинге. Скачал и установаил Qt, но куча ошибок выдается и не запустить. А очень надо fb3 переконвертировать в html
ИМ
Игорь МаксимовOct. 5, 2024, 7:51 a.m.
Django - Lesson 064. How to write a Python Markdown extension Приветствую Евгений! У меня вопрос. Можно ли вставлять свои классы в разметку редактора markdown? Допустим имея стандартную разметку: <ul> <li></li> <li></l…
d
dblas5July 5, 2024, 11:02 a.m.
QML - Lesson 016. SQLite database and the working with it in QML Qt Здравствуйте, возникает такая проблема (я новичок): ApplicationWindow неизвестный элемент. (М300) для TextField и Button аналогично. Могу предположить, что из-за более новой верси…
Now discuss on the forum
AW
Ayden WatkinsJan. 2, 2025, 12:09 a.m.
Why Paying for a Research Paper Can Be a Smart Choice Writing a research paper can be a daunting task, especially when faced with tight deadlines, complex topics, or a lack of resources. For many students, paying for a research paper is a practical…
p
pimacontrols85Dec. 31, 2024, 9:39 a.m.
Finding the Right Rittal Small Enclosure for Your Needs Rittal is a leading manufacturer of enclosures for industrial and IT applications. Their small enclosures offer a compact and reliable solution for a wide range of needs, from housing electronic…
Donald Randolph
Donald RandolphDec. 30, 2024, 2:59 a.m.
Personal Injury lawyer Santa Monica As an experienced Santa Monica personal injury lawyer, Donald C. Randolph has recovered over $100 Million in verdicts and settlements for our clients. In severe injury cases, this compensation i…
Nirvana Yoga School
Nirvana Yoga SchoolDec. 30, 2024, 5:13 a.m.
OAuth2.0 через VK, получение email Nirvana Yoga School is one of the most trusted and reputed traditional Rishikesh yoga courses , India certified by Yoga Alliance, USA. We aim to spread traditional yoga teachings so t…
s
sriparkDec. 30, 2024, 4:47 a.m.
Mobile app development company in Chennai A Mobile app development company in Chennai focuses on creating personalized mobile applications to meet various business requirements. These companies offer a full range of services,…

Follow us in social networks