csci 2510 tutorial 3 a tutorial3 x86basics program in assembly language n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
CSCI 2510 Tutorial 3 A “Tutorial3_x86Basics” Program in Assembly Language PowerPoint Presentation
Download Presentation
CSCI 2510 Tutorial 3 A “Tutorial3_x86Basics” Program in Assembly Language

Loading in 2 Seconds...

play fullscreen
1 / 15

CSCI 2510 Tutorial 3 A “Tutorial3_x86Basics” Program in Assembly Language - PowerPoint PPT Presentation


  • 131 Views
  • Uploaded on

CSCI 2510 Tutorial 3 A “Tutorial3_x86Basics” Program in Assembly Language. ZONG Wen Department of Computer Science and Engineering The Chinese University of Hong Kong wzong@cse.cuhk.edu.hk. Main topic:. 1, IA-32 Manuals 2, Tutorial3_x86Basics 3, Assembly Language Syntax

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'CSCI 2510 Tutorial 3 A “Tutorial3_x86Basics” Program in Assembly Language' - burian


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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
csci 2510 tutorial 3 a tutorial3 x86basics program in assembly language

CSCI 2510 Tutorial 3A “Tutorial3_x86Basics” Program in Assembly Language

ZONG Wen

Department of Computer Science and Engineering

The Chinese University of Hong Kongwzong@cse.cuhk.edu.hk

main topic

Main topic:

1, IA-32 Manuals

2, Tutorial3_x86Basics

3, Assembly Language Syntax

4, Related links and exercises

ia 32 manuals
IA-32Manuals
  • Volume 1: Basic Architecture
  • Volume 2A: Instruction Set Reference, A-M
  • Volume 2B: Instruction Set Reference, N-Z
tutorial3 x86basics
Tutorial3_x86Basics
  • Download Tutorial3_x86Basics.zip
    • http://www.cse.cuhk.edu.hk/csci2510
tutorial3 x86basics1
Tutorial3_x86Basics
  • Extract Tutorial3_x86Basics.zip
  • Open Tutorial3_x86Basics.sln (Visual Studio Solution file) in Visual C++ 2008
  • Press F7 to Build Solution (assemble)
    • Antivirus software may need to be temporarily shutdown to avoid false alarm
  • Add a Break Point . Press F10 to Start Debugging
  • Right click onEditor Window (assembly code,) click “Go to Disassembly”
tutorial3 x86basics2
Tutorial3_x86Basics
  • View the values of variables in Registers, Memory 1 and Watch windows.(in Debug->Window)
assembly language syntax
AssemblyLanguageSyntax
  • .686
    • Target processor. Use instructions for Pentium class machines.
  • .MODEL FLAT, StdCall
    • Use the flat memory model. Use Standard calling conventions.
  • .DATA
    • Create a near data segment. Local variables are declared after this directive.
  • .CODE
    • Indicates the start of a code segment.
assembly language syntax1
AssemblyLanguageSyntax
  • option casemap:none
    • Case sensitive to avoid messing up function names.
  • include include\msvcrt.inc
  • includeliblib\msvcrt.lib
    • Include external library function definitions.
    • MicroSoftVisual C RunTime
assembly language syntax2
AssemblyLanguageSyntax
  • ; comment line
  • main PROC ; begin of procedure
  • label1: ; define an address label
  • jmp label1 ; jump to label1, i.e., infinite loop!
  • main ENDP ; end of procedure
  • times2 PROC ; begin of procedure
  • shl eax, 1 ; shift left by 1 bit, i.e., multiply by 2 in binary!
  • ret ; return
  • times2 ENDP ; end of procedure
  • END times2 ;end of this assembly file AND define entry point
assembly language syntax3
AssemblyLanguageSyntax
  • DB, DW, DWORD, DQ
    • Define 1-byte, 2-byte, 4-byte, 8-byte data items.
    • Intel uses little-endian, i.e. the least significant byte of a word is stored at its lowest address.
  • Examples:
  • SINGLEBYTE DB12h
  • TWOBYTEDW1234h
  • FOURBYTE DWORD12345678h
  • EIGHTBYTE DQ123456789abcdef0h
assembly language syntax4
AssemblyLanguageSyntax
  • Use DB to define a string, ended with 0 (null terminator)
    • HELLODB"Hello world!", 0
    • FORMATDB"ebx = %d (base 10)", 10, 0
    • ASCII code of new-line is 10, \n is NOT supported!
  • SIXBYTE DB6 DUP(99h)
    • Define 6 bytes, with 99h as the content of each byte
    • n DUP(X) means duplicate X n times
  • PI EQU 3.14159
  • MYREG EQU eax
    • Symbolic constants for MASM substitution
assembly language syntax6
AssemblyLanguageSyntax
  • moveax, 0a34abcdfh;eax = 0a34abcdfh
  • xoreax, eax ;eax = 0
  • addMYREG, ebx ;eax = eax + ebx
  • Refer to x86Basic.asm for more details and examples.
related link
Relatedlink
  • Intel® 64 and IA-32 Architectures Software Developer's Manuals:
    • http://www.intel.com/products/processor/manuals/
exercises
Exercises
  • Define two 32-bit integers in data segment, compute their average (floored to integer), and use crt_printf() to output the result.
  • Try to use crt_scanf() to read a 32-bit integer from user, multiply it by 2, and output the result.