[ Prev ] [ Index ] [ Next ]

Chapter 5

Question 1

Fill in the following table to show how the given integers are represented, assuming that 16 bits are used to store values and the machine uses two’s complement notation.

Integer Hex 4-Byte Big Endian (Hex value as seen in memory) 4-Byte Little Endian (Hex value as seen in memory))
28 1C 001C 1C00
2216 8A8 08A8 A808
-18675 -48F3 B70D 0DB7
-12 -C FFF4 F4FF
31456 7AE0 7AE0 E07A

First and foremost, I converted each integer to Hex. For the sake of time, I just used an online convert to do this. This one in particular.

Next, we can work on big and little endian. However! We must make sure to give both endians in hex signed 2's complement! The converter I linked does this for us. As you may remember, 2's complement only changes the number if its negative. Therefore, only -12 and -18675 will look different.

Now then, remember that 1-byte = 8-bits! So then, if hex consists of base-16 numbers then that means we'll need a total of 4 bits to represent a single base-16 number (24 = 16). In that case, a byte is enough to represent the decimal numbers 0-255 or 0 to FF in hex.

What you should take away here is that a single byte can hold two hex digits! This is important because big and little endian is not based on the ordering of the digits but the ordering of the bytes! That's why 1C doesn't become C1. 1C takes up a byte so when we rearrange the bytes it stays just 1C since that's a whole byte right there.

Since values are stored in 16 bits as per the question, that means we'll be storing numbers with 2 bytes which is a four digit hex number.

I believe there is an inconsistency in the table. He states that the big and little endian numbers are 4 bytes but this would require 32 bits. In that case, 00 1C should instead be 00 00 00 1C. However, he gave me a perfect score on the homework. Therefore, I believe the 4 bytes was a typo. He should have written 2 bytes.

Question 2

Exercise 11.

Convert the following expressions from infix to reverse Polish (postfix) notation.

This is rather easy to do. The main thing to note is that, when evaluating postfix, we use a stack. Postfix is fantastic because we can simply go from left to right over the expression and, with the help of a stack, evaluate it!

Everytime you encounter a number in a postfix expression, put it on the stack. Whenever you encounter an operation such as addition or division, pop the top two values off of the stack, perform the operation, and place the result back onto the stack. Continue to do this until done.

Keeping that in mind, when converting infix to postfix you need to make sure that your postfix expression evaluates correctly. Remember PEMDAS! As for the actual conversion, I personally just do it off of intuition and then double check it evaluates correctly. Perhaps there is a more algorithmic approach you could use but, for these smaller expressions, I find that intuition works fine.

1a) (8 - 6) / 2
8 6 - 2 /

2b) (2 + 3) * 8 / 10
2 3 + 8 * 10 /

3c) (5 * (4 + 3) * 2 - 6)
5 4 3 + * 2 * 6 -

Our professor suggested for 3c that I use 4  3 + 5 * 2 * 6 - instead. I still got a 100 on the homework though. They both evaluate the same.

Question 3

Exercise 17.

In a computer instruction format, the instruction length is 11 bits and the size of an address field is 4 bits. Is it possible to have:

1) 5 two-address instructions
A single address is 4 bits which gives us 24 possible values. Be that the case, two-address instructions would have 24 * 24 possible values.

With 5 two-addess instructions, we have 5 * 24 * 24 = 1280 bits.

2) 45 one-address instructions
45 * 24 = 720 bits.

3) 32 zero-address instructions
32 = 32 bits.

4) using the specified format? Justify your answer.
If the instruction length is 11 bits, then we have room for 211 = 2048 bits.
1280 + 720 + 32 = 2032 bits.
Since 2032 < 2048, we have enough room!

Following this, the question asks:
17b) Assume that a computer architect has already designed 6 two-address and 24 zero-address instructions using the instruction format above. What is the maximum number of one-address instructions that can be added to the instruction set?

To begin, let's figure out how much space we have to work with!

6 * 24 * 24 = 1536 bits.
24 = 24 bits.

1536 + 24 = 1560 bits.

So then, assuming we still have the 211 bits of space to work with, let's see what remains:
2048 - 1560 = 488 bits.

Great! so we have 488 bits of space left to make as many one-address instructions as we possibly can. So, how many can we make?

488 / 24 = 61/2 = 30.5.

So then, this means we can have up to 30 one-address instructions for 30 * 24 = 480 bits which is just under the 488 bits we have available to fill up.

Once again, the answer is that we have enough room for 30 one-address instructions.

Question 4

Exercise 22.

Perhaps the best way to start this problem off is with a screenshot:

This question is quite easy so long as you know the definition of the different modes.

Immediate:
This mode of addressing is named as such because the value to be referenced immediately follows the operation code in the instruction.

So then, since we have LOAD 500, the immediate value is just 500.
The answer is 0x500.

Direct:
For direct addressing, we call it as such for the value to be referenced is obtained by specifying its memory address directly in the instruction.

So, for LOAD 500 we merely look at address 0x500 and get the corresponding value.

The answer is 0x100.

Indirect:
This mode of addressing is like direct but with an extra hint of indirection. In this mode, the bits in the address field specify a memory address that is to be used as a pointer (remember, a pointer is just an address in memory to a value).

Therefore, LOAD 500 gives us the pointer to another address in memory 0x100. Now then, 0x100 points to the 0x100 address in memory which contains the value 0x600.

So then, 0x500 -> 0x100 -> 0x600.

The answer is 0x600.

Indexed:
This mode of address uses an index register to store an offset which is added to the operand resulting in the effective address of the data!

What do I mean by this? Well, LOAD 500 gives us 0x500. Our R1 register contains 0x200.
Now then, 0x500 + 0x200 = 0x700. Remember, R1 is the offset that add to our load instruction!

Now then, the final value that we are looking for is at address 0x700!

The answer is 0x800.