Docsity

Assembly language basics, Slides of Computer Science

Toggle sidebar
bg1
Assembly Language for Intel-Based
Assembly Language for Intel-Based
Computers, 4
Computers, 4th
th Edition
Edition
Chapter 3: Assembly Language
Fundamentals
(c) Pearson Education, 2002. All rights reserved. You may modify and copy this slide show for your personal use, or
for use in the classroom, as long as this copyright statement, the author's name, and the title are not changed.
•Chapter corrections (Web) Assembly language sources (Web)
Slides prepared by Kip R. Irvine
Revision date: 09/15/2002
Kip R. Irvine
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33

Partial preview of the text

Download Assembly language basics and more Slides Computer Science in PDF only on Docsity!

Assembly Language for Intel-BasedAssembly Language for Intel-Based

Computers, 4 Computers, 4

thth^

EditionEdition

Chapter 3: Assembly Language

Fundamentals

(c) Pearson Education, 2002. All rights reserved. You may modify and copy this slide show for your personal use, or for use in the classroom, as long as this copyright statement, the author's name, and the title are not changed.

  • (^) Chapter corrections (Web) Assembly language sources (Web) Slides prepared by Kip R. Irvine Revision date: 09/15/ Kip R. Irvine

Chapter Overview Chapter Overview

  • (^) Basic Elements of Assembly Language
  • (^) Example: Adding and Subtracting Integers
  • (^) Assembling, Linking, and Running Programs
  • (^) Defining Data
  • (^) Symbolic Constants
  • (^) Real-Address Mode Programming

Integer Constants Integer Constants

  • (^) Optional leading + or – sign
  • (^) binary, decimal, hexadecimal, or octal digits
  • (^) Common radix characters:
    • (^) h – hexadecimal
    • (^) d – decimal
    • (^) b – binary
    • (^) r – encoded real

Examples: 30d, 6Ah, 42, 1101b

Hexadecimal beginning with letter: 0A5h

Integer Expressions Integer Expressions

  • (^) Operators and precedence levels:
  • (^) Examples:

Reserved Words and Identifiers Reserved Words and Identifiers

  • (^) Reserved words (Appendix D) cannot be used as

identifiers

  • (^) Instruction mnemonics, directives, type attributes, operators, predefined symbols
  • (^) Identifiers
  • (^) 1-247 characters, including digits
  • (^) case insensitive (by default)
  • (^) first character must be a letter, _, @, or $
  • (^) Directives
  • command understood by the assembler
  • (^) not part of Intel instruction set
  • (^) case insensitive

Directives Directives

  • (^) Commands that are recognized and acted

upon by the assembler

  • (^) Not part of the Intel instruction set
  • (^) Used to declare code, data areas, select memory model, declare procedures, etc.
  • (^) Different assemblers have different directives
  • (^) NASM != MASM, for example

Labels Labels

  • (^) Act as place markers
    • (^) marks the address (offset) of code and data
  • (^) Follow identifer rules
  • (^) Data label
    • (^) must be unique
    • (^) example: myArray (not followed by colon)
  • (^) Code label
    • (^) target of jump and loop instructions
    • (^) example: L1: (followed by colon)

Mnemonics and Operands Mnemonics and Operands

  • (^) Instruction Mnemonics
    • (^) "reminder"
    • (^) examples: MOV, ADD, SUB, MUL, INC, DEC
  • (^) Operands
    • (^) constant (immediate value)
    • (^) constant expression
    • (^) register
    • (^) memory (data label)

Instruction Format Examples Instruction Format Examples

  • (^) No operands
    • (^) stc ; set Carry flag
  • (^) One operand
    • (^) inc eax ; register
    • (^) inc myByte ; memory
  • (^) Two operands
    • (^) add ebx,ecx ; register, register
    • (^) sub myByte,25 ; memory, constant
    • (^) add eax,36 * 25 ; register, constant- expression

Example: Adding and Subtracting Integers Example: Adding and Subtracting Integers

TITLE Add and Subtract (AddSub.asm) ; This program adds and subtracts 32-bit integers. INCLUDE Irvine32.inc .code main PROC mov eax,10000h ; EAX = 10000h add eax,40000h ; EAX = 50000h sub eax,20000h ; EAX = 30000h call DumpRegs ; display registers exit main ENDP END main

Suggested Coding Standards Suggested Coding Standards (1 of 2)(1 of 2)

  • (^) Some approaches to capitalization
    • (^) capitalize nothing
    • (^) capitalize everything
    • (^) capitalize all reserved words, including instruction mnemonics and register names
    • (^) capitalize only directives and operators
  • (^) Other suggestions
    • (^) descriptive identifier names
    • (^) spaces surrounding arithmetic operators
    • (^) blank lines between procedures

Suggested Coding Standards Suggested Coding Standards (2 of 2)(2 of 2)

  • (^) Indentation and spacing
    • (^) code and data labels – no indentation
    • (^) executable instructions – indent 4-5 spaces
    • (^) comments: begin at column 40-45, aligned vertically
    • (^) 1-3 spaces between instruction and its operands
      • (^) ex: mov ax,bx
    • (^) 1-2 blank lines between procedures

Program Template Program Template

TITLE Program Template (Template.asm) ; Program Description: ; Author: ; Creation Date: ; Revisions: ; Date: Modified by: INCLUDE Irvine32.inc .data ; (insert variables here) .code main PROC ; (insert executable instructions here) exit main ENDP ; (insert additional procedures here) END main Instructors: please customize as needed

Assembling, Linking, and Running Programs Assembling, Linking, and Running Programs

  • (^) Assemble-Link-Execute Cycle
  • (^) make32.bat
  • (^) Listing File
  • (^) Map File