homework3-solution.pdf - CSE/EE 5/7385 Microcontroller...

This preview shows page 1 out of 5 pages.

Unformatted text preview: CSE/EE 5/7385 Microcontroller Architecture and Interfacing HOMEWORK 3 1. Assume the following values are signed ARM halfwords. Calculate their value in decimal (radix-­‐10) and show all your work. a) 0xFEED Negative value, magnitude is 0x0112+0x1=0x0113. In decimal the magnitude is 1×162+1×161+3×160=275. ANSWER: -­‐275 b) 0xCAFE Negative value, magnitude is 0x3501+0x1=0x3502. In decimal, the magnitude is 3×163+5×162+2×160=12,288+1,280+2=13,570. ANSWER: -­‐13,570 c) 0xACE Positive value (msb=0), magnitude is 10×162+12×161+14×160 = 2560+192+14 = 2,766. ANSWER: +2,766. d) 0xFF Positive value (msb=0), magnitude is 15×161+15×160 = 255. ANSWER: +255 2) An embedded system designer must output a one byte (1) signed magnitude value to an interface that drives a seven-­‐segment LCD display with a plus/minus sign. Answer the following questions about signed magnitude values. a) What is the maximum positive value in both decimal and hexadecimal? Hex: 0x7F Decimal: 7×161+15×160=+127 b) What is the minimum negative value in both decimal and hexadecimal? Hex: 0xFF Decimal: -­‐1× (7×161+15×160)=1127 c) What decimal value does 0x80 correspond to? Corresponds to a negative zero (which doesn’t make sense mathematically). Answer is zero (0). Would Display “-­‐0”. d) What hexadecimal value should be output to the LCD display if the decimal value 0 (zero) is to be displayed? It should be 0x00 and NOT 0x80 since 0x80 would cause the negative sign to be displayed and negative zero does not make sense. 3) Using the smallest size among (BYTE, HALFWORD, WORD), give the hexadecimal value for the following decimal values. Assume that 2’s complement is used for signed values. For full credit, show your calculations, do not merely use a calculator and give the result. a) -­‐17,635 This requires two bytes and is thus a HALFWORD. The magnitude is 0x44E3, thus the 2’s complement form becomes 0xBB1C+0x1=0xBB1D. ANSWER: HALFWORD-­‐ 0xBB1D. b) -­‐47 This a single BYTE. The magnitude is 0x2F, thus the 2’s complement is 0xD0+0x1=0xD1. ANSWER: BYTE-­‐0xD1. c) 238 This has magnitude 0xEE, however since the MSb is set, it would be interpreted as a negative value if it were stored in a BYTE and thus be incorrect. ANSWER: HALFWORD-­‐0xEE. d) -­‐128 This value has magnitude 0x80, however it must undergo 2’s complementation to indicate negation. Therefore, the magnitude is given as a HALFWORD 0x0080 and is complemented as 0xFF7F+0x1=0xFF80. ANSWER: HALFWORD-­‐0xFF80. 4) Translate the following string given between the double quotes into it’s 8-­‐bit ASCII equivalent. Give your answer as a set of hexadecimal bytes and include the spaces. “HW 3 Question” The ASCII standard requires 7-­‐bits for each character, however, it is commonly used by setting the MSb to 0 and occasionally by using the MSb as an odd or even parity bit. In this case, 8-­‐bits are requested, but no parity is mentioned, thus the MSb is reset. Using the ASCII table below, the translation is: “H”-­‐0x48, “W”-­‐0x57, Space-­‐0x20, “3”-­‐0x33, Space-­‐0x20, “Q”-­‐0x51, “u”-­‐0x75, “e”-­‐ 0x65, “s”-­‐0x73, “t”-­‐0x74, “i”-­‐0x69, “o”-­‐0x6F, “n”-­‐0x6E In block form (from left to right) ANSWER: 48 57 20 33 20 51 75 65 73 74 69 6F 6E 5) What constant would be loaded in register r0 after the following instructions execute. Give your answer in BOTH hexadecimal and decimal. Assume the constants represent signed 2’s complement values a) mov r0, #0x9D, 5 0x0000009D rotated right by 5 bits becomes 0xA8000004. Since the MSb=1, this is a negative value. The magnitude is then 0x57FFFFFB+0x1=0x57FFFFFC. Converting this magnitude to decimal: 5×167+7×166+15×165+15×164+15×163+15×162+15×161+12×160 =1,342,177,280+117,440,512+15,728,640+983,040+61,440+3,840+240+12 =1,476,395,004 ANSWER: -­‐1,476,395,004 0xA8000004 b) mov r0, #0x53, 30 0x00000053 is rotated right by 30 bits which is the same as rotating left by 32-­‐30=2 bits. Thus, the rotated value is 0x0000014C. This is a positive value since MSb=0. The magnitude is 1×163+4×162+12×160=4,096+1,024+12=5,132. ANSWER: +5,132 0x0000014C c) mvn r0, #53 The second operand is specified as a decimal value, so it must be converted to hexadecimal and then negated. The hexadecimal value is 0x00000035 and the negated form is 0xFFFFFFCA. Since the MSb=1, this is interpreted as a negative value. The magnitude of the negative value is 0x00000035+0x1=0x00000036. In decimal, this becomes 3×161+6×160=49. ANSWER: -­‐49 0xFFFFFFCA d) mvn r0, #255, 30 The second operand is given in decimal, so it must be converted to its hexadecimal form so it can be negated. 255=0x000000FF and when negated becomes 0xFFFFFF00. Rotating right by 30 bits is equivalent to rotating left by 2 bits, therefore the rotated value is 0x FFFFFF2B. Since the MSb=1, this represents a negative value. The magnitude is 0x000000D4+0x1=0x000000D5. In decimal, this magnitude is 13×161+5×160=213. ANSWER: -­‐213 0xFFFFFF2B 6) Using any combination of mov, mvn, with or without rotates, or shifts, give a single instruction that will cause the following constants to be loaded into register r1. a) 0xFF There are several correct answers. Two of these are: mov r1, 0xFF, or mvn r1, 0xFFFFFF00 ANSWER: mov r1, 0xFF b) 0xC400 There are several correct answers. One of these is: mov r1, 0xC4, 24 c) 0x7D8 There are several correct answers. One of these is: mov r1, 0xFB, 29 d) 0x17400 There are several correct answers. One of these is: mov r1, 0x5D, 20 e) 0x1980 There are several correct answers. One of these is: mov r1, 0x5D, 20 f) 0xA50000 There are several correct answers. One of these is: mov r1, 0xA5, 8 7) Give the single instruction that will load the following constants into register r0. You may ONLY use a literal pool if that is the only possible way to load the instruction. a) 0xFFFFFFFF There are several correct answers. One of these is: mvn r0, 0x0 b) 0x12340000 There are several correct answers. One of these is: ldr r0, =0x1234 c) 0xFFFFFFFE There are several correct answers. One of these is: mvn r0, 0x1 d) 0x88888888 There are several correct answers. One of these is: ldr r0, =0x88888888 8) Give the total number of bits (as a decimal, base-­‐10 number) for the following. B Your answer should be in total number of bits in the form A×2 where A is NOT a 11 factor of 2 (two). Do not use Kilo-­‐, Mega-­‐, or Giga-­‐. An example is 6 Kbits = 3×2 so A=3 and B=11. ARM word: _A=1_B=5____ 32 Mbits: _A=1_B=25_______ Byte: _A=1_B=3__ 16 GBytes: _A=1 B=37_ ARM halfword: _A=1 B=4_ 48 KBytes: __A=3_B=17___ 9) The diagram below depicts a portion of the ARM memory before the instruction executes. Assume that the processor is operating in little endian mode, is executing the sequence of instructions below, and that it DOES support unaligned accesses. mov ldr ldr ldr and and cmp cmp cmp cmp r0, r1, r2, r3, r1, r2, r2, r1, r3, r1, #0x8004 ;r0 <[r0, #-1] ;r1 <[r0] ;r2 <=0xFFFFFFFF ;r3 <r1, #0xff ;r1 <r2, #0xff ;r2 <#255 ;Instruction #255 ;Instruction r1 ;Instruction #0 ;Instruction 0x00008004 0xA1332CFF 0x332CFF00 0xFFFFFFFF 0x000000FF 0x00000000 A r2-0xff=0x=0xffffff01 B r1-0xff=0x00000000 C r3-r1=0xffffff00 D r1-0x0=0x000000ff a) Give the flag contents immediately after Instruction A executes: N = _1__ C = _0__ Z = _0__ V = _0__ b) Give the flag contents immediately after Instruction B executes: N = _0__ C = _1__ Z = _1__ V = _0__ c) Give the flag contents immediately after Instruction C executes: N = _1__ C = _1__ Z = _0__ V = _0__ d) Give the flag contents immediately after Instruction D executes: N = _0__ C = _1__ Z = _0__ V = _0__ ...
View Full Document

  • Fall '08
  • BUTLER

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern