How do you access more memory (above the 1MB) in DOS if the [640KB](https://en.wikipedia.org/wiki/Conventional_memory) of conventional memory are not enough?

I have read a lot about this, but I couldn't figure out how to do this in actual code. Is there an API for this (like [HIMEM.SYS](https://en.wikipedia.org/wiki/HIMEM.SYS)), or can I code it myself? Any answer is fine, whether it uses the XMS or the EMS standard or manually written code. From what I read, though, EMS requires specialized hardware, which is not very convenient.

If you can, please also explain if there are any differences between doing it on an [Intel 80286](https://en.wikipedia.org/wiki/Intel_80286) or an [Intel 80386](https://en.wikipedia.org/wiki/Intel_80386). Does it necessarily require switching to [protected mode](https://en.wikipedia.org/wiki/Protected_mode)?