R20 = (4 * R16 + 3 * R17 - R18) / 8

.org 0
    ldi r16, 10
    ldi r17, 20
    ldi r18, 10   
    lsl r16
    lsl r16
    mov r20,r17
    lsl r20
    add r20,r17
    add r20, r16
    sub r20,r18
    asr r20
    asr r20
    asr r20
    rjmp konec

I created this program (ATMega169), to compute the expression and for the sake of accuracy I would need the operations to be performed in 16 bits. I know that there are R26 R27 registers that "act" as one, but I have no idea how to work with it. I need some study material or some kind of advice. Thank you in advance

  • 2
    \$\begingroup\$ study the ATmega datasheet ... there may also be a programming manual .... it is possible that there is s sequence of events to follow when dealing with 16 bit data transfers .... possibly operate on upper byte first and the lower byte on the next operation \$\endgroup\$ – jsotola Apr 22 at 0:38
  • \$\begingroup\$ There’s X,Y and Z which are register pairs 26:27,28:29,30:31. Mainly for pointer (indirect addressing) use. For your math, X,Y or Z won’t help you much. \$\endgroup\$ – Kartman Apr 22 at 1:18
  • \$\begingroup\$ And if I convert the registers to these x and y, then I don't get more range or any benefits? \$\endgroup\$ – Aaron7 Apr 22 at 1:27

The \$x\$ and \$y\$ and \$z\$ registers are mostly for indirect references: "These registers are 16-bit address pointers for indirect addressing of the data space." There aren't any ALU operations that support 16-bit because the ALU is an 8-bit ALU, not a 16-bit ALU. There's no escaping that requirement here.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.