Assembly Language for Intel-Based Computers, 4 th Edition Chapter 3: Assembly Language Fundamentals Assembling, Linking and Running Programs Example Programs.

Slides:



Advertisements
Similar presentations
Introduction to Assembly Language
Advertisements

Assembly Language for Intel-Based Computers, 4 th Edition Chapter 1: Basic Concepts (c) Pearson Education, All rights reserved. You may modify and.
Assembly Language for x86 Processors 6th Edition Chapter 5: Procedures (c) Pearson Education, All rights reserved. You may modify and copy this slide.
Assembly Language for x86 Processors 6th Edition
Assembly Language for Intel-Based Computers, 5th Edition
CS2422 Assembly Language and System Programming Assembly Language Fundamentals Department of Computer Science National Tsing Hua University.
Assembly Language for Intel-Based Computers Chapter 15: BIOS-Level Programming (c) Pearson Education, All rights reserved. You may modify and.
Assembly Language for Intel-Based Computers, 4 th Edition Chapter 6: Conditional Processing (c) Pearson Education, All rights reserved. You may modify.
Assembly Language for Intel-Based Computers, 4 th Edition Chapter 7: Integer Arithmetic (c) Pearson Education, All rights reserved. You may modify.
Assembly Language for Intel-Based Computers Chapter 5: Procedures Kip R. Irvine.
Web siteWeb site ExamplesExamples Irvine, Kip R. Assembly Language for Intel-Based Computers, Symbolic Constants Equal-Sign Directive Calculating.
Outline Learning Assembly by an Example.  Program Formats  Some Simple Instructions  Assemble and Execute Learning Another Example  Data Definition.
Web siteWeb site ExamplesExamples Irvine, Kip R. Assembly Language for Intel-Based Computers, Intrinsic Data Types (1 of 2) BYTE, SBYTE 8-bit unsigned.
Assembly Language for Intel-Based Computers, 5 th Edition Chapter 3: Assembly Language Fundamentals (c) Pearson Education, All rights reserved.
Kip Irvine: Assembly Language for Intel-Based Computers Overview Stack Operations (PUSH and POP) Procedures Procedure Parameters Software Interrupts MS-DOS.
Assembly Language for Intel-Based Computers, 4th Edition
Assembly Language for Intel-Based Computers Chapter 3: Assembly Language Fundamentals Kip Irvine.
Assembly Language for Intel-Based Computers Chapter 13: 16-Bit MS-DOS Programming Kip R. Irvine.
Assembly programming A little background on using the software.
Assembly Language for Intel-Based Computers, 4 th Edition Chapter 13: 16-Bit MS-DOS Programming (c) Pearson Education, All rights reserved. You may.
Assembly Language for Intel-Based Computers Chapter 16: Expert MS-DOS Programming (c) Pearson Education, All rights reserved. You may modify.
Assembly Language for Intel-Based Computers, 4 th Edition Chapter 5: Procedures (c) Pearson Education, All rights reserved. You may modify and copy.
Assembly Language for Intel-Based Computers, 5 th Edition Chapter 1: Basic Concepts (c) Pearson Education, All rights reserved. You may modify.
Assembly Language for Intel-Based Computers, 4 th Edition Lecture 23: Finite State Machines, WHILE operator (c) Pearson Education, All rights reserved.
Assembly Language for Intel-Based Computers, 4 th Edition Chapter 3: Assembly Language Fundamentals (c) Pearson Education, All rights reserved. You.
Web siteWeb site ExamplesExamples Irvine, Kip R. Assembly Language for Intel-Based Computers, Defining and Using Procedures Creating Procedures.
CS2422 Assembly Language & System Programming September 26, 2006.
Chapter 2 Software Tools and Assembly Language Syntax.
ICS312 Set 4 Program Structure. Outline for a SMALL Model Program Note the quiz at the next lecture will be to reproduce this slide.MODEL SMALL.586 ;
Assembly Language for Intel-Based Computers, 4 th Edition Chapter 2: IA-32 Processor Architecture (c) Pearson Education, All rights reserved. You.
Assembly Language for Intel-Based Computers, 5 th Edition Chapter 13: 16-Bit MS-DOS Programming (c) Pearson Education, All rights reserved.
Chapter 3: Assembly Language Fundamentals
Assembly Fundamentals Computer Organization and Assembly Languages Yung-Yu Chuang 2005/10/13 with slides by Kip Irvine.
Assembly Language for x86 Processors 7th Edition
Assembly Language for x86 Processors 6th Edition Chapter 3: Assembly Language Fundamentals (c) Pearson Education, All rights reserved. You may modify.
Assembly Language for Intel-Based Computers, 5 th Edition Chapter 3: Assembly Language Fundamentals (c) Pearson Education, All rights reserved.
Assembly Language for Intel-Based Computers, 5 th Edition Chapter 3: Assembly Language Fundamentals (c) Pearson Education, All rights reserved.
Assembly Language for Intel-Based Computers, 5 th Edition Chapter 13: 16-Bit MS-DOS Programming (c) Pearson Education, All rights reserved.
Assembly Language for x86 Processors 6th Edition
BIOS and DOS Programming in DOS INT 10 and 21H. Interrupts There are some extremely useful subroutines within BIOS or DOS that are available to the user.
Assembly Language for Intel-Based Computers, 6 th Edition Chapter 8: Advanced Procedures (c) Pearson Education, All rights reserved. You may.
Assembly Language for Intel-Based Computers Chapter 13: 16-Bit MS-DOS Programming Kip R. Irvine.
Summer 2014 Chapter 3: Assembly Language Fundamentals.
Assembly Language for Intel-Based Computers Chapter 7: Integer Arithmetic (c) Pearson Education, All rights reserved. You may modify and copy.
Assembly Language for x86 Processors 7th Edition Chapter 13: High-Level Language Interface (c) Pearson Education, All rights reserved. You may modify.
Assembly Language for Intel-Based Computers, 4 th Edition Unpacked and Packed Integers (c) Pearson Education, All rights reserved. You may modify.
Assembly Language for Intel-Based Computers, 5 th Edition Chapter 10: Structures and Macros (c) Pearson Education, All rights reserved. You.
In Class Program Write, assemble and test a program: –Use the DB directive to define the following list of numbers and name it array: 31h, 32h, 33h, 34h.
Chapter Bit MS-DOS Programming Assembly Language for Intel-Based Computers, 4th edition Kip R. Irvine.
Assembly Language for Intel-Based Computers, 4 th Edition Chapter 5: Procedures Lecture 18 Linking to External Library The Book’s Link Library Stack Operations.
Assembly Language for Intel-Based Computers, 4 th Edition Chapter 5: Procedures Lecture 19: Procedures Procedure’s parameters (c) Pearson Education, 2002.
Assembly Language for Intel-Based Computers, 4 th Edition Chapter 13: 16-Bit MS-DOS Programming Interrupts (c) Pearson Education, All rights reserved.
Assembly Language for x86 Processors 6th Edition Chapter 3: Assembly Language Fundamentals (c) Pearson Education, All rights reserved. You may modify.
CSC 221 Computer Organization and Assembly Language Lecture 16: Procedures.
Assembly Language for Intel-Based Computers, 4 th Edition Chapter 2: IA-32 Processor Architecture (c) Pearson Education, All rights reserved. You.
Assembly Language for Intel-Based Computers, 4 th Edition Lecture 22: Conditional Loops (c) Pearson Education, All rights reserved. You may modify.
CS2422 Assembly Language and System Programming 0 Week 7 & 8 Intro. To Assembly Programming.
Assembly Language for Intel-Based Computers, 4 th Edition Chapter 3: Assembly Language Fundamentals (c) Pearson Education, All rights reserved. You.
Assembly Language for x86 Processors 6th Edition
1st prog! Q: Read a char – from a keyboard & display it at the beginning of the next line! ====== A.
Assembly Language Fundamentals
Microprocessor and Assembly Language
Assembly Language for Intel-Based Computers, 5th Edition
Assembly Language for Intel-Based Computers, 4th Edition
Assembly Language for Intel-Based Computers
Symbolic Instruction and Addressing
Assembly Language for Intel-Based Computers, 5th Edition
Unit:08 Software Interrupts
Hardware & Software Architecture
Presentation transcript:

Assembly Language for Intel-Based Computers, 4 th Edition Chapter 3: Assembly Language Fundamentals Assembling, Linking and Running Programs Example Programs (c) Pearson Education, 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)Chapter correctionsAssembly language sources Slides prepared by Kip R. Irvine Revision date: 09/15/2002 Modified by Dr. Nikolay Metodiev Sirakov Kip R. Irvine

Web siteWeb site ExamplesExamples Irvine, Kip R. Assembly Language for Intel-Based Computers, Example: Adding and Subtracting Integers TITLE Add and Subtract (AddSub.asm) ; Program Description: This program adds and subtracts 32-bit integers. ; Author: ; Creation Date: ; Revisions: ; Date: Modified by: 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

Web siteWeb site ExamplesExamples Irvine, Kip R. Assembly Language for Intel-Based Computers, Example Output Program output, showing registers and flags: EAX= EBX=7FFDF000 ECX= EDX=FFFFFFFF ESI= EDI= EBP=0012FFF0 ESP=0012FFC4 EIP= EFL= CF=0 SF=0 ZF=0 OF=0

Web siteWeb site ExamplesExamples Irvine, Kip R. Assembly Language for Intel-Based Computers, Suggested Coding Standards (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

Web siteWeb site ExamplesExamples Irvine, Kip R. Assembly Language for Intel-Based Computers, Suggested Coding Standards (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

Web siteWeb site ExamplesExamples Irvine, Kip R. Assembly Language for Intel-Based Computers, Alternative Version of AddSub TITLE Add and Subtract (AddSubAlt.asm) ; This program adds and subtracts 32-bit integers..386.MODEL flat,stdcall.STACK 4096 ExitProcess PROTO, dwExitCode:DWORD DumpRegs PROTO.code main PROC mov eax,10000h; EAX = 10000h add eax,40000h; EAX = 50000h sub eax,20000h; EAX = 30000h call DumpRegs INVOKE ExitProcess,0 main ENDP END main

Web siteWeb site ExamplesExamples Irvine, Kip R. Assembly Language for Intel-Based Computers, 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

Web siteWeb site ExamplesExamples Irvine, Kip R. Assembly Language for Intel-Based Computers, Assembling, Linking, and Running Programs Assemble-Link-Execute Cycle make32.bat Listing File Map File

Web siteWeb site ExamplesExamples Irvine, Kip R. Assembly Language for Intel-Based Computers, Assemble-Link Execute Cycle The following diagram describes the steps from creating a source program through executing the compiled program. If the source code is modified, Steps 2 through 4 must be repeated.

Web siteWeb site ExamplesExamples Irvine, Kip R. Assembly Language for Intel-Based Computers, make32.bat Called a batch file Run it to assemble and link programs Contains a command that executes ML.EXE (the Microsoft Assembler) Contains a command that executes LINK32.EXE (the 32-bit Microsoft Linker) Command-Line syntax: make32 progName (progName does not include the.asm extension) Use make16.bat to assemble and link Real-mode programs

Web siteWeb site ExamplesExamples Irvine, Kip R. Assembly Language for Intel-Based Computers, Listing File Use it to see how your program is compiled Contains source code addresses object code (machine language) segment names symbols (variables, procedures, and constants) Example: addSub.lstaddSub.lst

Web siteWeb site ExamplesExamples Irvine, Kip R. Assembly Language for Intel-Based Computers, Listing File, AddSub Listing File_AddSubC – AddSubC.LST Listing File_AddSub - AddSub.LST Listing File_AddSub32 – AddSub32.LST

Web siteWeb site ExamplesExamples Irvine, Kip R. Assembly Language for Intel-Based Computers, Map File Information about each program segment: starting address ending address size segment type Example: addSub.mapaddSub.map

Web siteWeb site ExamplesExamples Irvine, Kip R. Assembly Language for Intel-Based Computers, Add and Subtract, 16-Bit Version, Variables TITLE Add and Subtract, Version 2 (AddSub2.asm) INCLUDE Irvine16.inc.data val1 DWORD 10000h val2 DWORD 40000h val3 DWORD 20000h finalVal DWORD ?.code main PROC mov initialize DS mov ds,ax mov eax,val1; get first value add eax,val2; add second value sub eax,val3; subtract third value mov finalVal,eax; store the result call DumpRegs; display registers exit main ENDP END main

Web siteWeb site ExamplesExamples Irvine, Kip R. Assembly Language for Intel-Based Computers, Add and Subtract, 32-Bit Version, Variables TITLE Add and Subtract, Version 2 (AddSub2.asm) INCLUDE Irvine32.inc.data val1 DWORD 10000h val2 DWORD 40000h val3 DWORD 20000h finalVal DWORD ?.code main PROC mov eax,val1; get first value add eax,val2; add second value sub eax,val3; subtract third value mov finalVal,eax; store the result call DumpRegs; display registers exit main ENDP END main

Web siteWeb site ExamplesExamples Irvine, Kip R. Assembly Language for Intel-Based Computers, Redirecting Input-Output (2 of 2) Standard input, standard output can both be redirected Standard error cannot be redirected Suppose we have created a program named myprog.exe that reads from standard input and writes to standard output. Following are MS-DOS commands that demonstrate various types of redirection: myprog < infile.txt myprog > outfile.txt myprog outfile.txt

Web siteWeb site ExamplesExamples Irvine, Kip R. Assembly Language for Intel-Based Computers, INT Instruction The INT instruction executes a software interrupt. The code that handles the interrupt is called an interrupt handler. Syntax: INT number (number = 0..FFh) The Interrupt Vector Table (IVT) holds a 32-bit segment- offset address for each possible interrupt handler. Interrupt Service Routine (ISR) is another name for interrupt handler.

Web siteWeb site ExamplesExamples Irvine, Kip R. Assembly Language for Intel-Based Computers, Interrupt Vectoring Process

Web siteWeb site ExamplesExamples Irvine, Kip R. Assembly Language for Intel-Based Computers, Common Interrupts INT 10h Video Services INT 16h Keyboard Services INT 17h Printer Services INT 1Ah Time of Day INT 1Ch User Timer Interrupt INT 21h MS-DOS Services

Web siteWeb site ExamplesExamples Irvine, Kip R. Assembly Language for Intel-Based Computers, MS-DOS Function Calls (INT 21h) Page 465 ASCII Control Characters Selected Output Functions Selected Input Functions Example: String Encryption Date/Time Functions

Web siteWeb site ExamplesExamples Irvine, Kip R. Assembly Language for Intel-Based Computers, ASCII Control Characters 08h - Backspace (moves one column to the left) 09h - Horizontal tab (skips forward n columns) 0Ah - Line feed (moves to next output line) 0Ch - Form feed (moves to next printer page) 0Dh - Carriage return (moves to leftmost output column) 1Bh - Escape character Many INT 21h functions act upon the following control characters:

Web siteWeb site ExamplesExamples Irvine, Kip R. Assembly Language for Intel-Based Computers, INT 21h Function 09h: Write String to Standard Output.data string BYTE "This is a string$".code mov ah,9 mov dx,OFFSET string int 21h The string must be terminated by a '$' character. DS must point to the string's segment, and DX must contain the string's offset:

Web siteWeb site ExamplesExamples Irvine, Kip R. Assembly Language for Intel-Based Computers, Selected Input Functions 01h, 06h - Read character from standard input 0Ah - Read array of buffered characters from standard input 0Bh - Get status of the standard input buffer 3Fh - Read from file or device

Web siteWeb site ExamplesExamples Irvine, Kip R. Assembly Language for Intel-Based Computers, INT 21h Function 0Ah: Read buffered array from standard input –Page 469 count = 80 KEYBOARD STRUCT maxInput BYTE count; max chars to input inputCount BYTE ?; actual input count buffer BYTE count DUP(?); holds input chars KEYBOARD ENDS Requires a predefined structure to be set up that describes the maximum input size and holds the input characters. Example:

Web siteWeb site ExamplesExamples Irvine, Kip R. Assembly Language for Intel-Based Computers, INT 21h Function 0Ah.data kybdData KEYBOARD <>.code mov ah,0Ah mov dx,OFFSET kybdData int 21h Executing the interrupt:

Web siteWeb site ExamplesExamples Irvine, Kip R. Assembly Language for Intel-Based Computers, INT 21h Function 2Ah: Get system date mov ah,2Ah int 21h mov year,cx mov month,dh mov day,dl mov dayOfWeek,al Returns year in CX, month in DH, day in DL, and day of week in AL

Web siteWeb site ExamplesExamples Irvine, Kip R. Assembly Language for Intel-Based Computers, INT 21h Function 2Ch: Get system time mov ah,2Ch int 21h mov hours,ch mov minutes,cl mov seconds,dh Returns hours (0-23) in CH, minutes (0-59) in CL, and seconds (0-59) in DH, and hundredths (0-99) in DL.

Web siteWeb site ExamplesExamples Irvine, Kip R. Assembly Language for Intel-Based Computers, Example Programs TITLE Display the Date and Time Read, display, and copy a text file