Presentation is loading. Please wait.

Presentation is loading. Please wait.

Informationsteknologi Friday, September 28, 2007Computer Architecture I - Class 21 Today’s class More assembly language programming.

Similar presentations


Presentation on theme: "Informationsteknologi Friday, September 28, 2007Computer Architecture I - Class 21 Today’s class More assembly language programming."— Presentation transcript:

1 Informationsteknologi Friday, September 28, 2007Computer Architecture I - Class 21 Today’s class More assembly language programming

2 Informationsteknologi Friday, September 28, 2007Computer Architecture I - Class 22 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

3 Informationsteknologi Friday, September 28, 2007Computer Architecture I - Class 23 Addition (signed) add reg dest,reg src1,reg src2  Performs reg dest = reg src1 + reg src2  Uses register addressing (no memory reference) addi reg dest,reg src,const  Performs reg dest = reg src + const  Add immediate, because const is part of instruction (no memory reference) add reg dest,reg src,const  Will generate an addi instruction by the assembler add reg dest, const  Will generate addi reg dest,reg dest,const

4 Informationsteknologi Friday, September 28, 2007Computer Architecture I - Class 24 Addition (unsigned) addu reg dest,reg src1,reg src2  Performs reg dest = reg src1 + reg src2 addiu reg dest,reg src,const  Performs reg dest = reg src + const addu reg dest,reg src,const  Will generate an addiu instruction by the assembler addu reg dest, const  Will generate addiu reg dest,reg dest,const

5 Informationsteknologi Friday, September 28, 2007Computer Architecture I - Class 25 Subtraction sub reg dest,reg src1,reg src2  Performs reg dest = reg src1 - reg src2  This is a signed subtraction subu reg dest,reg src1,reg src2  Performs reg dest = reg src1 - reg src2  This is an unsigned subtraction No subi instruction  Can do an addi with the negative of what you want to subtract

6 Informationsteknologi Friday, September 28, 2007Computer Architecture I - Class 26 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 reg src1,reg src2 will put the low 32 bits of the product in lo and the high 32 bits in hi Use mflo reg dest (move from lo ) to get the low 32 bits into a register Use mfhi reg dest (move from hi ) to get the high 32 bits into a register The pseudo-instruction mul reg dest,reg src1,reg src2 will get the low 32 bits of the product into reg dest

7 Informationsteknologi Friday, September 28, 2007Computer Architecture I - Class 27 Division div reg src1,reg src2 will put the integer quotient of reg src1 /reg src2 in lo and the remainder in hi The pseudo-instruction div reg dest,reg src1,reg src2 will get the integer quotient into reg dest

8 Informationsteknologi Friday, September 28, 2007Computer Architecture I - Class 28 Example program Program temperature.asm converts Celsius temperatures to Fahrenheit Study it and demo itdemo

9 Informationsteknologi Friday, September 28, 2007Computer Architecture I - Class 29 In-class exercise Modify the temperature conversion program so it converts from Fahrenheit to Celsius instead.

10 Informationsteknologi Friday, September 28, 2007Computer Architecture I - Class 210 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

11 Informationsteknologi Friday, September 28, 2007Computer Architecture I - Class 211 Conditional branching beq reg src1,reg src2,addr – branch to addr if reg src1 equals reg src2 beqz reg,addr – branch to addr if reg equals 0 bne reg src1,reg src2,addr – branch to addr if reg src1 does not equal reg src2 blt reg src1,reg src2,addr – branch to addr if reg src1 is less than reg src2 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

12 Informationsteknologi Friday, September 28, 2007Computer Architecture I - Class 212 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 themdemo

13 Informationsteknologi Friday, September 28, 2007Computer Architecture I - Class 213 In-class exercise Write a program to count how many times the letter ‘e’ appears in a string.


Download ppt "Informationsteknologi Friday, September 28, 2007Computer Architecture I - Class 21 Today’s class More assembly language programming."

Similar presentations


Ads by Google