Assignment 2, due Sep 5Solutions
Part of
the homework for CS:2630, Fall 2019
|
a) 01011101 = (i) +93 (ii) –35 (iii) +93
b) 11100010 = (i) –30 (ii) +98 (iii) –98
c) 01101010 = (i) +106 (ii) –22 (iii) +106
d) 11110011 = (i) –13 (ii) +115 (iii) –115
e) 01111011 = (i) +123 (ii) –5 (iii) +123
Note added after seeing some of the solutions turned in: Too many students seem to have read "show it's interpretation as a 2's complement number" as requesting the number be 2's complemented. This is entirely wrong! "Interpret this in the following number system" does not mean "apply some transformation to this," it means "give this some meaning."
So, if your answer to any part of this question was a bit pattern, perhaps the 2's complement of the original bit pattern, that is simply wrong!
Some students gave bit patterns as answers to part (i) while giving decimal numbers for parts (ii) and (iii). This should have been even more obviously wrong, since parts (i), (ii) and (iii) were clearly parallel constructions, implying that their answers should have had the same form.
I ran the intcast.c program from chapter 3, which stored the integer 0x41424344 in memory and then picked it apart as characters. The output was:
p[0] = 0x44 = 'D' p[1] = 0x43 = 'C' p[2] = 0x42 = 'B' p[3] = 0x41 = 'A'
This has 0x44 as the first byte, so the machine that goes by the name fastx01.divms.uiowa.edu is a lowbyter.
Students were not required to show their work, so the above answer is overkill. The one word "lowbyter" would suffice.
const void * const a = NULL; const void * const b = &a; const void * const c = &b;
Note that const void * x declares x to be a pointer to a constant value, while void * const x declares x to be a constant-valued pointer to a variable. The above three declarations declare constant-valued pointers to constant values. That is to say, the pointers can be stored in read-only memory and the values to which they point might as well be in read-only memory as well. The fact that these are void pointers suppresses lots of type checking but plays little role in this assignment.
Note that, by default, everything you assemble with the SMAL assembler gets put in read-only memory.
A problem: Write SMAL code equivalent to the above. Note, it can be written in 3 lines of code and it would be foolish to expand it beyond 6 lines (what you get by putting labels on separate lines from the word they label). (1.0 points)
A: W NULL B: W A C: W B
The above code assumes that NULL is defined as zero somewhere, it assumes that we have not overridden the default that the SMAL assembler assembles into ROM, and it assumes that we begin on an aligned address. That's an adequate answer, but we can force two of the three assumptions by adding a bit of code:
USE "hawk.h" NULL = 0 ALIGN 4 A: W NULL B: W A C: W B