4. [15 points] For this problem we will focus on a hypothetical 16-bit machine (instead of 32 or 64 as we are accustomed
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am
4. [15 points] For this problem we will focus on a hypothetical 16-bit machine (instead of 32 or 64 as we are accustomed
question are as follows: • Sp-print pointer/address (in hex) • %c - print byte as ascii character • x-print int/unsigned in hex Note: If the variable passed into printf is not the same as what the format string expects, the input will be converted to the correct type before printing out. As an example, if I try to print a char using u (which is expecting an unsigned int), the char will be converted to an unsigned int first, and then the value of that unsigned int will be printed out in decimal. Consider the following portion of memory, displayed as a table as in class and in previous labs. Each table cell is a memory location, which contains a single byte, with values shown in hex, and the address of the leftmost byte on each row is shown to the left of the row. Addresses increase as we move to the right and down in the table. Address 0xc360 37 3f d5 12 Oxc364 34 12 43 01 0xc368 17 IT 94 79 0xc36c 9c 88 ba 50 (a) [1 points] What are the contents of memory location 0xc36b in binary? For each of the following code snippets, which include printf statements, write down what would be printed out. In each part, assume that p is a pointer of type void that has the value 0xc360. (b) [2 points] chara (char*)p; printf("su", *(a+5)); Output: ? (c) [2 points] char *a = (char *)p; printf("%d", *(a+2)); • Su-print unsigned int in decimal • %d-print (signed) int in decimal • $1x-print long/unsigned long in hex Output: ? (d) [2 ints] int *a = (int *)p; printf("%u", (a+3)); Output: ? Page < 6 of 10 C I ZOOM +
4. [15 points] For this problem we will focus on a hypothetical 16-bit machine (instead of 32 or 64 as we are accustomed to). This means that, for this problem, an int is 2-bytes, a long is 4-bytes, while a char still is 1-byte. Also assume that signed values are encoded using a two's-complement encoding. Recall that the printf options relevant to this