Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Construct a MIPS code programme that reads the keyboard input of 8-bit binary nu

ID: 3638082 • Letter: C

Question

Construct a MIPS code programme that reads the keyboard input of 8-bit binary number in ASCII where the only input is 0s or 1s. The code should convert the string you have read in, into a numeric value. When a string is read in, it is to store as a numeric value in memory using the ASCII mapping.

Character 0 has as ASCII value = 4810 or 0x30.
Character 1 has as ASCII value = 4910 or 0x31.

Do not worry about handling any other characters. The input should always output as 8 characters long. The program will then be outputting the value in both base 10 and base 16 representations. Assuming the value is unsigned, the sample output should appear as follows:

Enter number (1 or 0): 10101111
The number in base 16 : 0xAF
The number in base 10 : 175

Use logical operators, shifts and branching to successfully implement this program.

Explanation / Answer

The purpose of memory is to store groups of bits, and deliver them (to the processor for loading into registers) upon demand. Most present-day computers store information in multiples of 8 bits, called a byte (or octet). Most also assign a numeric address to each byte. This is convenient because characters can be stored in bytes. Memory addresses are 32-bit numbers, ranging from 0x00000000 to 0xFFFFFFFF. This is a large amount of memory, most computers do not have actual memory for all of this "address space." Memory can hold both program instructions and data. One function of the operating system is to assign blocks of memory for the instructions and data of each process (running program). Another thing a good operating system does is to allow many processes to run concurrently on the computer. The SPIM simulator always assigns your program to these fixed, even numbered locations, for your convenience: 0x00400000 - Text segment - program instructions 0x10000000 - Data segment 0x7FFFFFFF, and decreasing addresses - Stack segment A word generally means the number of bits that can be transferred at one time on the data bus, and stored in a register. In the case of MIPS, a word is 32 bits, that is, 4 bytes. Words are always stored in consecutive bytes, starting with an address that is divisible by 4. Caution: other processors, other definitions. Some people refer to 16 bits as a word, to others it may mean 64 bits. Storage order of words How should one store a word (say, a register holding a number) in 4 bytes? There are two equally valid schemes: starting with the lowest numbered byte, Little Endian: Store the little end of the number (least significant bits) first, or Big Endian: Store the big end of the number first. (These terms come from Gulliver's Travels by Jonathan Swift, in which two parties are at war over whether hard-boiled eggs should be opened at the little end or the big end of the egg.) MIPS is little-endian. One result of this is that character data appear to be stored "backwards" within words. Here is a representation of part of memory, storing the characters "Help" (0x706c6548) and then the number 32766 (0x00007ffe).