Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Informationsteknologi Today’s class More assembly language programming Friday, September 28, 2007 Computer Architecture I - Class 2 1 Informationsteknologi Data transfer instructions lw – load word from memory into a register (note that the address must be a word address, divisible by 4) lb – load byte sw – store word into memory from a register (address must be for a word) sb – store byte Friday, September 28, 2007 Computer Architecture I - Class 2 2 Informationsteknologi Addition (signed) add regdest,regsrc1,regsrc2 addi regdest,regsrc,const Performs regdest = regsrc + const Add immediate, because const is part of instruction (no memory reference) add regdest,regsrc,const Performs regdest = regsrc1 + regsrc2 Uses register addressing (no memory reference) Will generate an addi instruction by the assembler add regdest, const Will generate addi regdest,regdest,const Friday, September 28, 2007 Computer Architecture I - Class 2 3 Informationsteknologi Addition (unsigned) addu regdest,regsrc1,regsrc2 addiu regdest,regsrc,const Performs regdest = regsrc + const addu regdest,regsrc,const Performs regdest = regsrc1 + regsrc2 Will generate an addiu instruction by the assembler addu regdest, const Will generate addiu regdest,regdest,const Friday, September 28, 2007 Computer Architecture I - Class 2 4 Informationsteknologi Subtraction sub regdest,regsrc1,regsrc2 subu regdest,regsrc1,regsrc2 Performs regdest = regsrc1 - regsrc2 This is a signed subtraction Performs regdest = regsrc1 - regsrc2 This is an unsigned subtraction No subi instruction Can do an addi with the negative of what you want to subtract Friday, September 28, 2007 Computer Architecture I - Class 2 5 Informationsteknologi Multiplication Result of multiplying two 32-bit numbers can be 64 bits big Have two special registers called lo and hi to hold the two 32-bit parts of the result mult regsrc1,regsrc2 will put the low 32 bits of the product in lo and the high 32 bits in hi Use mflo regdest (move from lo) to get the low 32 bits into a register Use mfhi regdest (move from hi) to get the high 32 bits into a register The pseudo-instruction mul regdest,regsrc1,regsrc2 will get the low 32 bits of the product into regdest Friday, September 28, 2007 Computer Architecture I - Class 2 6 Informationsteknologi Division div regsrc1,regsrc2 will put the integer quotient of regsrc1/regsrc2 in lo and the remainder in hi The pseudo-instruction div regdest,regsrc1,regsrc2 will get the integer quotient into regdest Friday, September 28, 2007 Computer Architecture I - Class 2 7 Informationsteknologi Example program Program temperature.asm converts Celsius temperatures to Fahrenheit Study it and demo it Friday, September 28, 2007 Computer Architecture I - Class 2 8 Informationsteknologi In-class exercise Modify the temperature conversion program so it converts from Fahrenheit to Celsius instead. 5 Celsius ( Fahrenheit 32) 9 Friday, September 28, 2007 Computer Architecture I - Class 2 9 Informationsteknologi Unconditional branching j addr – jumps to the indicated address and continues execution from there jr reg – jumps to the address stored in the specified register and continues execution from there Friday, September 28, 2007 Computer Architecture I - Class 2 10 Informationsteknologi Conditional branching beq regsrc1,regsrc2,addr – branch to addr if regsrc1 equals regsrc2 beqz reg,addr – branch to addr if reg equals 0 bne regsrc1,regsrc2,addr – branch to addr if regsrc1 does not equal regsrc2 blt regsrc1,regsrc2,addr – branch to addr if regsrc1 is less than regsrc2 The assembler will let the second operand be a constant instead of a register if desired There are many more – see Appendix B (page 146) of Waldron Friday, September 28, 2007 Computer Architecture I - Class 2 11 Informationsteknologi Example programs Program length.asm prints out the length of a character string Program replace.asm replaces lower case ‘a’ with upper case ‘A’ in a string Study them and demo them Friday, September 28, 2007 Computer Architecture I - Class 2 12 Informationsteknologi In-class exercise Write a program to count how many times the letter ‘e’ appears in a string. Friday, September 28, 2007 Computer Architecture I - Class 2 13