-2

I need to multiply two unsigned numbers(in this case the numbers are 234 and 24), however I have no idea how to do it. I need to multiply them without using registers R16, R17 and R18(the registers are present in the code bellow). I tried to multiply them by just typing mul 234, 24, however ATMEL studios tells me that the numbers are invalid registers. The microcontroller is ATmega8.

;
; Vjezba_1.asm
;
; Created: 4/29/2020 8:57:18 PM
; Author : Ilario
;
//1. zad
.DEF rez = R18
.DEF op1 = R17
.DEF op2 = R16
//2. zad
ldi op1, 67
ldi op2, 76
ldi rez, 0
//3. zad
Inc op1
add rez, op1
add rez, op2
//4. zad
dec rez
sub rez, op2
//5. zad
add  0x0F1AC2, 0xA2320F
//6. zad
mul 234, 24

start:
  inc r16
  rjmp start
ile123
  • 57
  • 1
  • 6
  • How about you use `ldi` to load the numbers into two register and then use `mul` to multiply then? Have you checked the AVR instruction set manual to make sure you know how `ldi` and `mul` work and what kind of operands they take? – David Grayson May 02 '20 at 19:07
  • After some time I have managed ti figure it out how to do it thanks to your suggestion. – ile123 May 02 '20 at 19:17

1 Answers1

0
.DEF varA = R20
.DEF varB = R21
 ldi varA, 245
 ldi varB, 24
 mul R20, R21
 ldi rezo2, 0
 ldi rezo1, 0
 add rezo1, R1
 add rezo2, R0
ile123
  • 57
  • 1
  • 6