Why "shorthand" instructions for lsr, rol, tst and

Go To Last Post
6 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi folks:
I have not ever seen this question asked so I am asking.

This is a curiosity question.

I have noticed that the resulting assembly instructions that are emitted by avr-gcc will substitute the add, adc, and or eor instructions for the original lsl, rol, tst and clr instructions.

In reviewing the avr.h header for binutils 2.4, I see that those instructions are defined as:

   /* Shorthand for {eor,add,adc,and} r,r above.  */
AVR_INSN (clr,  "r=r", "001001rdddddrrrr", 1, AVR_ISA_1200, 0x2400)
AVR_INSN (lsl,  "r=r", "000011rdddddrrrr", 1, AVR_ISA_1200, 0x0c00)
AVR_INSN (rol,  "r=r", "000111rdddddrrrr", 1, AVR_ISA_1200, 0x1c00)
AVR_INSN (tst,  "r=r", "001000rdddddrrrr", 1, AVR_ISA_1200, 0x2000)

Is there any particular reason why the original instructions are not used? The substitutions still use 1 clock cycle and to the best of my knowledge, the flags affected are the same.

Thank you in advance.

Peace and blessings,
Scott

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

They will not be substituted at any time, only in specific circumstances. e.g. ADD Rd, Rs may be replaced with LSL Rd when Rd and Rs are the same register. The functionality is the same since adding a register with itself is the same as multiplying the register by 2 which is the same as LSL. If you look at the Instruction Set pdf you see that LSL has the same opcode value as ADD with Rd == Rs. The same for ADC => ROL and EOR => CLR. AND => TST may happen when the result of the AND is not used and only SREG flags are tested. If you run a binary file through a disassembler you may find the opposite. Something that was originally LSL might be read back as ADD.

Regards,
Steve A.

The Board helps those that help themselves.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi Koschi:
Thank you for the response.

I get that the function is the same between the instructions. I had missed that the OPCODE was the same for each.

So this originates with ATMEL from the very forst AT90S1200 then ... I suppose the instructions in question were referenced in the assembly language guide to make it easier on programmers?

I've never seen avr-gcc substitute "clr r0" for "eor r0,r0" but I have seen it in reverse. Same with "lsl r0", etc.

Thanks again.

Peace and blessings,
Scott

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If you hunt around here you'll find a list I produced that reduces Atmel's claimed "136 powerful instruction" (or whatever the number is at the top of each AVR datasheet) to the actual 76 (I think it was) unique instructions. They use a lot or synonyms. I guess CLR Rn is more descriptive than EOR Rn, Rn and so on.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

These are the ones that I know:

Quote:
LSL: Assembler automatically inserts ADD with Rd == Rr
ROL: Assembler automatically inserts ADC with Rd == Rr
TST: Assembler automatically inserts AND with Rd == Rr
CLR: Assembler automatically inserts EOR with Rd == Rr
SBR: Assembler automatically replaces SBR with ORI
CBR: Assembler automatically replaces with ANDI with K complemented
SEC: Assembler inserts BSET, with (sss = 000)
SEZ: Assembler inserts BSET, with (sss = 001)
SEN: Assembler inserts BSET, with (sss = 010)
SEV: Assembler inserts BSET, with (sss = 011)
SES: Assembler inserts BSET, with (sss = 100)
SEH: Assembler inserts BSET, with (sss = 101)
SET: Assembler inserts BSET, with (sss = 110)
SEI: Assembler inserts BSET, with (sss = 111)
CLC: Assembler inserts BCLR, with (sss = 000)
CLZ: Assembler inserts BCLR, with (sss = 001)
CLN: Assembler inserts BCLR, with (sss = 010)
CLV: Assembler inserts BCLR, with (sss = 011)
CLS: Assembler inserts BCLR, with (sss = 100)
CLH: Assembler inserts BCLR, with (sss = 101)
CLT: Assembler inserts BCLR, with (sss = 110)
CLI: Assembler inserts BCLR, with (sss = 111)
SER: Assember automatically inserts LDI with KKKKKKKK = 11111111
BRCS, BRLO: Assembler automatically inserts BRBS, with (sss = 000)
BREQ: Assembler automatically inserts BRBS, with (sss = 001)
BRMI: Assembler automatically inserts BRBS, with (sss = 010)
BRVS: Assembler automatically inserts BRBS, with (sss = 011)
BRLT: Assembler automatically inserts BRBS, with (sss = 100)
BRHS: Assembler automatically inserts BRBS, with (sss = 101)
BRTS: Assembler automatically inserts BRBS, with (sss = 110)
BRIE: Assembler automatically inserts BRBS, with (sss = 111)
BRCC, BRSH: Assembler automatically inserts BRBC, with (sss = 000)
BRNE: Assembler automatically inserts BRBC, with (sss = 001)
BRPL: Assembler automatically inserts BRBC, with (sss = 010)
BRVC: Assembler automatically inserts BRBC, with (sss = 011)
BRGE: Assembler automatically inserts BRBC, with (sss = 100)
BRHC: Assembler automatically inserts BRBC, with (sss = 101)
BRTC: Assembler automatically inserts BRBC, with (sss = 110)
BRID: Assembler automatically inserts BRBC, with (sss = 111)

Regards,
Steve A.

The Board helps those that help themselves.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

My list here:

https://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&p=911951...

'=' denotes synonym (looks very close to Steve's list).