Subsections

- 3.5.2.1 __sfr (in/out to 8-bit addresses)
- 3.5.2.2 __banked __sfr (in/out to 16-bit addresses)
- 3.5.2.3 __sfr (in0/out0 to 8 bit addresses on Z180/HD64180)

## 3.5.2 Z80/Z180/eZ80 intrinsic named address spaces

###
3.5.2.1 __sfr (in/out to 8-bit addresses)

The Z80 family has separate address spaces for memory and input/output memory. I/O memory is accessed with special instructions, e.g.:

> __sfr __at(0x78) IoPort; /* define a var in I/O space at 78h called IoPort */

Writing 0x01 to this variable generates the assembly code:

> 3E 01 ld a,#0x01
> D3 78 out (_IoPort),a

###
3.5.2.2 __banked __sfr (in/out to 16-bit addresses)

The keyword __banked is used to support 16 bit addresses in I/O memory e.g.:

> __sfr __banked __at(0x123) IoPort;

Writing 0x01 to this variable generates the assembly code:

> 01 23 01 ld bc,#_IoPort
> 3E 01 ld a,#0x01
> ED 79 out (c),a

###
3.5.2.3 __sfr (in0/out0 to 8 bit addresses on Z180/HD64180)

The compiler option —portmode=180 (80) and a compiler #pragma portmode z180 (z80) is used to turn on (off) the Z180/HD64180 port addressing instructions in0/out0 instead of in/out. If you include the file z180.h this will be set automatically.