4) Suppose the memory of a computer is as follows:
Address 0x100 |
Address 0x101 |
Address 0x102 |
Address 0x103 |
12 |
34 |
56 |
78 |
What integer value is this on a big-endian computer?
5) Use a stack to evaluate the postfix expression: 6 3 * 5 3 - /
In big-endian machines, The Most Significant byte of the data is put in the lowest address
the most significat byte of given data is 78, so it goes to the lowest address, the next 3 bytes are placed in order in next 3 bytes.
So in a big-endian machine the values are placed as
Address 0x100 |
Address 0x101 |
Address 0x102 |
Address 0x103 |
78 |
56 |
34 |
12 |
2.
The expression is 6 3 * 5 3 - /
to do this we scan the expression from left to right and if the current element is a number we push it to stack , if it is an operator we pop 2 elements from stack, operate those 2 element with current operation and then push the result back to stack
first element is 6, a number so push it to stack. Stack is |6|
2nd is also a number so push it to stack.Stack is |6 3|
3rd is *,an operator to we pop 3 and 6 and push 6*3=18 to stack. Stack is |18|
next is 5, so we push it to stack. Stack is |18 5|
next we push 3 to stack. Stack is |18 5 3|
next is - so we pop 3 and 5 and store 5-3=2 to stack.Stack is |18 2|
next is / so we pop 18 and 2 and push 18/2=9 to stack .Stack is |9|
so the expression calculates to 9
Get Answers For Free
Most questions answered within 1 hours.