4

Consider a computer that has a byte addressable memory organized in 32 bit words according to the big endian scheme. A program reads ASCII characters entered at a keyboard and stores them in successive byte locations, starting at location 1000. Show the contents of two memory words at locations 1000 and 1004 after the name "johnson" has been entered.

Stephan202
  • 59,965
  • 13
  • 127
  • 133
  • 4
    While transcribing your homework question, you mis-spelled ASCII – pavium Oct 13 '09 at 11:37
  • 3
    No, no, that's the American Standard Code for Information Interchange Indentation. You know, the stuff people fight holy wars over, like tabs or spaces :-) – Joey Oct 13 '09 at 11:39

4 Answers4

3

Just convert each letter to hex using a handy ASCII table, and add them to memory sequentially. This renders easily as gorgeous ASCII graphics:

+------+--+--+--+--+
|0x1000|6A|6F|68|6E|
+------+--+--+--+--+

The last four bytes were left out, this is homework after all.

unwind
  • 391,730
  • 64
  • 469
  • 606
  • 1
    Your nice ASCII art painfully reminds me of my hours of dabbling with J which renders boxed values like this (http://www.jsoftware.com/help/dictionary/d010.htm). – Joey Oct 13 '09 at 11:52
  • @Johannes: Indeed. Reminds me of an answer of my own: http://stackoverflow.com/questions/897366/how-do-pointer-to-pointers-work-in-c/897414#897414 – Stephan202 Oct 13 '09 at 12:02
0

There is no such thing as endianes for storing a single byte (such as an ASCII character). Endianes only comes into play when a value is represented as multiple bytes. So for example, storing a sequence of bytes is the same in little- and big-endian, only the representation of the bytes are different. For example, take the number 3 735 928 559 (or 0xdeadbeef in hex notation) and store that as a 32-bit word (e.g., an int) at memory location 1000 will give:

ADR: 1000 1001 1002 1004
BE: de ad be ef
LE: ef be ad de

-2

I think than words will have next values:

1000: 0x6a6f686e
1004: 0x736f6e00

'Cause of name contains only 7 characters, eight character is unknown, so last position (00) may have any value.

-2
1000: 0x6a 6f 68 6e
         j  o  h  n
1004: 0x73 6f 63 00
        s  o  n  NULL
General Grievance
  • 4,555
  • 31
  • 31
  • 45
  • 3
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Apr 15 '22 at 11:28