0

When I disassemble an Arduino IDE created pjoject I see in the created code ("disassembled code actually"), the it uses IN / OUT instruction on port 0X6F.

Like this (part of disassembled list):

00E3     4FFF                SBCI      R31,0XFF                 ; .O
00E4     91A5                LPM       R26,Z+                   ; ..
00E5     91B4                LPM       R27,Z                    ; ..
00E6     B79F                IN        R25,0X6F                 ; ..
00E7     94F8                CLI                                ; ..
00E8     1161                CPSE      R22,R1                   ; a.
00E9     C004                RJMP      L00EE                    ; ..

00EA     918C                LD        R24,X                    ; ..
00EB     9530                COM       R19                      ; 0.
00EC     2338                AND       R19,R24                  ; 8#
00ED     C002                RJMP      L00F0                    ; ..

00EE     91EC      L00EE:    LD        R30,X                    ; ..
00EF     2B3E                OR        R19,R30                  ; >+
00F0     933C      L00F0:    ST        X,R19                    ; <.
00F1     BF9F                OUT       0X6F,R25                 ; ..
00F2     9508      L00F2:    RET   

Anyway the ATMEGA328 Datasheet says that port 0x6F is memorymapped and as such should be accessed through LDS/STS instructions. This problem really confuses me. Can anyone give me an explanation ?? Thanks !

2
  • What is the original C/C++ code? Commented May 1, 2019 at 19:23
  • 1
    avr-objdump disassembles those bytes to in r25, 0x3f and out 0x3f, r25, which is consistent with Mikael Patel's answer. It looks like your disassembler is broken. Commented May 1, 2019 at 19:55

1 Answer 1

4

The AVR operation code for the IN instruction is:

Loads data from the I/O Space (Ports, Timers, Configuration Registers, etc.) into register Rd in the Register File.

Operation:
(i) Rd ← I/O(A)
Syntax: Operands: Program Counter:
(i) IN Rd,A 0 ≤ d ≤ 31, 0 ≤ A ≤ 63, PC ← PC + 1
16-bit Opcode: 1011 0AAd dddd AAAA

The disassemble of the operation code B79F (hex) = 1011 0111 1001 1111 (bin) is IN R25,$3F which is actually SREG.

The block of code with the IN, CLI and OUT instruction is a critical section where the flags in SREG are saved, interrupts are turned off, and later the SREG is restored.

Cheers!

2
  • Thansk a lot . I'll check with the Disasm creator, tell him the problem and recompile when I get a new version.. Hope that solves the problem. Anyway many, many thanks for the constructive answers. Commented May 1, 2019 at 20:37
  • HI: (time 22:23 European time): Called him, told him about the error. He examined. Corrected it. Returned a new version. I ran it. Disassembled the file (which give the above list), io-ports are now correct (all in range 0x00 - 0x6F) Thank for a valuable help. KSH Commented May 1, 2019 at 21:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.