Compute the number of words needed?

S

sumedh.....

In a compiler there are 36bits for a word and to store a character
8bits are needed. In this to store a character two words appended.
Then for storing k characters string,how many words are needed?
 
E

Eric Sosman

sumedh..... wrote On 07/16/07 10:34,:
In a compiler there are 36bits for a word and to store a character
8bits are needed. In this to store a character two words appended.
Then for storing k characters string,how many words are needed?

What is a "word?" Before answering, observe that
it cannot be an int or long or any other C data type.
(Every C object can be viewed and manipulated as an
array of bytes; your four-and-a-half-byte "word" does
not meet that criterion.)
 
R

Richard Bos

sumedh..... said:
In a compiler there are 36bits for a word and to store a character
8bits are needed.

This is possible.
In this to store a character two words appended.

This is ungrammatical, and without meaning.
Then for storing k characters string,how many words are needed?

This is homework. Do it yourself.

Richard
 
M

Martin Ambuhl

sumedh..... said:
In a compiler there are 36bits for a word and to store a character
8bits are needed. In this to store a character two words appended.
Then for storing k characters string,how many words are needed?

I suppose this is homework, so it's probably a good thing that the
question is not stated clearly. In particular, it is underspecified.
Suppose that you have 10 bytes to recover. These can be in 9 bytes in
one conjoined 72-bit chunk + 1 more byte. Must you retrieve two words
(a 72-bit bit chunk) for that last byte, or can you do it with only one
more 36-bit word? The answer in this case could be either 3 or 4 words.

Let's consider some real-life cases.
The major 36-bit word machines I have used are in the IBM 7090/7094, DEC
PDP-6/PDP-10, and GE 635/645 families. In all of these, addressing of
bytes had to be to groups of contiguous bits within a word. That meant
that the world you seem to be concerned with did not obtain: two
contiguous 36-bit words could not be treated as one 72-word for purposes
of byte addressing. Hoe, then, does one handle bytes.

In the GE 635/645 case, a common answer was to use 9-bit bytes. This
meant one could have a 512 character character set, or 256 characters
with a bit used as a flag of some sort, or just a wasted bit per char.

In the PDP 6/PDP-10 case, where a byte pointer stored the base word
address, the size of a byte (1-36 bits) and the position of the next
byte (relative to the end of the word), the normal choices were
a) 6x6-bit bytes, inappropriate for C, but useful in situations
where case sensitivity was not needed
a') an even more restricted set of 40 characters (RAD50) which were
rarely interpreted, but rather an encoded word was created and
used in symbol tables. much as a password look up table.
b) 5x7-bit bytes, with the last bit either wasted of used as a
flag. Inappropriate for C, but capable of handling ASCII text.
c) 4x8-bit bytes, with 4 bits either wasted or used as a set of
flags. C chars can be accommodated within this scheme, but attempts
to fit this into a coherent integer type system can be tricky.
d) 4x9-bit bytes, as in the GE 635/645 case. This accommodates C chars
nicely, and because the PDP-6/PDP-10 series have instructions for
retrieving and storing either the right or left hand 18-bits of a
word separately, it is trivial to implement using the basic
instruction set for the machine a type system including
9-bit chars
18-bit shorts
36-bit int
and, if you choose to make ints and longs different lengths,
72-bit longs can be added at small cost in computation.
 
K

Kenneth Brody

sumedh..... said:
In a compiler there are 36bits for a word and to store a character
8bits are needed. In this to store a character two words appended.
Then for storing k characters string,how many words are needed?

AFAIK, it's up to the implementation.

I used a 36-bit word system (DEC KL-10), back in college, but this was
before I started programming in C. On that platform, the Fortran
compiler would store text as five 7-bit characters per 36-bit word,
with one bit wasted. (Filenames were six 6-bit characters, equivalent
to ASCII range 0x20 through 0x5F offset by 0x20.)

I don't think a C compiler could do that, as I seem to recall that
CHAR_BITS must be at least 8. However, it could store four 8-bit
characters, wasting 4 bits per word. It could also store one 8-bit
character per word, wasting 28 bits. Or, it could do anything in
between. Perhaps it would store four 9-bit chars per word?

--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody | www.hvcomputer.com | #include |
| kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------+
Don't e-mail me at: <mailto:[email protected]>
 
M

Malcolm McLean

sumedh..... said:
In a compiler there are 36bits for a word and to store a character
8bits are needed. In this to store a character two words appended.
Then for storing k characters string,how many words are needed?
It's not a good question.
In C terms, if you want 8 bit chars on a 36 bit machine, you have a real
problem. One way is to handle chars as 36 bit quantities. Most non-text
intensive mainframes would probably do this. The other way is to handle the
memory as blocks of 72 bits, or nine characters. This means that you can
have 8-bit chars, at a cost of a certain inefficiency in pointers and
integer arithmetic. Char pointers would need an address plus char offset.
The "all computer s are Turing equivalent" approach would be to handle the
memory as a flat stream of bits, and build 8-bit types on top of this. This
would have the advantage of working, but it would be horribly slow, and thus
suitable only for a toy compiler.

The number of words you need to hold a string is different for each
approach.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,434
Messages
2,571,691
Members
48,796
Latest member
Greg L.

Latest Threads

Top