Click here to Skip to main content
15,887,027 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
We assume that the values of the variables A, B, C, D, F are located in the central memory of the computer. All variables are 4 byte integers. Opcodes are 1 byte, except push/pop operations which are 2 bits. Memory addressing is 16 bits and register addressing is 5 bits. Calculate code density and memory traffic for the following code :

a)
ASM
PUSH D
PUSH B
PUSH A
ADD
PUSH C
MUL
DIV
POP F

b)
ASM
LOAD A
ADD B
STORE T
LOAD C
DIV D
MUL T
STORE F


What I have tried:

For case , i've made some calculations:
Code Density for A) = number of push/pop* 2bit + number.ALU instructions * 8 bit + number of push/pop * 16 bit = 5*2+ 3*8 + 5 *16 = 10+24+80=114 bit

Code density for B) = Total nuber of instructions * 8bit + number of Load/Store * 16 bit = 7*8 + 4*16 =56+64 =120 bit

Memorty traffic Case A = ?????
Memory Traffic Case B = ????

I don't know if these calculations are ok , and what about Memory traffic ?
Posted
Updated 13-Jan-24 2:24am
v2
Comments
Richard MacCutchan 13-Jan-24 4:15am    
Every instruction that addresses a memory location (including PUSH and POP) adds to memory traffic.

While we are more than willing to help those that are stuck, that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us to do it all for you.

So we need you to do the work, and we will help you when you get stuck. That doesn't mean we will give you a step by step solution you can hand in!
Start by explaining where you are at the moment, and what the next step in the process is. Then tell us what you have tried to get that next step working, and what happened when you did.

And what little calculation you have done so far seem very suspect, or the definition of your virtual machine is (again, we mentioned this in both of your other questions) is needed to even begin working out any actual numbers: either your registers are all different sizes, or you made up the numbers ...
With your question history, you seem to be trying to get others to do you homework for you by doing a slapdash job and hoping for a complete result to hand in as your own work...

If you are having problems getting started at all, then this may help: How to Write Code to Solve a Problem, A Beginner's Guide[^]
 
Share this answer
 
Comments
desanti 13-Jan-24 19:31pm    
Yes , you've found it. Someone will pay me 1 million dollars only to solve this problem. Please give me your bank account so we divide this sum , and after show me your solution for this problem.
OriginalGriff 14-Jan-24 2:13am    
"Divide"? What have you done that makes you think you deserve any of the money?
desanti 14-Jan-24 13:06pm    
At least i've tried to calculate code Density , you only have talked ans talked useless moral words without giving at least an idea about the solution of the problem. Maybe you should change your profession , try to make the psychologist , you can help people.
Quote:
Opcodes are 1 byte, except push/pop operations which are 2 bits.

The increase in memory traffic caused by an instruction that addresses a memory location depends on the size of the memory address. In the task, it was specified that the memory addressing is 16 bits. This means that each memory address is 16 bits or 2 bytes in size. Consequently, every instruction that addresses a memory location (e.g. LOAD, STORE, PUSH, POP) would require 2 bytes for the memory address in addition to the opcode. This applies regardless of the size of the opcode itself. Coding opcodes with 2 bits sounds strange, is there a typing error?

//edit:
As all variables are 4 bytes in size, this also affects the calculation of memory traffic for some commands that use memory addresses (such as LOAD, STORE, PUSH, POP). Each access to a variable requires an additional 4 bytes for the value of the variable.

Example:
PUSH D (2 bytes for memory address + 4 bytes for the value + x bytes for opcode)

Various architecture data are missing, if the data bus does not manage 4 bytes together, several accesses would be necessary.
If OriginalGriff's comment applies with the stack-based virtual machine, this will probably also result in higher values.
 
Share this answer
 
v2
Comments
CPallini 13-Jan-24 9:19am    
5.
OriginalGriff 13-Jan-24 10:39am    
And more, I suspect - the first code looks like a stack based virtual machine (and his previous questions referred to one) so all operations that require two operands will require 3 * 16 bit accesses: two POPs and a PUSH for the results.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900