News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

recv byte count

Started by ecube, November 29, 2007, 07:04:58 AM

Previous topic - Next topic

ecube

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?

jj2007

Either use qwords, or count kBytes...

Shantanu Gadgil

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
To ret is human, to jmp divine!

Tedd


.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
No snowflake in an avalanche feels responsible.

ecube

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?

Tedd

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.
No snowflake in an avalanche feels responsible.

ecube

that's pretty neat :) thanks for explaining it to me tedd, I never seen anyone intentionally overflow something, but if works, great :D

Tedd

That is how the instructions are designed to work :wink
You can do a similar thing for 'long' subtraction, using SUB/SBB
No snowflake in an avalanche feels responsible.