ASSEMBLY LANGUAGE FOR INTEL-BASED COMPUTERS, PROCEDURES.

Slides:



Advertisements
Similar presentations
Assembly Language for Intel-Based Computers, 4 th Edition Chapter 1: Basic Concepts (c) Pearson Education, All rights reserved. You may modify and.
Advertisements

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 Intel-Based Computers, 4 th Edition Chapter 5: Procedures (c) Pearson Education, All rights reserved. You may modify and copy.
Important Irvine Library Procedures Randomize Randomize –Initializes the seed of the random-number formula by both the Random32 and the RandomRange procedures.
Assembly Language for Intel-Based Computers Chapter 15: BIOS-Level Programming (c) Pearson Education, All rights reserved. You may modify and.
Assembly Language Procedures.
Assembly Language for x86 Processors 6th Edition
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 Chapter 5: Procedures Kip R. Irvine.
Runtime Stack Managed by the CPU, using two registers
Outline Learning Assembly by an Example.  Program Formats  Some Simple Instructions  Assemble and Execute Learning Another Example  Data Definition.
Assembly Language for Intel-Based Computers, 4 th Edition Chapter 5: Procedures (c) Pearson Education, All rights reserved. You may modify and copy.
Libraries and Procedures
Assembly Language for Intel-Based Computers, 5 th Edition Chapter 5: Procedures (c) Pearson Education, All rights reserved. You may modify and copy.
CS2422 Assembly Language and System Programming Procedures Department of Computer Science National Tsing Hua University.
Assembly Language for Intel-Based Computers, 4th Edition
Assembly Language for Intel-Based Computers Chapter 2: IA-32 Processor Architecture Kip Irvine.
Assembly Language for Intel-Based Computers, 5 th Edition Chapter 1: Basic Concepts (c) Pearson Education, All rights reserved. You may modify.
Assembly Language Basic Concepts IA-32 Processor Architecture.
Assembly programming A little background on using the software.
Kip Irvine: Assembly Language for Intel-Based Computers
Table 1. Software Hierarchy Levels.. Essential Tools An assembler is a program that converts source-code programs into a machine language (object file).
Assembly Language for Intel-Based Computers, 4 th Edition Chapter 5: Procedures (c) Pearson Education, All rights reserved. You may modify and copy.
CS2422 Assembly Language & System Programming October 31, 2006.
CS2422 Assembly Language & System Programming October 24, 2006.
Assembly Language for Intel-Based Computers, 5 th Edition Chapter 1: Basic Concepts (c) Pearson Education, All rights reserved. You may modify.
Irvine, Kip R. Assembly Language For Intel-Based Computers XADD Instruction.code mov ax,1000h mov bx,2000h ; AX = 1000h, BX = 2000h xadd ax,bx ; AX = 3000h,
Coding.
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.
Web siteWeb site ExamplesExamples Irvine, Kip R. Assembly Language for Intel-Based Computers, Stack Operations Runtime Stack PUSH Operation POP.
CS2422 Assembly Language & System Programming September 26, 2006.
Chapter 2 Software Tools and Assembly Language Syntax.
Assembly Language for Intel-Based Computers, 5 th Edition Chapter 1: Basic Concepts (c) Pearson Education, All rights reserved. You may modify.
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 ;
Sahar Mosleh California State University San MarcosPage 1 Applications of Shift and Rotate Instructions.
Assembly Language for Intel-Based Computers, 5 th Edition Chapter 5: Procedures (c) Pearson Education, All rights reserved. You may modify and copy.
Summer 2014 Chapter 1: Basic Concepts. Irvine, Kip R. Assembly Language for Intel-Based Computers 6/e, Chapter Overview Welcome to Assembly Language.
Assembly Language for x86 Processors 7th Edition
Assembly Language for Intel-Based Computers, 4 th Edition Chapter 3: Assembly Language Fundamentals Assembling, Linking and Running Programs Example Programs.
Chapter 3 Elements of Assembly Language. 3.1 Assembly Language Statements.
Assembly Language for x86 Processors 6th Edition Chapter 5: Procedures (c) Pearson Education, All rights reserved. You may modify and copy this slide.
Functions available for Writing to the Video Display Three different ways to write to the display –Irvine library functions –DOS Video Functions (Interrupt.
Assembly Language for Intel-Based Computers, 6th Edition Chapter 5: Procedures (c) Pearson Education, All rights reserved. You may modify and copy.
Assembly Language for x86 Processors 7th Edition
File I/O MS-DOS Interrupt 21h has many functions dealing with file and directory I/O services. Both MS-DOS and MS_Windows use 16- bit integers called HANDLES.
Sahar Mosleh California State University San MarcosPage 1 Nested Procedure calls and Flowcharts.
Binary Number Output To display a number in binary format, a program looks at each bit in the number and sends the ASCII equivalent of a ‘1’ (31h) or a.
CT215: Assembly Language Programming Chapter 10: Macros (c) Pearson Education, All rights reserved. You may modify and copy this slide show for your.
Computer Organization and Assembly Languages Yung-Yu Chuang 2006/11/13
Assembly Language for Intel-Based Computers, 5 th Edition Chapter 10: Structures and Macros (c) Pearson Education, All rights reserved. You.
Assembly Language for Intel-Based Computers, 5 th Edition Chapter 5: Procedures (c) Pearson Education, All rights reserved. You may modify and copy.
CHAPTER 5: PROCEDURES ASSEMBLY LANGUAGE FOR INTEL- BASED COMPUTERS, 5 TH EDITION (c) Pearson Education, All rights reserved. You may modify and copy.
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, 5 th Edition Chapter 5: Procedures (c) Pearson Education, All rights reserved. You may modify and copy.
Assembly Language for Intel-Based Computers, 4 th Edition Chapter 5: Procedures Lecture 19: Procedures Procedure’s parameters (c) Pearson Education, 2002.
Procedure Computer Organization and Assembly Languages Yung-Yu Chuang 2005/10/27 with slides by Kip Irvine.
Libraries and Procedures COE 205 Computer Organization and Assembly Language Computer Engineering Department King Fahd University of Petroleum and Minerals.
CSC 221 Computer Organization and Assembly Language Lecture 16: Procedures.
Assembly Language for Intel-Based Computers, 4 th Edition Chapter 5: Procedures (c) Pearson Education, All rights reserved. You may modify and copy.
3/10/2003 Lecture 9: Procedures Assembly Language for Intel-Based Computers 4th edition Kip R. Irvine.
Assembly Language for x86 Processors 6th Edition
Assembly Language for x86 Processors 7th Edition
Chapter 5: Procedures.
Libraries and Procedures
Assembly Language for Intel-Based Computers, 4th Edition
The Stack and Procedures
More on operators and procedures in the Linked
Computer Architecture and System Programming Laboratory
Presentation transcript:

ASSEMBLY LANGUAGE FOR INTEL-BASED COMPUTERS, PROCEDURES

Web siteWeb site ExamplesExamples CHAPTER OVERVIEW Linking to an External Library The Book's Link Library Stack Operations Defining and Using Procedures Program Design Using Procedures 2

Web siteWeb site ExamplesExamples THE BOOK'S LINK LIBRARY Link Library Overview Calling a Library Procedure Linking to a Library Library Procedures – Overview Six Examples 3

Web siteWeb site ExamplesExamples LINK LIBRARY OVERVIEW A file containing procedures that have been compiled into machine code constructed from one or more OBJ files To build a library,... start with one or more ASM source files assemble each into an OBJ file create an empty library file (extension.LIB) add the OBJ file(s) to the library file, using the Microsoft LIB utility 4 Take a quick look at Irvine32.asm by clicking on Examples at the bottom of this screen.

Web siteWeb site ExamplesExamples LINKING TO A LIBRARY Your programs link to Irvine32.lib using the linker command inside a batch file named make32.bat. Notice the two LIB files: Irvine32.lib, and kernel32.lib the latter is part of the Microsoft Win32 Software Development Kit (SDK) 5

Web siteWeb site ExamplesExamples WHAT'S NEXT Linking to an External Library The Book's Link Library Stack Operations Defining and Using Procedures Program Design Using Procedures 6

Web siteWeb site ExamplesExamples CALLING A LIBRARY PROCEDURE 7 INCLUDE Irvine32.inc.code mov eax,1234h; input argument call WriteHex; show hex number call Crlf; end of line Call a library procedure using the CALL instruction. Some procedures require input arguments. The INCLUDE directive copies in the procedure prototypes (declarations). The following example displays "1234" on the console:

Web siteWeb site ExamplesExamples LIBRARY PROCEDURES - OVERVIEW (1 OF 4) 8 CloseFile – Closes an open disk file Clrscr - Clears console, locates cursor at upper left corner CreateOutputFile - Creates new disk file for writing in output mode Crlf - Writes end of line sequence to standard output Delay - Pauses program execution for n millisecond interval DumpMem - Writes block of memory to standard output in hex DumpRegs – Displays general-purpose registers and flags (hex) GetCommandtail - Copies command-line args into array of bytes GetMaxXY - Gets number of cols, rows in console window buffer GetMseconds - Returns milliseconds elapsed since midnight

Web siteWeb site ExamplesExamples LIBRARY PROCEDURES - OVERVIEW (2 OF 4) 9 GetTextColor - Returns active foreground and background text colors in the console window Gotoxy - Locates cursor at row and column on the console IsDigit - Sets Zero flag if AL contains ASCII code for decimal digit (0–9) MsgBox, MsgBoxAsk – Display popup message boxes OpenInputFile – Opens existing file for input ParseDecimal32 – Converts unsigned integer string to binary ParseInteger32 - Converts signed integer string to binary

Web siteWeb site ExamplesExamples CONT.. Random32 - Generates 32-bit pseudorandom integer in the range 0 to FFFFFFFFh Randomize - Seeds the random number generator RandomRange - Generates a pseudorandom integer within a specified range ReadChar - Reads a single character from standard input 10

Web siteWeb site ExamplesExamples LIBRARY PROCEDURES - OVERVIEW (3 OF 4) 11 ReadFromFile – Reads input disk file into buffer ReadDec - Reads 32-bit unsigned decimal integer from keyboard ReadHex - Reads 32-bit hexadecimal integer from keyboard ReadInt - Reads 32-bit signed decimal integer from keyboard ReadKey – Reads character from keyboard input buffer ReadString - Reads string from standard input, terminated by [Enter]

Web siteWeb site ExamplesExamples CONT.. SetTextColor - Sets foreground and background colors of all subsequent console text output StrLength – Returns length of a string WaitMsg - Displays message, waits for Enter key to be pressed WriteBin - Writes unsigned 32-bit integer in ASCII binary format. WriteBinB – Writes binary integer in byte, word, or doubleword format WriteChar - Writes a single character to standard output 12

Web siteWeb site ExamplesExamples LIBRARY PROCEDURES - OVERVIEW (4 OF 4) 13 WriteDec - Writes unsigned 32-bit integer in decimal format WriteHex - Writes an unsigned 32-bit integer in hexadecimal format WriteHexB – Writes byte, word, or doubleword in hexadecimal format WriteInt - Writes signed 32-bit integer in decimal format WriteString - Writes null-terminated string to console window WriteToFile - Writes buffer to output file WriteWindowsMsg - Displays most recent error message generated by MS-Windows

Web siteWeb site ExamplesExamples EXAMPLE 1 14.code call Clrscr mov eax,500 call Delay call DumpRegs Clear the screen, delay the program for 500 milliseconds, and dump the registers and flags. EAX= EBX= ECX=000000FF EDX= ESI= EDI= EBP= E ESP=000000F6 EIP= EFL= CF=0 SF=1 ZF=0 OF=0 Sample output:

Web siteWeb site ExamplesExamples EXAMPLE 2 15.data str1 BYTE "Assembly language is easy!",0.code mov edx,OFFSET str1 call WriteString call Crlf Display a null-terminated string and move the cursor to the beginning of the next screen line.

Web siteWeb site ExamplesExamples EXAMPLE 2A 16.data str1 BYTE "Assembly language is easy!",0Dh,0Ah,0.code mov edx,OFFSET str1 call WriteString Display a null-terminated string and move the cursor to the beginning of the next screen line (use embedded CR/LF)

Web siteWeb site ExamplesExamples EXAMPLE 3 17 IntVal = 35.code mov eax,IntVal call WriteBin; display binary call Crlf call WriteDec; display decimal call Crlf call WriteHex; display hexadecimal call Crlf Display an unsigned integer in binary, decimal, and hexadecimal, each on a separate line Sample output:

Web siteWeb site ExamplesExamples EXAMPLE 4 18.data fileName BYTE 80 DUP(0).code mov edx,OFFSET fileName mov ecx,SIZEOF fileName – 1 call ReadString Input a string from the user. EDX points to the string and ECX specifies the maximum number of characters the user is permitted to enter. A null byte is automatically appended to the string.

Web siteWeb site ExamplesExamples EXAMPLE 5 19.code mov ecx,10; loop counter L1:mov eax,100; ceiling value call RandomRange; generate random int call WriteInt; display signed int call Crlf; goto next display line loop L1; repeat loop Generate and display ten pseudorandom signed integers in the range 0 – 99. Pass each integer to WriteInt in EAX and display it on a separate line.

Web siteWeb site ExamplesExamples EXAMPLE 6 20.data str1 BYTE "Color output is easy!",0.code mov eax,yellow + (blue * 16) call SetTextColor mov edx,OFFSET str1 call WriteString call Crlf Display a null-terminated string with yellow characters on a blue background. The background color is multiplied by 16 before being added to the foreground color.

Web siteWeb site ExamplesExamples EXAMPLE : RANDOM INTEGERS INCLUDE Irvine32.inc.code main PROC mov ecx,5; loop counter L1:mov eax,100; ceiling value call RandomRange; generate random int call WriteInt; display signed int call Crlf; goto next display line loop L1; repeat loop exit main ENDP END main 21