I am stuck at a simple homework on 32bit machine read write cycle
A read from or write to memory on a 32bit machine is done at 4 byte per cycle , if I have an integer and a long double variables assigned with some values, then how many cycles does it take to开发者_如何转开发 read/write them ? Does it make any difference if I use these variables on different platforms et machines ? Thank you.
Find out how how many bytes is the integer and the long double in your case. Then use the rule of three to compute how long it takes.
On x86 32 bit sizes are as such Integer 4 bytes, long double is actually 16 bytes (at least it should be, on some arch's its 8 bytes and on others 12 bytes) and each cycle can only operate on 4 bytes at a time so Integer takes 1 cycle and long double takes 4 (3 and 2 respectively for the other sizes mentioned) cycles. On 64 bit machines with SSE instructions can do 16 bytes in one or two cycles.
There's a good question on this topic found here: long long implementation in 32 bit machine The highest rated response has insights into how they're stored, and operated upon as well.
Since I don't know what architecture you're referring to, and since it's just homework, I am tempted to say it'll take two mov
instructions to perform storing a long long integer. And thus, two cycles.
Integer = 4 byte, long double = 10 byte which means integer = 1 cycle long double = 2.5(3?) cycles.
精彩评论