Cseeee 230 computer organization and assembly

This preview shows page 22 - 24 out of 52 pages.

CSE/EEE 230 Computer Organization and Assembly Language Chapter 2 Notes 2.5.4.4 sw $v1, -48($sp) [Ref: MIPS32 Vol II-A, p. 281] Syntax: sw rt, offset(rs) sw op field: 101011 rs: $sp = $29 = 11101 rt: $v1 = $3 = 00011 imm: 1111_1111_1101_0000 Encoding: 101011 11101 00011 1111111111010000 = 0xAFA3FFD0 op rs rt imm 2.5.5 Example Instruction Decodings [Ref: MIPS Vol II-A, Appendix A, Tables A.2 and A.3] Decoding is the process of converting a binary ma- chine language instruction to the equivalent assembly language instruction. A disassembler is a program that will perform decoding. 2.5.5.1 0x0232_4027 Write 0x0232_4027 in binary: 000000 10 0011 0010 0100 0000 0010 0111 . Since the op field is 000000 we know this is an R-format instruction. Refer to SPECIAL table A.3 for the funct field, which is in bits 5:0: funct: 100111 = NOR The encoding of the NOR instruction can be found on p. 223. Syntax: nor rd, rs, rt Encoding: 000000 10001 10010 01000 00000 100111 op rs rt rd shamt funct rs: 10001 = $17 = $s1 rt: 10010 = $18 = $s2 rd: 01000 = $8 = $t0 Instruction: nor $t0, $s1, $s2 2.5.5.2 0x001D_58C0 Write 0x001D_58C0 in binary: 000000 00 0001 1101 0101 1000 1100 0000 . Since the op field is 000000 we know this is an R-format instruction. Refer to SPECIAL table A.3 for the funct field, which is in bits 5:0: funct: 000000 = SLL The encoding of the SLL instruction can be found on p. 265. Syntax: sll rd, rt, shamt Encoding: 000000 00000 11101 01011 00011 000000 op rs rt rd shamt funct rs: unused rt: 11101 = $29 = $sp rd: 01011 = $11 = $t3 shamt: 00011 = 3 Instruction: sll $t3, $sp, 3 (c) Kevin R. Burger :: Computer Science & Engineering :: Arizona State University Page 22
CSE/EEE 230 Computer Organization and Assembly Language Chapter 2 Notes 2.6 Instructions for Making Decisions [Ref: Textbook §2.6] To implement HLL if statements and loops requires instructions which perform the re- lational operations ( < , > , , , == , and != ) and based on the result of the comparison, execute one sequence of instructions or a different sequence. 2.6.1 MIPS Jump Instruction j label # PC ← label A j instruction is a form of unconditional branch , i.e., we always jump to label and start executing the in- structions there. This is equivalent to a HLL goto statement . 2.6.2 MIPS Branch Equal Instruction beq $src1, $src2, label # If $src1 == $src2 then PC ← label else PC ← PC + 4 A beq instruction is a form of conditional branch , i.e., we only start executing the instructions at label if the values in $src1 and $src2 are the same. In this case, we say that we "take" the branch. 2.6.3 MIPS Branch Not Equal Instruction bne $src1, $src2, label # If $src1 != $src2 then PC ← label else PC ← PC + 4 We take the branch if $src1 does not equal $src2. 2.6.4 MIPS Branching Pseudoinstructions [Ref: MIPS32 Vol II-A p. 267] Several of the MIPS branching instructions are actually implemented as pseu- doinstructions using beq , bne , and the slt instruction: slt $dst, $src1, $src2 # If $src1 < $src2 then $dst ← 1 else $dst ← 0 Branch if Greater Than: bgt $src1, $src2, label Operation: if $src1 > $src2 PC ← label else PC ← PC + 4 Implemented as: slt $at, $src2, $src1 bne $at, $zero, label Branch if Less Than: blt $src1, $src2, label Operation: if $src1 < $src2 PC ← label else PC ← PC + 4 Implemented as: slt $at, $src1, $src2 bne $at, $zero, label Branch if Greater Than or Equal: bge $src1, $src2, label Operation: if $src1 $src2 PC ← label else PC ← PC + 4 Implemented as: slt $at, $src1, $src2 beq $at, $zero, label Branch if Less Than or Equal:

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture