1 / 13

Arithmetic Ops

Arithmetic Ops. Register Arithmetic. add : add two registers add $ dest , $src1, $src2 sub : subtract src2 from src 1 sub $ dest , $src1, $src2. It's a Trap!. Add/Subtract trap on overflow Jump to special location in memory, look for instructions. Unsigned Arithmetic.

oma
Download Presentation

Arithmetic Ops

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. Arithmetic Ops

  2. Register Arithmetic • add: add two registers add $dest, $src1, $src2 • sub: subtract src2 from src1 sub $dest, $src1, $src2

  3. It's a Trap! • Add/Subtract trap on overflow • Jump to special location in memory, look for instructions

  4. Unsigned Arithmetic • addu/subu: add/subtract two registers, ignore overflow! • Still can overflow, up to assembler/programmer to catch

  5. Immediate Arithmetic • iversions take immediate: addi $dest, $src1, imdtaddiu$dest, $src1, imdt No subi… just addi with negative

  6. Calculation • Assume register $8 has a value representing x, calculate 5x – 4 and store the answer in $9

  7. So how do we multiply for real??? • …

  8. Mult • mult: multiplymult $src1, $src2 • Answer placed in double register • hi / lo

  9. Retrieval • hi / lo register are not addressable • Must move answer back to regular registers: • mflo: move from lomflo $dest Real hardware : must wait after mflo before next mult

  10. Retrieval • mfhi: move from himfhi $dest • Special purpose only… you shouldn't need

  11. Multu • multu: unsigned multiplication • mult : extends sign bit • multu : do not extend sign bit • mult never traps

  12. Div • Division algorithm uses double sized register • Builds remainder in upper half, quotient in low • Use div, then mflo/mfhi:

  13. SRA • sra: shift right arithmetic • Preserve sign bit sra $dest, $src1, shiftBits

More Related