Introduction to Machine And Assembly Language - PowerPoint PPT Presentation

1 / 20
About This Presentation
Title:

Introduction to Machine And Assembly Language

Description:

We now really understand syntax and are pretending we understand conditional processing. And we're going to start looking at more interesting instructions ... – PowerPoint PPT presentation

Number of Views:99
Avg rating:3.0/5.0
Slides: 21
Provided by: richar134
Category:

less

Transcript and Presenter's Notes

Title: Introduction to Machine And Assembly Language


1
Introduction to Machine And Assembly Language
  • Data Transfers and Mathematics
  • Dr. Richard Ford

2
Okay
  • We now really understand syntax and are
    pretending we understand conditional processing
  • And were going to start looking at more
    interesting instructions
  • Basically, were going to increase our vocabulary
    and see why ASM is very different from Java
  • With great power comes great responsibility

3
Direct Memory Operands
  • Already used these
  • Remember our very exciting program from last
    week?
  • mov eax, var1

4
The MOV instruction
  • One of the most important instructions
  • MOV destination, source
  • Rules
  • Both operands must be the same size
  • Both operands cannot be memory operands
  • CS, EIP and IP cannot be destination operands
  • An immediate value cannot be moved to a segment
    register

5
Memory to Memory?
  • Cmon you tell me how to do it
  • .datavar1 WORD ?var2 WORD ?.code
  • Now what?

6
Zero/Sign Extension
  • How you move from a small register to a larger
    one
  • Why is this a problem?
  • Solution?
  • .datacount WORD 1.codemov ecx, 0mov cx, count
  • But what if count is SIGNED? Lets try it

7
MOVZX
  • Move with Zero eXtend
  • .databyte1 BYTE 9Bhword1 WORD 0A69h.codemovzx
    eax, word1movzx edx, byte1movzx cx, byte1

8
MOVSX
  • Same idea but for signed numbers
  • Remind me how signed numbers work?
  • mov bx, 0A69hmovsx eax, bxmovsx edx, blmovsx
    cx, bl

9
LAHF/SAHF
  • Loads and saves the flags into AH
  • .datasaveflags BYTE ?.codelahfmov saveflags,
    ahmov ah, saveflagssahf

10
XCHG
  • Swap two operands of equal size
  • xchg ax, bxxchg ah, alxchg var1, bxxchg eax,
    ebx
  • How to swap two memory contents?

11
Direct-offset Operands
  • Pretty straightforward
  • .dataarrayB BYTE 10h,20h,30h,40h.codemov al,
    arrayBmov al, arrayB1mov al, arrayB2
  • What about mov al, arrayB20 ?

12
Addition and Subtraction
  • The simplest method is to add or subtract one
  • INC EAX
  • DEC BX

13
Adding More than One
  • ADD instruction
  • ADD destination, source
  • ADD eax, var1

14
Subtraction is the same way
  • SUB destination, source
  • sub eax, 12345h
  • Note ADD and SUB both can change the flags this
    is important

15
Negation
  • Very simple indeed
  • NEG reg
  • NEG mem

16
Flags and Arithmetic
  • Zero and Sign Flags
  • Zero set when result is ZERO
  • Sign set when result is negative
  • mov cx, 1sub cx, 1mov ax, 0ffffhinc axinc
    axsub cx, 1add cx, 2

17
The Carry Flag
  • Only meaningful on unsigned arithmetic, when the
    result is too large or too small
  • mov al, 0ffhadd al, 1mov ax, 00ffhadd ax,
    1mov al, 1sub al, 2

18
Overflow Flag
  • Only meaningful on signed arithmetic
  • When we would overflow a value
  • mov al, 127inc al

19
All Done
  • We now understand how some of the flags work, and
    we can add and subtract numbers easily
  • Next, well look at Data-related operators

20
Assignment
  • Make the bubblesort complete, so you can sort an
    arbitrary array of SWORDs
  • Print out the array before you start and after
    using WriteInt
  • For extra credit
  • Stop sorting once youre done (i.e. dont do
    unnecessary passes through the array)
  • Sort on the sequentially shorter unordered
    remainder of the array
Write a Comment
User Comments (0)
About PowerShow.com