MIPS3 - Assembly vs. machine language So far we've been...

Info iconThis preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon
55 Assembly vs. machine language ± So far we’ve been using assembly language . We assign names to operations (e.g., add ) and operands (e.g., $t0 ). Branches and jumps use labels instead of actual addresses. Assemblers support many pseudo-instructions. ± Programs must eventually be translated into machine language , a binary format that can be stored in memory and decoded by the CPU. ± MIPS machine language is designed to be easy to decode. Each MIPS instruction is the same length, 32 bits. There are only three different instruction formats, which are very similar to each other. ± Studying MIPS machine language will also reveal some restrictions in the instruction set architecture, and how they can be overcome.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
56 ± simple instructions all 32 bits wide ± very structured, no unnecessary baggage ± only three instruction formats op rs rt rd shamt funct op rs rt 16 bit address op 26 bit address R I J Three MIPS formats Signed value -32768 ~ +32767 R-type: ALU instructions (add, sub,…) *I-type: immediate (addi …), loads (lw …), stores (sw …), conditional branches (bne …), jump register (jr …) J-type: jump (j), jump and link (jal)
Background image of page 2
57 ± Small constants are used quite frequently (50% of operands) e.g., A = A + 5; B = B + 1; C = C - 18; ± MIPS Instructions: addi $29, $29, 4 slti $8, $18, 10 andi $29, $29, 6 ori $29, $29, 4 Constants
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
58 ± Larger constants can be loaded into a register 16 bits at a time. The load upper immediate instruction lui loads the highest 16 bits of a register with a constant, and clears the lowest 16 bits to 0s. An immediate logical OR, ori , then sets the lower 16 bits. ± To load the 32-bit value 0000 0000 0011 1101 0000 1001 0000 0000: lui $s0, 0x003D # $s0 = 003D 0000 (in hex) ori $s0, $s0, 0x0900 # $s0 = 003D 0900 ± This illustrates the principle of making the common case fast. Most of the time, 16-bit constants are enough. It’s still possible to load 32-bit constants, but at the cost of two instructions and one temporary register. ± Pseudo-instructions may contain large constants. Assemblers will translate such instructions correctly. ± We used a lw instruction before. Larger constants
Background image of page 4
59 ± The limited 16-bit constant can present difficulties for accesses to global data. Let’s assume the assembler puts a variable at address 0x10010004. 0x10010004 is bigger than 32,767 ± In these situations, the assembler breaks the immediate into two pieces. lui $t0, 0x1001 # 0x1001 0000 lw $t1, 0x0004($t0) # Read from Mem[0x1001 0004] Loads and stores
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
60 ± For branch instructions, the constant field is not an address, but an offset from the next program counter (PC+4) to the target address. beq $at, $0, L add $v1, $v0, $0 add $v1, $v1, $v1 j Somewhere L: add $v1, $v0, $v0 ± Since the branch target L is three instructions past the first add , the address field would contain 3×4=12. The whole beq instruction would be stored as: 000100 00001 00000 0000 0000 0000 1100 op rs rt address Branches Why (PC+4)? Will be clear when we learned pipelining
Background image of page 6
61 ± Empirical studies of real programs show that most branches go to targets less than 32,767 instructions away branches are mostly used in loops and conditionals, and programmers are taught to make code bodies short.
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 33

MIPS3 - Assembly vs. machine language So far we've been...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online