ARITHMETIC INSTRUCTIONS (INTEGERS) - PowerPoint PPT Presentation

1 / 14
About This Presentation
Title:

ARITHMETIC INSTRUCTIONS (INTEGERS)

Description:

Add and Sub takes two operands. Examples (word type) Add ax, bx ; register operands ... Assembly program structure. Every assembly program has the following structure: ... – PowerPoint PPT presentation

Number of Views:46
Avg rating:3.0/5.0
Slides: 15
Provided by: shantil
Category:

less

Transcript and Presenter's Notes

Title: ARITHMETIC INSTRUCTIONS (INTEGERS)


1
(No Transcript)
2
ARITHMETIC INSTRUCTIONS (INTEGERS)
  • ADD for Addition
  • SUB for Subtraction
  • IMUL for Multiplication
  • IDIV for Division

3
Examples for Addition and Subtraction
  • Add and Sub takes two operands
  • Examples (word type)
  • Add ax, bx register operands
  • Add Ax, d memory to register
  • Sub e, ax register to memory
  • Both operands cannot be memory locations. Memory
    operand is surrounded by square brackets

4
Examples for Addition and Subtraction
  • Add and Sub takes two operands
  • Examples (byte type)
  • Add al, bl register operands
  • Add bh, d memory to register
  • Sub e, al register to memory
  • Both operands cannot be memory locations. Memory
    operand is surrounded by square brackets

5
Multiplication and Division
  • IMUL, IDIV and NEG takes one operand
  • IMUL and IDIV both uses registers ax and dx for
    word type operands. For byte type, both IMUL and
    IDIV uses registers al and ah.
  • In case of word type data, Number to be
    multiplied or divided has to be in register ax.
    For byte type, Number to be multiplied or divided
    has to be in register al
  • For word type data, number in ax is extended from
    16 bits to 32 bits by multiplying by one and
    stored in register ax and dx. For byte type,
    number in al is extended from 8 bits to 16 bits
    word by multiplying by one and stored in register
    ax.

6
Assembly program structure
  • Every assembly program has the following
    structure
  • .model small
  • . stack 256
  • .data
  • data def8ned required in the program
  • .code
  • main proc
  • mov ax, _at_dat
  • mov ds, ax
  • assembly code to get the desired results
  • code to terminate the program.
  • mov ax, 04C00h
  • int 21h
  • main endp
  • end main

7
Creating a source file
  • Select notepad and type the following code
  • .model small
  • .stack 256
  • .data data segment
  • a db 'hello world !!!', 13, 10, ''
  • .code code segment
  • main proc required
  • mov ax, _at_data required
  • mov ds, ax required
  • mov dx, offset a
  • mov ah, 9
  • int 21h
  • mov ax, 04C00h required
  • int 21h required
  • main endp required
  • end main required

8
Saving a file on floppy
  • Select file on menu bar
  • Select save as
  • Select A drive
  • Give a name HELLO.ASM
  • Select save
  • The file you created is saved on your floppy.

9
Data definitions (Byte)
  • Assume the following data definitions
  • A db 66 B db -8
  • d dw 0 e db 0
  • f db 0 g db 0
  • h db 0 i db 0
  • One db 1

10
Byte addition and subtraction
  • Code to compute e a b
  • mov al, a
  • add al, b
  • mov e, al
  • Code to compute f a -b
  • mov al, a
  • sub al, b
  • mov f, al

11
Byte multiplication and division
  • Code to
  • compute d a b compute g a / b
  • mov al, a mov
    al, a
  • imul one imul
    one
  • imul b idiv
    b
  • mov d, al mov
    h, al

  • mov i, ah

12
Data definitions (Word)
  • Assume the following data definitions
  • A dw 66 B dw -8
  • d dw 0 e dw 0
  • f dw 0 g dw 0
  • h dw 0 i dw 0
  • One dw 1

13
word addition and subtraction
  • Code to compute e a b
  • mov ax, a
  • add ax, b
  • mov e, ax
  • Code to compute f a -b
  • mov ax, a
  • sub ax, b
  • mov f, ax

14
Word multiplication and division
  • Code to
  • compute d a b compute g a / b
  • mov ax, a mov
    ax, a
  • imul one imul
    one
  • imul b idiv
    b
  • mov d, ax mov
    h, ax

  • mov i, dx
Write a Comment
User Comments (0)
About PowerShow.com