1 / 13

Today’s class

Today’s class. More assembly language programming. 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.

louvain
Download Presentation

Today’s class

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Today’s class • More assembly language programming Computer Architecture I - Class 2

  2. 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 Computer Architecture I - Class 2

  3. Addition (signed) • add regdest,regsrc1,regsrc2 • Performs regdest = regsrc1 + regsrc2 • Uses register addressing (no memory reference) • addi regdest,regsrc,const • Performs regdest = regsrc + const • Add immediate, because const is part of instruction (no memory reference) • add regdest,regsrc,const • Will generate an addi instruction by the assembler • add regdest, const • Will generate addi regdest,regdest,const Computer Architecture I - Class 2

  4. Addition (unsigned) • addu regdest,regsrc1,regsrc2 • Performs regdest = regsrc1 + regsrc2 • addiu regdest,regsrc,const • Performs regdest = regsrc + const • addu regdest,regsrc,const • Will generate an addiu instruction by the assembler • addu regdest, const • Will generate addiu regdest,regdest,const Computer Architecture I - Class 2

  5. Subtraction • sub regdest,regsrc1,regsrc2 • Performs regdest = regsrc1 - regsrc2 • This is a signed subtraction • subu regdest,regsrc1,regsrc2 • 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 Computer Architecture I - Class 2

  6. 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 Computer Architecture I - Class 2

  7. 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 Computer Architecture I - Class 2

  8. Example program • Program temperature.asm converts Celsius temperatures to Fahrenheit • Study it and demo it Computer Architecture I - Class 2

  9. In-class exercise • Modify the temperature conversion program so it converts from Fahrenheit to Celsius instead. Computer Architecture I - Class 2

  10. 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 Computer Architecture I - Class 2

  11. 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 Computer Architecture I - Class 2

  12. 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 Computer Architecture I - Class 2

  13. In-class exercise • Write a program to count how many times the letter ‘e’ appears in a string. Computer Architecture I - Class 2

More Related