I'm rolling off my own TCP/IP stack. The network byte ordering is different from the PC byte ordering, and I see this when I run tests on my own stack with linux tcpdump.
If I take a 16-bit network value and I want to increment the original value by 1, I could use this kind of code (in all cases, networkvalue is declared as a double-word):
mov AX,[CS:networkvalue]
xchg AL,AH
inc AX
xchg AL,AH
mov [CS:networkvalue],AX
But how would I do it with a 32-bit value successfully? Because this kind of code:
mov EAX,[CS:networkvalue]
inc EAX
mov [CS:networkvalue],EAX
does not work properly.
The reason why I ask this is because I want to take the sequence number of a remote packet, increment it then send it out as an acknowledgement and both values are 32-bit.
The only thing I can come up with off the top of my head is this, but I might be off:
mov BL,[CS:networkvalue]
mov BH,[CS:networkvalue+1]
mov CL,[CS:networkvalue+2]
mov CH,[CS:networkvalue+3]
mov [CS:networkvalue],CH
mov [CS:networkvalue+1],CL
mov [CS:networkvalue+2],BH
mov [CS:networkvalue+3],BL
mov EAX,[CS:networkvalue]
inc EAX
mov [CS:networkvalue],EAX
mov BL,[CS:networkvalue]
mov BH,[CS:networkvalue+1]
mov CL,[CS:networkvalue+2]
mov CH,[CS:networkvalue+3]
mov [CS:networkvalue],CH
mov [CS:networkvalue+1],CL
mov [CS:networkvalue+2],BH
mov [CS:networkvalue+3],BL
Any idea how I can solve my issue?
And I would prefer an answer that would work with older (say 386' or 486' model PC's) because I'm making networking software for an older popular game.