Luke Kraus lek81@pitt.edu
This project was used to take some input from the user and to write the MIPS assembly instruction and machine code depending on their input. I broke the project into three different sections. The first section was to get the input from the user. I wrote out all the strings to prompt the user for input and read their values in and moved them into their corrosponding $t register (ex. first input $t1, seocond $t2, ect.) The second part was to print out the MIPS assembly code. I called a function "branches" which compared the users input against the 9 numbers. Depending on what they entered it would branch off to the correct instruction. I wrote the functions individually. The approach I took was to first check the next line number and if it required the Line number to be displayed to display it. Next I printed out the assembly instruction. Next were the registers, which I used a register to keep track of which registers were being used. So if the first register that needed to printed was $t2 i would add two to the register counter and compare it to the numbers and print out the register. Than I would need to remove one from it (this was because for addi $t2, $t1, 100)to print the second register. If it required three registers I would do the same thing, just adjusting the register counter as needed. I did the same thing for the Line number and Immediate counter. I assigned a register to these and it would just check it against some number and then it would print out the correct immediate or line numner. The final part was to print out the hex representation of the machine code. This was very involved. To do this I created two buffers. On buffer was the binary buffer and the other was the hex buffer. The binary buffer is where I printed the binary to. So I went through each operation and set its opcode in the first 6 values. Than I would move the address pointer to the correct spot and print the registers to the binary stream and then move it again if a immediate was printed. After the 32bit binary was loaded into the binary buffer I created a function to transfer the binary to hex. I read in 4 bits at a time and looked at the first bit. IF this bit was 48 (0 ascii) than I moved on, but if it was 49 (1 ascii) I added 8 to the counter. I checked the next 3 bits following the same logic. This gave me the hex value of the first 4 bits. So I wrote this to the hex buffer and moved the address pointer over 1 than repeated the process till I checked all of the 4bit sequences. I then had the machine code in the hex buffer so I just printed it out. Finally, I went back through the program and formatted it to make sure that it looked the same as the sample output. I was not able to find any bugs in my program as it matched the sample output exactally. I also tried some other values that were not printed on the sample output and they correctly displayed for me.