ICS 51 Discussion 3 - PowerPoint PPT Presentation

1 / 9
About This Presentation
Title:

ICS 51 Discussion 3

Description:

ICS 51 Discussion 3. Multiplication, Division, and Stack. Multiplication Operation ... Why Using Stack. What if we run out of registers? ... – PowerPoint PPT presentation

Number of Views:17
Avg rating:3.0/5.0
Slides: 10
Provided by: gua88
Category:
Tags: ics | discussion | run | up

less

Transcript and Presenter's Notes

Title: ICS 51 Discussion 3


1
ICS 51 Discussion 3
  • Multiplication, Division, and Stack

2
Multiplication Operation
  • Unsigned multiplication MUL
  • Code MUL Operand
  • If Operand is a byte, e.g. MUL BL, thenAX
    ALOperand
  • If Operand is a word, e.g., MUL BX, thenDXAX
    AXOperand
  • If Operand is a dword, e.g., MUL EBX,
    thenEDXEAX EAXOperand
  • Signed multiplication IMUL
  • (look up the code table)

3
MUL Examples
  • Mov EAX, 0 // Clear EAX
  • Mov AL, 5 //First number
  • Mov BL, 10 //Second number
  • Mul BL //Multiply 2 numbers
  • Where and what is the result?
  • AX ALBL 50

4
MUL Examples (cont.)
  • Mov EDX, 0 //clear EDX
  • Mov EAX, 0 //clear EAX
  • Mov AX, 4460 //first number
  • Mov BX, 1000 //second number
  • Mul BX //multiply 2 numbers
  • Where and what is the result?
  • DXAX AXBX 4,460,000
  • 4,460,000 440DE0 in Hex
  • DX has 0x0044, AX has 0x0DE0

5
Division Operation
  • Unsigned division DIV
  • Code DIV Operand
  • If Operand is a byte, e.g. DIV BL, thenAL
    AX/Operand AH Rest
  • If Operand is a word, e.g., DIV BX, thenAX
    DXAX/Operand DX Rest
  • If Operand is a dword, e.g., DIV EBX, thenEAX
    EDXEAX/Operand EDX Rest
  • Signed division IDIV
  • (look up the code table)

6
DIV Example
  • Mov EDX, 70001 //dividend
  • Mov AX, DX //move lower 2 bytes to AX
  • Shr EDX, 16 //DX has the higher 2 bytes
  • Mov CX, 2 //divisor
  • Div CX //divide 70001 by 2
  • Result
  • Quotient AX DXAX / CX 35000
  • Remainder DX 1

7
Why Using Stack
  • What if we run out of registers?
  • What if the registers you are going to use are
    currently used by other functions?
  • Answers PUSH and POP

8
Stack Push/Pop Examples
  • run out of registersPush EAX //save EAX on
    the stackPush EBX //save EBX on the stack
    use EAX and EBX for some calculations Pop EBX
    //move top of the stack to EBXPop EAX //move top
    of the stack to EAX to restore
    its original value
  • Note the orders of PUSH and POP are reversed

9
Stack Push/Pop Examples (cont.)
  • void functionXXX() __asm Push EAX Push
    EBX Pop EBX Pop EAX
Write a Comment
User Comments (0)
About PowerShow.com