1 / 19

Overview

Overview. Basic Elements of Assembly Language Sample Hello Program Assembling, Linking and Debugging Data Allocation Directives Symbolic Constants Data Transfer Instructions Arithmetic Instructions Basic Operand Types. Basic Elements of Assembly Language. Constants and Expressions

hiram-case
Download Presentation

Overview

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. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Overview • Basic Elements of Assembly Language • Sample Hello Program • Assembling, Linking and Debugging • Data Allocation Directives • Symbolic Constants • Data Transfer Instructions • Arithmetic Instructions • Basic Operand Types Irvine: Assembly Language for Intel-Based Computers (1999)

  2. Basic Elements of Assembly Language • Constants and Expressions • Numeric Literals • Character or String constant • Statements • Names • Labels for Variables • Code Labels Irvine: Assembly Language for Intel-Based Computers (1999)

  3. Numeric Literals (Constants) • A numeric literal is any combination of digits, plus: • optional decimal point, exponent, sign • examples of decimal literals: 5234 5.5 -5.5 26.0E+05 +35d Irvine: Assembly Language for Intel-Based Computers (1999)

  4. Numeric Literals • Use a radix symbol (suffix) to select binary, octal, decimal, or hexadecimal 6A15h ; hexadecimal 0BAF1h ; leading zero required 32q ; octal 1011b ; binary 35d ; decimal (default) Irvine: Assembly Language for Intel-Based Computers (1999)

  5. Symbolic Constant (Integer) • Defined using the = operator • Must evaluate to a 16-bit integer • or 32-bit integer when .386 directive used COUNT = 25 ROWS = 10 tablePos = ROWS * 5 Irvine: Assembly Language for Intel-Based Computers (1999)

  6. Constant Expression • Combination of numeric literals, operators, and defined symbolic constants • must be evaluated at assembly time • examples: 4 * 20 -3 * 4 / 6 ROWS - 3 ; (ROWS is a constant) COUNT MOD 5 Irvine: Assembly Language for Intel-Based Computers (1999)

  7. Statements • Label, mnemonic, operands, comment • one statement per line • name and comment are optional • operands depend on the instruction • Example.... Irvine: Assembly Language for Intel-Based Computers (1999)

  8. Statement Example mnemonic Operands Label ; Code Here: mov ax,count ; Data, using DW directive myArray dw 1000h,2000h dw 3000h,4000h Comment Data name Irvine: Assembly Language for Intel-Based Computers (1999)

  9. The Hello World Program • title Hello World Program         (hello.asm) • ; This program displays “Hello, world!” • .model small • .stack 100h • .data • message db “Hello, world!”,0dh,0ah,’$’ • .code • main proc •     mov  ax,@data •     mov  ds,ax •     mov  ah,9 •     mov  dx,offset message •     int  21h •     mov  ax,4C00h •     int  21h • main endp • end main Irvine: Assembly Language for Intel-Based Computers (1999)

  10. Sample Hello Program program title (comment) • title Hello World Program         (hello.asm) • ; This program displays “Hello, world!” • .model small • .stack 100h comment line memory model set the stack size Irvine: Assembly Language for Intel-Based Computers (1999)

  11. Sample Hello Program starts the data segment • .data • message db “Hello, world!”,0dh,0ah,’$’ • .code • main proc •     mov  ax,@data •     mov  ds,ax •     mov  ah,9 •     mov  dx,offset message •     int  21h •     mov  ax,4C00h •     int  21h • main endp • end main starts the code segment sets DS to the offset of the data segment calls DOS display function 9 halts program Irvine: Assembly Language for Intel-Based Computers (1999)

  12. Common Assembler Directives Irvine: Assembly Language for Intel-Based Computers (1999)

  13. Assemble-Link-Execute Cycle Irvine: Assembly Language for Intel-Based Computers (1999)

  14. Files Created by the Assembler and Linker Irvine: Assembly Language for Intel-Based Computers (1999)

  15. Data Allocation Directives Irvine: Assembly Language for Intel-Based Computers (1999)

  16. Define Byte (DB) • Create data having a byte attribute • one or more bytes may be defined together • can mix different data representations • can assign a starting value .data char1 db 'A' signed1 db -128 combo db 'A',-10, 30h, 40q, 1101b list db 10,20,30,40 aString db "Hello there",0 count db ? ; uninitialized Irvine: Assembly Language for Intel-Based Computers (1999)

  17. DUP Operator • Use DUP to create an array • each element is assigned the same value .data arrayB db 30 dup(10h) array2 db 10 DUP(?) ; uninitialized array3 db 5 Dup(0), 33h Irvine: Assembly Language for Intel-Based Computers (1999)

  18. Define Word (DW) • Create data having a word attribute • can mix different data representations • can use integer expressions • can contain 16-bit offset of another variable .data wordVal dw 1234h,5000h,65535, -24 signed1 db 35 * 4 aString dw "AB" ptr1 dw offset wordval Irvine: Assembly Language for Intel-Based Computers (1999)

  19. Define Doubleword (DD) • Create one or more 32-bit integers • doubleword attribute .data largeVal dd 12345678h array dd 100 dup(?) smallVals dd -1,-2,-3,-4,-5 Irvine: Assembly Language for Intel-Based Computers (1999)

More Related