CS 61C L17 Introduction to MIPS: Instruction Representation III (1) Garcia, Fall 2004 © UCBLecturer PSOE Dan Garciawww.cs.berkeley.edu/~ddgarciainst.eecs.berkeley.edu/~cs61cCS61C : Machine Structures Lecture 17 – Introduction to MIPS Instruction Representation III 2004-10-08World Cyber Games⇒ 5-day competitionheld in SF to determine the topvideo game players in theworld. Halo, Warcraft III, FIFASoccer, Counter-Strike, etc.www.worldcybergames.comCS 61C L17 Introduction to MIPS: Instruction Representation III (2) Garcia, Fall 2004 © UCBOutline• Disassembly• Pseudoinstructions and“True” Assembly Language (TAL) v.“MIPS” Assembly Language (MAL)CS 61C L17 Introduction to MIPS: Instruction Representation III (3) Garcia, Fall 2004 © UCBDecoding Machine Language• How do we convert 1s and 0s to C code?Machine language ⇒ C?• For each 32 bits:• Look at opcode: 0 means R-Format, 2 or 3mean J-Format, otherwise I-Format.• Use instruction type to determine whichfields exist.• Write out MIPS assembly code, convertingeach field to name, register number/name,or decimal/hex number.• Logically convert this MIPS code into validC code. Always possible? Unique?CS 61C L17 Introduction to MIPS: Instruction Representation III (4) Garcia, Fall 2004 © UCBDecoding Example (1/7)• Here are six machine languageinstructions in hexadecimal:00001025hex0005402Ahex11000003hex00441020hex20A5FFFFhex08100001hex• Let the first instruction be at address4,194,304ten (0x00400000hex).• Next step: convert hex to binaryCS 61C L17 Introduction to MIPS: Instruction Representation III (5) Garcia, Fall 2004 © UCBDecoding Example (2/7)• The six machine language instructions inbinary: 000000000000000000010000001001010000000000000101010000000010101000010001000000000000000000000011000000000100010000010000001000000010000010100101111111111111111100001000000100000000000000000001• Next step: identify opcode and format1, 4-31 rs rt immediate0 rs rt rd functshamtRIJ target address2 or 3CS 61C L17 Introduction to MIPS: Instruction Representation III (6) Garcia, Fall 2004 © UCBDecoding Example (3/7)• Select the opcode (first 6 bits)to determine the format: 000000000000000000010000001001010000000000000101010000000010101000010001000000000000000000000011000000000100010000010000001000000010000010100101111111111111111100001000000100000000000000000001• Look at opcode:0 means R-Format,2 or 3 mean J-Format,otherwise I-Format.• !Next step: separation of fieldsRRIRIJFormat:CS 61C L17 Introduction to MIPS: Instruction Representation III (7) Garcia, Fall 2004 © UCBDecoding Example (4/7)• Fields separated based on format/opcode:0 0 0 2 3700 0 5 8 4204 8 0 +30 2 4 2 3208 5 5 -12 1,048,577• Next step: translate (“disassemble”) toMIPS assembly instructionsRRIRIJFormat:CS 61C L17 Introduction to MIPS: Instruction Representation III (8) Garcia, Fall 2004 © UCBDecoding Example (5/7)• MIPS Assembly (Part 1):Address: Assembly instructions:0x00400000 or $2,$0,$00x00400004 slt $8,$0,$50x00400008 beq $8,$0,30x0040000c add $2,$2,$40x00400010 addi $5,$5,-10x00400014 j 0x100001• Better solution: translate to moremeaningful MIPS instructions (fix thebranch/jump and add labels, registers)CS 61C L17 Introduction to MIPS: Instruction Representation III (9) Garcia, Fall 2004 © UCBDecoding Example (6/7)• MIPS Assembly (Part 2):or $v0,$0,$0Loop: slt $t0,$0,$a1beq $t0,$0,Exitadd $v0,$v0,$a0addi $a1,$a1,-1j LoopExit:• Next step: translate to C code(be creative!)CS 61C L17 Introduction to MIPS: Instruction Representation III (10) Garcia, Fall 2004 © UCBDecoding Example (7/7)• After C code (Mapping below)$v0: product$a0: multiplicand$a1: multiplierproduct = 0;while (multiplier > 0) {product += multiplicand;multiplier -= 1;}Before Hex:00001025hex0005402Ahex11000003hex00441020hex20A5FFFFhex 08100001hexDemonstrated Big 61CIdea: Instructions arejust numbers, code istreated like data or $v0,$0,$0Loop: slt $t0,$0,$a1 beq $t0,$0,Exit add $v0,$v0,$a0 addi $a1,$a1,-1 j LoopExit:CS 61C L17 Introduction to MIPS: Instruction Representation III (12) Garcia, Fall 2004 © UCBKilo, Mega, Giga, Tera, Peta, Exa, Zetta, Yotta• Common use prefixes (all SI, except K [= k in SI])• Confusing! Common usage of “kilobyte” means1024 bytes, but the “correct” SI value is 1000 bytes• Hard Disk manufacturers & Telecommunications arethe only computing groups that use SI factors, sowhat is advertised as a 30!GB drive will actually onlyhold about 28 x 230 bytes, and a 1!Mbit/s connectiontransfers 106 bps.1024 = 1,000,000,000,000,000,000,000,000280 = 1,208,925,819,614,629,174,706,176YYotta1021 = 1,000,000,000,000,000,000,000270 = 1,180,591,620,717,411,303,424ZZetta1018 = 1,000,000,000,000,000,000260 = 1,152,921,504,606,846,976EExa1015 = 1,000,000,000,000,000250 = 1,125,899,906,842,624PPeta1012 = 1,000,000,000,000240 = 1,099,511,627,776TTera109 = 1,000,000,000230 = 1,073,741,824GGiga106 = 1,000,000220 = 1,048,576MMega103 = 1,000210 = 1,024KKiloSI sizeFactorAbbrNamephysics.nist.gov/cuu/Units/binary.htmlCS 61C L17 Introduction to MIPS: Instruction Representation III (13) Garcia, Fall 2004 © UCBkibi, mebi, gibi, tebi, pebi, exbi, zebi, yobi• New IEC Standard Prefixes [only to exbi officially]• International Electrotechnical Commission (IEC) in1999 introduced these to specify binary quantities.• Names come from shortened versions of theoriginal SI prefixes (same pronunciation) and bi isshort for “binary”, but pronounced “bee” :-(• Now SI prefixes only have their base-10 meaningand never have a base-2 meaning.280 = 1,208,925,819,614,629,174,706,176270 = 1,180,591,620,717,411,303,424260 = 1,152,921,504,606,846,976250 = 1,125,899,906,842,624240 = 1,099,511,627,776230 = 1,073,741,824220 = 1,048,576210 = 1,024FactorYiyobiZizebiEiexbiPipebiTitebiGigibiMimebiKikibiAbbrNameen.wikipedia.org/wiki/Binary_prefixAs of thiswriting, thisproposal hasyet to gainwidespreaduse…CS 61C L17 Introduction to MIPS: Instruction Representation III (14) Garcia, Fall 2004 © UCBReview from before: lui• So how does lui help us?• Example:addi $t0,$t0, 0xABABCDCDbecomes:lui $at, 0xABABori $at, $at, 0xCDCDadd $t0,$t0,$at• Now each I-format instruction has only a 16-bit immediate.• Wouldn’t it be nice if the assemblerwould this for us automatically?- If number too big, then just automaticallyreplace
View Full Document