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
Ua

Qt - Test 001. Signals and slots

  • Result:84points,
  • Rating points4
Ua

Qt - Test 001. Signals and slots

  • Result:42points,
  • Rating points-8
ОК

Qt - Test 001. Signals and slots

  • Result:47points,
  • Rating points-6
Last comments
ИМ
Игорь МаксимовNov. 22, 2024, 4:51 p.m.
Django - Tutorial 017. Customize the login page to Django Добрый вечер Евгений! Я сделал себе авторизацию аналогичную вашей, все работает, кроме возврата к предидущей странице. Редеректит всегда на главную, хотя в логах сервера вижу запросы на правильн…
Evgenii Legotckoi
Evgenii LegotckoiOct. 31, 2024, 6:37 p.m.
Django - Lesson 064. How to write a Python Markdown extension Добрый день. Да, можно. Либо через такие же плагины, либо с постобработкой через python библиотеку Beautiful Soup
A
ALO1ZEOct. 19, 2024, 1:19 p.m.
Fb3 file reader on Qt Creator Подскажите как это запустить? Я не шарю в программировании и кодинге. Скачал и установаил Qt, но куча ошибок выдается и не запустить. А очень надо fb3 переконвертировать в html
ИМ
Игорь МаксимовOct. 5, 2024, 12:51 p.m.
Django - Lesson 064. How to write a Python Markdown extension Приветствую Евгений! У меня вопрос. Можно ли вставлять свои классы в разметку редактора markdown? Допустим имея стандартную разметку: <ul> <li></li> <li></l…
d
dblas5July 5, 2024, 4:02 p.m.
QML - Lesson 016. SQLite database and the working with it in QML Qt Здравствуйте, возникает такая проблема (я новичок): ApplicationWindow неизвестный элемент. (М300) для TextField и Button аналогично. Могу предположить, что из-за более новой верси…
Now discuss on the forum
NW
Nayo WaiJan. 30, 2025, 2:22 p.m.
не запускается компьютер!!! Не запускается компьютер (точнее работает блок , но сам монитор вообще жесть)В общем я ничего с интернета не скачивала в последнее время. На компе никаких левых пр…
n
nklyJan. 3, 2025, 7:52 a.m.
Нужно запретить перемещение только некоторых итемов, остальные перемещать можно. Вопрос решен. Узнать QModelIndex элемента на который мы перетаскиваем другой элемент, можно с помощью функции indexAt(event->position().toPoint()) представления QTreeViev вызываемой в переопр…
M
MarselAug. 16, 2023, 7:26 p.m.
OAuth2.0 через VK, получение email Спасибо большое за помощь и простите за то что отнял время своей невнимательностью.
Evgenii Legotckoi
Evgenii LegotckoiJune 24, 2024, 8:11 p.m.
добавить qlineseries в функции Я тут. Работы оень много. Отправил его в бан.
t
tonypeachey1Nov. 15, 2024, 11:04 a.m.
google domain [url=https://google.com/]domain[/url] domain [http://www.example.com link title]

Follow us in social networks