Question 1: Good versions: bgt $t0,122,NL bgt $t0,96,LC (or bge $t0,97,LC) bgt $t0,90,NL blt $t0,65,NL or blt $t0,65,NL bgt $t0,122,NL bge $t0,97,LC bgt $t0,90,NL -2 Used branch that tests wrong condition, e.g. bgt $t0,97,LC (Code 97 IS a letter). -2 Incorrect assembler notation, as in bgt R[$t0],122,NL Question 2a: lb $t0, char($t1) or 0x24598003, preferably with an explanation that 2=opcode for lb, 4=destination register $t0 5= A register is $t1 18003 = address of char. High order digit should be changed to "9", to set I bit I allowed them to use different register numbers for $t0 and $t1 than those assigned by the assembler, since some people didn't have the mymipsasm doucmentation with them. But NOT register 0!! -1 Deciding that $t0 or $t1 can be assigned to register 0 -2 Forgetting to include the "5" for the A register in the hex version -1 and $t0,$t0, 0xF (Value should be 0xff) If this same mistake appears in 2b, take off only once for both similar mistakes. (The and instruction is not needed -- lb on MYMIPS is loads an UNSIGNED byte.) -2 More than 4 instructions -4 Attempting to negate byte that looks negative after being loaded (Don't also take credit for program too long) -5 Generated hex version of MYMIPS instruction, but did not string fields together into 8 hex digits, or write the "and" instruction -2 Code changes $t1 -2 Uses lw $t0,char($t1) -- doesn't work if address not word-aligned *-5 more, if fails to try to zero bits 31-9. Question 2b: They were told they could use ANY register, not strictly $at, for the intermediate result. Good Version: lui $at,1 (or lui $at, 0x0001) ori $at,$at,$at,0x8003 add $at,$at,$t1 lbu $t0,0($at) -2 Used "immediate" opcodes inappropriately -2 Used "non-immediate" opcodes inappropriately e.g lw, instead of la or li -3 Constructed target address incorrectly, e.g.: lui $t3, 0x1800 ori $t3, $t3, 0x3000 -3 Failed to load the byte from memory into register (no lb $t1, 0($t?)) -10 Completely confused use of instructions -10 Claimed "lb is not a pseudo-instruction" -10 Uses psuedo instructions. -5 Uses LW or LB (without later anding with 0xFF) instead of LBU. -3 Fails to include the add of $t1 when calculating the address to load from. Question 3a+b: If the same error is committed on both parts, take off only once However, count off separately for eachunrelated arithmetic error -- this carelessness should be discouraged. 0.75 = 0.11(binary) = 1.1 * 2**(-1) S=0 (number is >= 0) E-127=-1, so E=126 = 01111110 binary 8 bits M=100...0 (drop the "1." from the "1.1" (significand) 0 01111110 10000..000 0011 1111 0100 0000 0000 0000 0000 0000 (binary, spaced intohex digits) 3 F 4 0 0 0 0 0 -2.25 (S=1, since number < 0). 2.25 = 10.01 binary = 2**1 * 1.001 E-127=1, so E=128 = 10000000. M=00100000..000 1 10000000 001000...00 1100 0000 0001 0000 0000 0000 0000 0000 C 0 1 0 0 0 0 0 -3 Converted 0.75 to 1.1(binary) * 2**1, then used E field value of 127+1=128. Indicates confusion about the logic behind floating point representation -- Surely the result of the arithmetic should equal the original number. -3 Converted binary digits to hex incorrectly -1 Copying error -- 10000000 copied into answer as x100 0000 xxx -5 Did not normalize the number first Question 4: Good version -- Any working code is acceptable int A, B, C; // not needed int M1=-1, Zero=0; //Can be assumed int T; // Can be assumed SUB(C,Zero,-1); // Set C to 1 ADD(T,A,A); ADD(T,T,T); // Bit 29 now high order BLTZ(T,TestB); BLTZ(M1,No); TestB: ADD(T,B,B); ADD(T,T,T); BLTZ(T,Done); No: SUB(C,C,C); // Set C to zero if one of the bits is 0 Done: -1 Changed either A or B or both -1 Used a constant as the SECOND operand of ADD or SUB, or the FIRST operand of BLTZ or BNZ e.g. ADD(A,0,0), or BLTZ(-1,L1) -1 Puts 2 instead of 1 into C -0 Using XIT() to exit the program, even though it doesn't. Go ahead and allow this. Through ineffective flow control, C gets either 0 or 1 regardless of what happens. -2, if it could be fixed by adding a single BLTZ(-1,...); Take off more if the error seems more serious -- logic error. -5, maybe. Question 5: Good version: .globl main .data .align 2 A: .word 0 B: .word 0 C: .word 0 .text .align 2 main: lw $t0,A lw $t1,B and $t0,$t0,$t1 srl $t0,$t0,29 and $t0,$t0,1 sw $t0,C jr $ra .end +1 Design uses the AND operation in a reasonable way +1 Design uses shifts well, preferably using only 1 -1 Included useless loads of C into register (Don't count these, when counting code length) -1 Does not preserve contents of one or more $s registers, or $ra or $sp or ... -1 Omits one or both .align 2 commands -1 Omits the .data or .text directive or both -2 Omits the definition of any label, including A, B, and C. (deduct only once) -2 Omits or misuses the jr $ra (Accept "syscall exit", if coded as: li $v0,10 syscall ) -3 Bug in nearly correct code, like failing to store a value into C under some condition -1 Omits the main: label -1 Uses wrong shift count. Should be 29, to get rid of bits 0-28. -1 Misplaces the .end, so statements of the program follow it. -2 Code fails to work, because uses "bgtz" to test if bit 31 == 0. -1 Code longer than 12 instructions -- it can be done in 7, incl jr $ra -2 Uses instruction like sw 1,C to store 1 into C (sw 0,C is OK) (I'll accept omission of .globl main, and of .end, since SPIM does) Through ineffective flow control, C gets either 0 or 1 regardless of what happens. -2, if it could be fixed by adding a single BLTZ(-1,...); Take off more if the error seems more serious -- logic error. -5, maybe. -2 to -20 Judgement call for code that doesn't work. Reserve the -20 for complete garbage code, scale down depending on how serious you think the error is. I regard conceptual errors about how the machine works, and logical errors on the algorithm as serious, maybe worth -10; misunderstandings about how an instruction works, like lbu vs lb, as less serious, maybe worth -5. -2 Never stores into C -2 Uses .space 32 to reserve space for each int variable. -3 Tries to read the data using syscall 5 -5 shifts A and B right 29, then tests result for 0, assuming that all other bits are 0. -5 Combines tests of B29 and A29 incorrectly