Q:

Port 0x6F problem

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 ! 

A:

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!

