Introduction to Machine And Assembly Language - PowerPoint PPT Presentation

1 / 12
About This Presentation
Title:

Introduction to Machine And Assembly Language

Description:

We've looked at some of the procedures used in the book ... The program should then sort these strings alphabetically and print them out in order ... – PowerPoint PPT presentation

Number of Views:140
Avg rating:3.0/5.0
Slides: 13
Provided by: richar134
Category:

less

Transcript and Presenter's Notes

Title: Introduction to Machine And Assembly Language


1
Introduction to Machine And Assembly Language
  • Modular Programming Procedures
  • Dr. Richard Ford

2
Okay
  • Weve looked at some of the procedures used in
    the book
  • Now, we need to learn how to define our own
    procedures
  • But the best thing is, we already know how

3
Remember MAIN?
  • Main PROC
  • main ENDP
  • Well, thats a procedure (mostly)!
  • All we need to do is add a RET instruction, so
    the assembler knows were done

4
Um why?
  • Main is special
  • It ends with an exit command
  • This is an alias for a call to ExitProcess a
    Windows function
  • Exit INVOKE ExitProcess, 0
  • So, our procedures need to finish too hence the
    RET instruction
  • Chris DONT WORRY ABOUT INVOKE YET!!!

5
Procedures in General
  • A procedure receives registers from the calling
    code unchanged (this is a lie)
  • So, if EBX 123456h when we call a proc, it
    starts off with that value in the proc
  • Similarly if a register gets changed in a proc,
    its changed in the calling program too BE WARNED

6
Example PROC
  • SumOf PROC add eax, ebx add eax, ecx
    retSumOf ENDP
  • NOTE eax is changed in the calling code
  • Helpful to add comments (see p.160)

7
Remember that Stack thing?
  • Vital for understanding how procedures work
  • CALL is used to call a procedure it pushes the
    address of the next instruction on the stack, and
    JMPs to the procedure in memeory
  • RET JMPs back to the address we stored on the
    stack (probably youll see)
  • DEMO CALL.ASM

8
The Stack in Nested Procs
  • If a PROC calls a PROC calls a PROC what will the
    stack look like?
  • Look at NESTED.ASM
  • What will the stack look like at the bottom of
    the program?

9
Global Labels
  • Easy just use a

10
Saving and Restoring Registers
  • MASM makes it easy (though I /never/ use it)
  • USES Operator
  • ArraySum USES esi ecx
  • Would save esi and ecx and restore them at the
    end of the procedure
  • I prefer manually PUSHing and POPing, but hey,
    Im old fashioned
  • Lets modify NESTED.ASM and look in NTSD

11
Lets look at our first real program
  • Integer summation program with keyboard input

12
Assignment 3
  • You need to write a program that accepts strings
    from the keyboard - up to a maximum of 16
    strings. Each string can have a max length of 30
    characters. String entry should stop when the
    string done is entered.
  • The program should then sort these strings
    alphabetically and print them out in order
  • The program should be case insensitive to make it
    easier!
  • The printout show each string in a different
    color.
  • HINT This is just a bubblesort with a custom
    string comparison routine and a more complex swap
    function
Write a Comment
User Comments (0)
About PowerShow.com