Wednesday, March 03rd, 2004 MAL instructions most arithmatic operations are the same as MAL, except that operands are registers. The last operator can be an immediate Notation $r -- MAL syntax for a register desigation r is in range 0 - 31 avoid : 1-7,26,27,29 X(rb) MAL Syntax for Base-Displacement Addr Mode rb is register containing base addr X is the displacement if X isn't provided it is assumed to be zero rt/R - Target Register rs/S - Source Register rd/D - Destination Register Later -- X^n means take n bits of X ex 0^3 means 000 Xsubm mens take bit at position m in X ex 0101sub2 = 1 || means concatenate Ex: Hex Addr Hex contents 00002000 0011aaee c1 : .word 0x0011aaee 2004 ???? c2: .space 12 2008 ???? 200c ???? 2010 00000016 c3: .word 22 2014 000000f3 c4: .word 0x0000000f3 Load/Store la rt,label # Load Addr * Place label's addr into rt * ex: la $9, c1 # $9 gets 0x00002000 * how is opcode, rt, and label's address put into a 32 bit instr? Answer requires TAL li rt, immediate #Load Immediate * Place te immeditae value into rt ex: li $9 20 # Register 9 gets 0x0000000c immediate: a 16 bit 2's complement integer sign extended into the other half of the register lw rt, X(rb) # Load Word * Place the word at addr Xtrb into rt ex: lw $10, 0($9) # If $9 contains 0x00002000 $10 gets 0x0011aaee ex: lw $10, 15($9) # $10 gets 0x00000016 ex: lw $10, ($9) # same as ex1 sw rs,X(rb) #store word * Place contents of rs into word at addr x+rb * Ex: li $10, -1 #$10 gets 0xffffffff la $11, c4 #$11 gets 0x00002014 sw $10, ($11) #word at 0x00002014 gets 0xffffff lb rt, X(rb) # Load Byte * Place the byte at addr X+rb into LSByte of rt and sign extend through MSBytes of rt rt <---- (m[addr]sub7)^24 || m[addr] ex: lb $10,0($9) # if $9 contains 0x00002000 # little endian: $10 gets 0xffffffee lbu rt,X(rb) # Load Byte Unsigned rt <--- 0^24 || m[addr] sb rs, X(rb) # Store Byte * Place LSByte of rs into the byte at addr x+rb ex: li $10, -18 #$10 gets 0xffffffee la $11, $c2 #$11 gets 0x00002004 sb $10, 8($11) #byte at addr 0x0000200c gets 0xee Word instrs must use word aligned addrs byte instrs don't need alignment ALU Instrs * opcodes are the same as in SAL but operands must be in registers or an immediate value (for the second operand) Ex: add $10,$9,$8 # $10 gets sum of $9 and $8 add $10,$9,15 # $10 gets sum of 15 (16 bits 2's comp) sign # extended 2 32 bits and add to $9 BRANCHES *opcodes are the same as SAL but operands must be in registers ex: beq $20,$23,branchtarget b label j label #From MAL point of view these are the same I/O * Only 3 instructions getc # Like SAL get .byte putc # Like SAL put .byte puts # Like SAL puts BUT operand must be in a register puts label # Prints out null-termintes string of hars starting at label puts rs # prints out null-terminate string of chars starting at the addr in rs SUMMARY OF DIFFERENCE BETWEEN SAL AND MAL * MAL Doesn't have m[] and M[] Must use base displacement addr mode * MAL Branch instructions only use reg addressing mode * MAL ALU instructions only use register or immediate addressing modes * MAL Doesn't have SAL's put .word * MAL Doesn't have SAL's get .word