LAB 3 Due Friday, October 15, 5PM Negabinary Arithmetic Program Base -2 is one of my favorites! As with any other bases, the weight of position i is b^i, so the positions for an 8-bit negabinary number are: ... -128 64 -32 16 -8 4 -2 1 . -(1/2) 1/4 -(1/8) ... In our binary 32-bit MIPS world, the easiest thing to do on input is to separate the positive and negative parts (using a masking logical operation) and subtract them to get an internal 2s complement representation. To output a negabinary number, we can use a divide by -2 algorithm, but with adjustments to ensure that the remainder is either 0 or 1 (ie, never -1): ----------------------------------------- 37/ -2 = -18 r 1 -18/ -2 = 9 r 0 9/ -2 = -4 r 1 -4/ -2 = 2 r 0 2/ -2 = -1 r 0 -1/ -2 = 0 r -1 => -1 r 1 1/ -2 = 0 r 1 64 -32 16 -8 4 -2 1 1 1 0 0 1 0 1 37 = 1100101 ----------------------------------------- 7/ -2 = -3 r 1 -3/ -2 = 1 r -1 => 2 r 1 2/ -2 = -1 r 0 -1/ -2 = 0 r -1 => 1 r 1 1/ -2 = 0 r 1 16 -8 4 -2 1 1 1 0 1 1 7 = 11011 ----------------------------------------- Division by 2 in signed integers corresponds to rightshift with some corrections, so you can examine the bottom bit and use knowledge of the bottom bit and the iteration number (ie, even or odd (= pos or neg bit position) to determine the next dividend and the next bit. Write a program to convert between the following formats with input format specified by user. Formats: (u) unsigned binary (s) sign/mag binary (1) 1s complement (2) 2s complement (n) negabinary (d) decimal integer Use getc and putc for all the [nega]binary bases. Use geti and puti for integers. Example: : 8 : n1010 ============================================================= You may want to talk to TAs and classmates about the algorithms needed for this at the C level, or the use of specific instructions in MAL examples unrelated to this problem. Feel free to post negabinary conversions on the newsgroup to see if they're correct. Similarly, feel free to post questions about MAL syntax like how to print a string, and the like. SUBMIT: nega.mal README a. Name and email address b. Overview of your code c. Thoughts on negabinary -- -- What is the range of an n-bit negabinary number? -- How would you add 2 negabinary numbers? -- In what circumstances might negabinary be useful? d. Any other comments on MAL. Things to help get a +: - great prompts, error messages and the like - inclusion of excess notation with user-entered excess Things to that may lead to a - (but still credit): - Everything but the negabinary output - Can only handle 8-bit numbers (+ items may help move either of these to a check.) Revision: Submit 5:00 pm 10/18 program for any 1 non-decimal input to any 1 non-decimal output. Submit 5:00 pm on 10/22 the complete program.