Saturday, May 22, 2010

Computer Science question (Hex--Define Byte and Define Word)?

I am studying for an exam and the one thing I am confused on is the following:





Show contents, in hex, of following memory locations. Make sure to draw as many bytes as each will generate. Show contents in byte-swapped order where applicable.





Ok here are the three questions and my answers.








a) Flda dw 1659-----answer: 067B---%26gt;swapped 7B06





b)Fldb db 'House'---answer: 48 6F 75 73 65





c) Mydupe db 2 dup(77)---answer: 4D 4D





If I am wrong can you explain how you got the answer. Thanks.

Computer Science question (Hex--Define Byte and Define Word)?
1) The answer is correct...on some CPUs.


1659 decimal is 067B in hex. However, some CPUs like the Intel x86s and the 6502 CPU store numbers in memory backwards (lower byte/word/dword before upper byte/word/dword). For example, a Pentium will store the 32 bit number FAEA 0022 as 2200 EAFA.


Therefore, the word 067B on an Intel x86 CPU is stored in memory as 7B06.





2) The answer is correct. Since you are allocating bytes, the bytes are stored in memory as is. (If you allocated a string in C/C++, there would be a zero tacked onto the end of the string. C/C++ strings are always zero-terminated.)





3) The 3rd answer is correct. In English it translates to "Mydupe equals the value of decimal 77, which is duplicated twice." This means that Mydupe is essentially a small byte array of 2 bytes, and each byte contains the value of 77.


Other examples:





Uninitialized memory block of 1024 bytes:


Mydupe db 1024 dup (?)





Initialized memory block with the value of char '*'


Mydupe db 1024 dup ('*')


No comments:

Post a Comment