Today - PowerPoint PPT Presentation

About This Presentation
Title:

Today

Description:

... temperature.asm converts Celsius temperatures to Fahrenheit. Study it and ... temperature conversion program so it converts from Fahrenheit to Celsius instead. ... – PowerPoint PPT presentation

Number of Views:38
Avg rating:3.0/5.0
Slides: 14
Provided by: CaryL7
Category:

less

Transcript and Presenter's Notes

Title: Today


1
Todays class
  • More assembly language programming

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

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

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

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

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

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

8
Example program
  • Program temperature.asm converts Celsius
    temperatures to Fahrenheit
  • Study it and demo it

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

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

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

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

13
In-class exercise
  • Write a program to count how many times the
    letter e appears in a string.
Write a Comment
User Comments (0)
About PowerShow.com