pgubook-readers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Pgubook-readers] Chapter 1: Answers?


From: Graeme Stewart
Subject: [Pgubook-readers] Chapter 1: Answers?
Date: Thu, 30 Dec 2004 18:17:08 -0800

Thanks for taking the time to review my proposed answers! Go gentle on
me if I've totally missed the point, or clearly screwed something up.
:-)

Thanks,

Graeme

______________________________________

Chapter 1

Review

Know the Concepts

Describe the fetch-execute cycle.

The fetch-execute cycle is where the CPU reads an instruction from
memory, executes it, then reads the next instruction into memory,
executes it, etc, etc. The process of reading from the memory, and
executing the instruction read, is known as the fetch-execute-cycle.

What is a register? How would computation be more difficult without registers?

A register is a memory storage space used to hold data that is
currently being worked on (executed?). In a computation example the
numbers being manipulated would be held within the registers while the
computation is being performed.

Computation would be harder without registers as the CPU would
continually have to lookup the main memory space for data - thus
adding overhead and reducing performance.

How do you represent numbers larger than 255?

By using multiple bytes. 8 bits = 1 byte

1 2 4 8 16 32 64 128
0 0 0 0 0  0  0  0   = 0

1 2 4 8 16 32 64 128
1 1 1 1 1  1  1  1   = 255

Thus combining bytes (or extending bits) would give:

1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768
0 0 0 0 0  0  0   0   1   0   0    0    0    0     0     0  = 256


1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768
1 1 1 1 1  1  1   1   1   1   1    1    1    1     1     1  = 65536


How big are the registers on the machines we will be using?

Register size on x86 Linux systems we will be using are 4 bytes, or 32
bits long.  This allows for number representation between 0 and
4294967295. These are commonly described as 32bit operating systems.
64 bit operating systems can represent numbers between 0 and
18446744073709551616 in a single register.

How does a computer know how to interpret a given byte or set of bytes
of memory?

Generally it doesn't. All data is stored within memory independent of
the data type. The computer knows what to do with the different memory
locations through the registers. Without the registers to define the
actions to take with the data held within memory locations the data is
meaningless.

What are the addressing modes and what are they used for?

Immediate mode:
Initialize register, the data to initialize with is embedded in the instruction.

Register Addressing mode:
Access a register. The instruction contains the particular register to access.

Direct Addressing mode:
Access a memory location and load it into the register.

Indexed Addressing mode:
Access a memory location, offset by the index register, and index
multiplier, then load into the register.

Indirect Addressing mode:
Load the register with the memory location referenced by the reference
register! Indirect addressing mode calls an existing register, and
loads from the memory the location referenced by that register and not
the calling register.

Base Pointer Addressing mode:
As above, but with an additional offset that is added to the reference
registers address before lookup.

What does the instruction pointer do?

Points to the memory location of an instruction. Whatever is at the
memory location referenced is loaded as an instruction.

Use the Concepts

What data would you use in an employee record? How would you lay it
out in memory?

An employee record would contain: first name, last name, department, title, id. 

It would be laid out in memory thus:

Start of Record:
        Employee's first name pointer (1 word) – start of record
        Employee's last name pointer (1 word) – start of record + 4
        Employee's department pointer (1 word) – start of record + 8
        Employee's title pointer (1 word) – start of record + 12
        Employee's id pointer (1 word) – start of record + 16

Note: Title could contain multiple words. This is a pointer to the
title, not the title itself (that's stored somewhere else in memory).

If I had the pointer at the beginning of the employee record above,
and wanted to access a particular piece of data inside of it, what
addressing mode would I use?

Indexed Addressing mode.

In base pointer addressing mode, if you have a register holding the
value 3122, and an offset of 20, what address would you be trying to
access?

(20 + 3122) = 3142

In indexed addressing mode, if the base address is 6512, the index
register has a 5, and the multiplier is 4, what address would you be
trying to access?

((5*4) +6512) = 6522

In indexed addressing mode, if the base address is 123472, the index
register has a 0, and the multiplier is 4, what address would you be
trying to access?

((0*4) +123472) = 123472 

In indexed addressing mode, if the base address is 9123478, the index
register has a 20 and the multiplier is 1, what address would you be
trying to access?

((20*1) +9123478) = 9123498

Going Further

What are the minimum number of addressing modes needed for computation?

2? Not sure – Do you need a register to contain the value, and an
instruction pointer to contain the computational instruction?

Best I could find on the web:
http://www.osdata.com/topic/language/asm/address.htm#addressmodes

Why include addressing modes that aren't strictly needed?

Easier to code? Faster development?

Research and then describe how pipelining (or one of the other
complicating factors) affects the fetch-execute cycle.

Pipelining uses different hardware for the fetch-execute cycle. The
fetch is performed while the execute is being processed by a separate
hardware element. Instruction execution can be overlapped in a
pipeline.

This results in improved performance. The fetch can be occurring while
the execute is taking place, and is then ready to be executed as soon
as the cycle completes. The CPU becomes an assembly line.

http://www.nku.edu/~foxr/CSC362/NOTES03/ch5.ppt

Research and then describe the tradeoffs between fixed-length
instructions and variable-length instructions.

Fixed length makes instruction fetching predictable, which helps out
with performance and pipelining.

Variable length reduces the memory space required, but has an
additional performance overhead. Complicates code.

http://www.nku.edu/~foxr/CSC362/NOTES03/ch5.ppt




reply via email to

[Prev in Thread] Current Thread [Next in Thread]