Kashyap,
After one program executes n number of user instructions (set by --timer option of xsm simulator), a timer interrupt occurs.
Since you run the scheduler, execution passes to the other process (unless it is in wait state).
Since write involves no wait, during each timer interrupt, alternate switching happens between the two processes.
If the switch runs very symmetrically, then printing might happen in the order 1,2,3,4....
To break the sequence, in (only) one of the processes, just add a loop i = 1 to 100 do nothing.
You must do this after the semaphore is released, before it is acquired again.
With this, one process will acquire semaphore and print numbers at a slower rate than the other.
Hence you must expect the faster process to print several numbers from the list between two prints of the slower process.
Even after doing this, if your program prints numbers sequentially, then there is something wrong elsewhere.
Murali