Hi,
In your microcontroller you choose any two ports say port A and configure it as input and Port B and configure it as output.
There should be some slaves know and all should be in receive mode initially.
When the PC modbus application sends the packet which addressing a slave
a. for its input value, then that particular slave will change to transmission mode and reply the packet with port A input value for the query and then it will back to receive mode.
b. for its output value, then the particular slave will change its port B value based on the received value.
The packet details are available in wiki itself if you search for modbus communication. I meant the above for the packet in RTU frame format.