Affinity is not determined by the CPU state and can therefore not be modified by assembly (alone). You need participation of the OS. And each OS will have a specific call to do this.
What the OS will do: the OS will have a scheduler, which is in effect a program who determines which process runs when on what processor. With setting the affinity as a user, you configure this scheduler.
And if you wouldn't have a OS (which the question seems to imply I think), then you're writing the scheduler yourself and you will have own control of the configuration and you will probably start with a global runqueue and for each processor (core) watch this runqueue, and retrieve processes to run from it.
So how does this work then? During boot, only one CPU is running. If you as the OS are ready for it, you 'boot' the other CPUs which start executing your code, and which will probably run a kind of scheduler.
For an example implementation, see Linux 2.6.29 arch/x86/kernel/smpboot.c function do_boot_cpu(), which brings a CPU online in several ways using APIC.