I want to log a days worth of recieved bytes via the function recv, I don't think dword will hold it, how should I approach this?
Either use qwords, or count kBytes...
I too think qwords should do ... for now :wink ( ffff ffff ffff ffff [hex] == 18,446,744,073,709,551,615 [dec])
I think that many bytes per day would be enough. (Although, "enough" is never really enough!!! :bdg )
Ok getting too philosophical ... maybe!
I think the following code might be useful:
mov eax, dwBytesDownloadedLow
mov edx, dwBytesDownloadedHigh
;============================
add eax, dwBytesReceived ;from the recv function
adc edx, 0
;============================
mov dwBytesDownloadedLow, eax
mov dwBytesDownloadedHigh, edx
Then use the 64-bit pair of High:Low to output the number in "string" or KB or MB or whatever!
HTH,
Shantanu
.data?
count_lo DWORD ?
count_hi DWORD ?
.code
:
mov eax,bytes_recvd
add count_lo,eax
adc count_hi,0
:
You could keep adding 'adc' as many times as you like, but I don't think you'll get a QWORD of bytes in a day (~ 194TB/s for 24hours!!)
..or week :lol
you said use a qword but you're examples you're still using a 2 dwords to represent a qword and just filling 1 of the dwords with the count. doesn't the defeat the purpose?
The magic part is the ADC :wink
recv gives a 32-bit count of the bytes received in that call.
You take that value and add it onto count_lo - that only requires 32 bits until the total overflows...
When an addition overflows, the carry flag is set (the maximum an addition can overflow is only one extra bit.)
Then you add-with-carry onto count_hi. If there was no bit to carry this will do nothing (count_hi+0+0), but when the carry-flag is set the extra bit will be added on (count_hi+0+1) -- which, in effect, makes count_hi:count_lo behave as the 64-bit value you want.
And you can chain together as many dwords as you want, just by following with extra adc instructions.
that's pretty neat :) thanks for explaining it to me tedd, I never seen anyone intentionally overflow something, but if works, great :D
That is how the instructions are designed to work :wink
You can do a similar thing for 'long' subtraction, using SUB/SBB