ELEC 242 Using Library Procedures

Similar documents
Experiment 3 3 Basic Input Output

INTRODUCTION. NOTE Some symbols used in this manual CL = Click Left CR = Click Right DCL = Double Click Left = Enter. Page 1

Experiment #5. Using BIOS Services and DOS functions Part 1: Text-based Graphics

Experiment N o 3 Segmentation and Addressing Modes

Experiment N o 3. Segmentation and Addressing Modes

The statement above assumes that the PCMAC.INC file is in the current directory. The full path of the file can also be given:

Islamic University Gaza Engineering Faculty Department of Computer Engineering ECOM 2125: Assembly Language LAB

Lab 5: Input/Output using a Library of Procedures

reply db y prompt db Enter your favourite colour:, 0 colour db 80 dup(?) i db 20 k db? num dw 4000 large dd 50000

Lab 3: Defining Data and Symbolic Constants

EXPERIMENT TWELVE: USING DISK FILES

Summer 2003 Lecture 15 07/03/03

EEM336 Microprocessors I. Data Movement Instructions

UNIT 4. Modular Programming

Constants and. Lecture 7: Assembly Language Programs. Expressions (cont.) Constants and. Statements. Expressions

Experiment N o 1. Introduction to Assembly Language Programming

Constants and Expressions. Lecture 7: Assembly Language Programs. Constants and Expressions (cont.) Statements. Names. Assembly Directives

Q. State and Explain steps involved in program development. [w-08, w-10, s-12, w-11]

Experiment #2. Addressing Modes and Data Transfer using TASM

Experiment 3. TITLE Optional: Write here the Title of your program.model SMALL This directive defines the memory model used in the program.

ELEC VIDEO BIOS ROUTINES

Topics Introduction to Microprocessors. Chapter 5 Macros and modules. What is macro? How to use macro? (I) How to use macro?

Experiment N o 1. 1 Introduction to Assembly Language Programming

Video processing The INT instruction enables program to interrupt its own processing. Use INT instruction to handle inputs and outputs

CSCI516: Program 1 - October 11, 2010 The Program is due: October 25, 2010 in the beginning of the class

db "Please enter up to 256 characters (press Enter Key to finish): ",0dh,0ah,'$'

Memory Organization. 27 December 2016 Pramod Ghimire. Slide 1 of 21

Assembly Language for Intel-Based Computers, 4 th Edition. Chapter 5: Procedures. Chapter Overview. The Book's Link Library

Week /8086 Microprocessor Programming II

Experiment 8 8 Subroutine Handling Instructions and Macros

Libraries and Procedures

Microprocessors & Assembly Language Lab 1 (Introduction to 8086 Programming)

ORG ; TWO. Assembly Language Programming

Lab 2: Introduction to Assembly Language Programming

Marking Scheme. Examination Paper Department of CE. Module: Microprocessors (630313)

Chapter 3: Addressing Modes

Lecture (06) x86 programming 5

Programming in Module. Near Call

Lecture 13: I/O I/O. Interrupts. How?

Lecture 16: Passing Parameters on the Stack. Push Examples. Pop Examples. CALL and RET

mith College Computer Science CSC231 - Assembly Week #4 Dominique Thiébaut

Microcomputer Architecture..Second Year (Sem.2).Lecture(2) مدرس المادة : م. سندس العزاوي... قسم / الحاسبات

EXPERIMENT NINE DEVELOPING MACRO SEQUENCES

.code. lea dx,msg2. Page 1/8. Problem 1: Programming in Assembly [25 Points]

COE 205 Lab Manual Experiment N o 12. Experiment N o Using the Mouse

Assembly Language: g Part III. First Semester 2013 Department of Computer Science Faculty of Science Chiang Mai University

Transfer of Control. Lecture 10 JMP. JMP Formats. Jump Loop Homework 3 Outputting prompts Reading single characters

Assembly Language LAB

Basic Assembly SYSC-3006

Assembly Language for Intel-Based Computers, 4 th Edition. Chapter 3: Assembly Language Fundamentals

Assembly Language for Intel-Based Computers, 4 th Edition

SPRING TERM BM 310E MICROPROCESSORS LABORATORY PRELIMINARY STUDY

BLDEA S V.P. DR. P.G. HALAKATTI COLLEGE OF ENGINEERING & TECHNOLOGY, VIJAYAPURA

The Stack. Lecture 15: The Stack. The Stack. Adding Elements. What is it? What is it used for?

UNIVERSITY OF CALIFORNIA, RIVERSIDE

Libraries and Procedures

We can study computer architectures by starting with the basic building blocks. Adders, decoders, multiplexors, flip-flops, registers,...

8086 ALP TOOLS (CH 2) CHAPTER 2

EE 314 Spring 2003 Microprocessor Systems

Objectives. Saving Interrupt Vectors. Writing a Custom Interrupt Handler. Examples of use of System functions for Input-Output and Interrupts

By: Dalbir Singh, Computer Science Dep't

Assembly Language Fundamentals. Chapter 3

Marking Scheme. Examination Paper. Module: Microprocessors (630313)

CSE 505 Lecture 8: Introduction to Assembly Language

Ethical Hacking. Assembly Language Tutorial

16-bit MS-DOS and BIOS Programming

VARDHAMAN COLLEGE OF ENGINEERING (AUTONOMOUS) Shamshabad, Hyderabad

EC 333 Microprocessor and Interfacing Techniques (3+1)

Q1: Define a character string named CO_NAME containing "Internet Services" as a constant?

Microprocessor. By Mrs. R.P.Chaudhari Mrs.P.S.Patil

The registers(di,si) are automatically incremented or decremented depending on the value of the direction flag:

CPU. IBM PC and compatible Memory Structure

Assembly Language for Intel-Based Computers, 4 th Edition. Chapter 5: Procedures

ELEC 242 Time Delay Procedure

COE 205: Computer Organization & Assembly Language Introductory Experiment-B By Louai Al-Awami

COE 205. Computer Organization and Assembly Language Dr. Aiman El-Maleh

Computer Architecture and System Software Lecture 07: Assembly Language Programming

LABORATORY WORK NO. 8 WORKING WITH MACROS AND LIBRARIES

5. Using Signed Numbers and Look-up Tables

Chapter Overview. Assembly Language for Intel-Based Computers, 4 th Edition. Chapter 3: Assembly Language Fundamentals.

Assembly Fundamentals

Section 1: C Programming Lab

CS-202 Microprocessor and Assembly Language

Assignment 3. Problem Definition:

EEL 3801 Introduction to Computer Engineering Summer Home Work Schedule

Macros. Introducing Macros Defining Macros Invoking Macros Macro Examples Nested Macros Example Program: Wrappers

US06CCSC04: Introduction to Microprocessors and Assembly Language UNIT 1: Assembly Language Terms & Directives

Unit 5 DOS INTERRPUTS

Assembly Language Each statement in an assembly language program consists of four parts or fields.

Midterm Exam #2 Answer Key

COMPUTER ENGINEERING DEPARTMENT

Intel 8086: Instruction Set

LABORATORY 8: USING BIOS ROUTINES FOR KEYBOARD INPUT AND DISPLAY OUTPUT

The x86 Microprocessors. Introduction. The 80x86 Microprocessors. 1.1 Assembly Language

Islamic University Gaza Engineering Faculty Department of Computer Engineering ECOM 2125: Assembly Language LAB. Lab # 10. Advanced Procedures

Assembler Programming. Lecture 10

Islamic University Gaza Engineering Faculty Department of Computer Engineering ECOM 2125: Assembly Language LAB

3: 4: 5: 9: ',0 10: ',0 11: ',0 12: 13:.CODE 14: INCLUDE

INT 21H and INT 10H Programming and Macros

Assembly Language Lab #5

Transcription:

ELEC 242 Using Library Procedures There are a number of existing procedures that are already written for you that you will use in your programs. In order to use the library procedures that come with the text, you must install the example programs that come on the CD-ROM, or download the library from the authors web site at http://www.nuvisionmiami.com/books/asm/files/irvine.zip. You will need to unzip the file to your work disk and directory. The name of the file is irvine.lib. You can use the Windows find file to locate exactly where Irvine.lib is located on your hard drive. In order to use the procedures in this library, the library file must be on your data disk in the same directory as your asm and obj files. You should copy the file from your hard drive to your data directory (the root directory on the 3 ½ inch Floppy.) The files indicated by the EXTRN directive are accessed by the linker. To use a procedure in the library, we must identify the procedure name in the area of our source code file. The EXTRN directive should be laced in the code segment of our source code file immediately after the directive. In order to link to an external library file, you must name the library in the command line. The figure below shows that the Link Library is input to LINK.EXE just as the obj file. Therefore, when we invoke ML, we must identify the library. In addition, The modified ml command line is: ml /Fl irvine.lib filename.asm To make this easier, you may wish to create a batch file called go.bat. It would have one command in the file: ml /Fl irvine.lib %1.asm To assemble and link a file called lab07.asm using the batch file go.bat, go to the system prompt and enter the command: go lab07 where lab07 is the name of the asm file that you created. The command is entered without the extension. We can use this batch file even if we are not using a procedure in the library. We could identify a library in the command line even if there are no EXTRN directives in our asm file. In this case, nothing needs to be accessed form the library, so no error or warning will be generated. However, if we have an EXTRN directive and no library is accessed from the command line, error messages may be generated. This is accomplished by placing the name of the external procedures that we wish to use in the code segment, preferably immediately after the or directive. The procedures that we wish to use are identified as ProcName:proc where ProcName is the external procedure name. If more than one external procedure is required, each is comma delimited. If many procs are being used, we may continue on the next line by placing a, \ at the of the current line. (If you forget the comma before the \ you will receive an error message from the assembler). The line with the EXTRN directive would be similar to the following: Extrn Proc1Name: proc, Proc2Name: proc, \ Proc3Name: proc, Proc3Name: proc Page 1

ELEC 242 Using Library Procedures - writestring WriteString is a procedure that allows you to easily s a string of data stored in a null terminated array to the display. We performed a similar task already using Function 9 INT 21H with our Hello World program. Function 9 requires a string array terminated by $. To use the WriteString library procedure, we must create an null terminated (the last character of the array is,0) array of characters that provide the message. The program requirements are: A null terminated string must exist in the data segment. The base address of the null terminated string data must be placed in DX. The string (without the 0) is present on Standard Output (the display) To use WriteString, we might enter the following in the segment: cr equ 0dh lf equ 0ah greet db cr,lf, Welcome to Brookdale Community College. db cr, lf, 0 WriteString is an external procedure that exists in irvine.lib. We must identify the name of the procedure in irvine.lib that we wish to use. TITLE Program Hello World by Andrew H. Andersen, Jr. PAGE 60,80 ; Brookdale Community College.model small.stack 2000H cr equ 0dh lf equ 0ah greet db cr,lf, "Hello world",cr,lf,lf,0 done equ 04c00H extrn WriteString: proc ; This code uses a procedure in irvine.lib to display a message lea dx,greet ;or mov dx,offset greet ;an external procedure fini: mov ax,done int 21h Page 2

ELEC 242 Using Library Procedures - WriteInt WriteInt WriteInt is another procedure that has been written for you and is part of irvine.lib. WriteInt is a procedure that allows you to easily write unsigned, 16-bit integer data to the standard output in ASCII. This means that the range of values are 0 through 65 535. The data may be written binary, octal, decimal, or hexadecimal format. This procedure will perform the conversion to the desired number base, convert each digit to ASCII, and s the character to the console output. The 16-bit unsigned integer data must be in AX. Numeric value range is 0 to 65 535 The radix for the format of the desired numeric display format must be in BX. The radix is entered as 2,8,10,16. Any other data in BX is invalid. The numeric data is present on the display in the specified number base. To use a procedure in the library, we must identify the procedure name in the area of our source code file. The EXTRN directive should be laced in the code segment of our source code file immediately after the directive. The beginning of the code segment is similar to the following: extrn Writeint:proc ; The general setup for WriteInt with 16-bit data is: mov ax,num ;put data value in AX mov bx,10 ;put desired numeric format in bx call WriteInt ;call the procedure WriteInt Notice that this requires a single piece data to be in a word-sized data storage buffer called data. For byte-sized data, the program would have to be modified as follows: xor ax,ax ;Clear the AX register (we need AH to be 0) mov al,data ;put byte value in AL ; since ah is 0, we have a proper 16-bit value mov bx,10 ;put desired numeric format in bx call WriteInt ;call the procedure WriteInt The proceeding is fine for single value of data. Suppose we wish to write an array of 16-bit unsigned integers. We would need to use word pointer to the array, and a loop counter that is incremented by 2, and a word pointer. The following is an example of a procedure with its required data segment to use WriteInt to display word-sized unsigned integers from an array called values with nvals as the number of entries in array. array dw 24 dup (1) ;init to all 1's nvals equ (($-array)/2) ;($-array)/2 since there are 2 bytes/value ; The previous statement automatically calculates ; the number of elements in the array Page 3

ELEC 242 Using Library Procedures - WriteInt extrn Writeint: proc, Crlf: proc ;call to library procedure ; some stuff may be here ; Assume it fills an array with word-size integer data. ; We will use nested procedures to Call ShowIt to walk the array ; and call a library procedure Writeint ; to s the value to the display ; and another procedure Blank to move the cursor to a new line lea si,array ;load SI as an address pointer to values mov cx,nvals ;initialize the loop counter mov bx,10 ;load the number base to display again: mov ax,word ptr [si] ; Get value from the array using word ptr call Writeint ; use a library function to show the value call crlf ;only if you wish to place each ; value on a separate line add si,2 ;Increment address pointer by 2 loop again ;Continue to again until CX is 0 mov ax,4c00h ;normal MS-DOS exit int 21H To write multiple numbers on the same line, modify the code to the following: array dw 24 dup (1) ; init to all 1's nvals equ (($-array)/2) ;($-array)/2 since there are 2 bytes/value blank db,0 ; or replace the single space in the quotes ; with 20h,0 extrn Writeint: proc, Crlf: proc, WriteString: proc ; some stuff may be here lea dx, blank lea si,array ;load SI as an address pointer to values mov cx,nvals ;initialize the loop counter mov bx,10 ;load the number base to display Page 4

ELEC 242 Using Library Procedures - WriteInt again: mov ax,word ptr [si] ; Get value from the array using word ptr call Writeint ; use a library function to show the value ; to print 1 space between values add si,2 ; Increment address pointer by 2 loop again ; Continue to again until CX is 0 mov ax,4c00h ; normal MS-DOS exit int 21H Page 5

ELEC 242 Using Library Procedures - ReadInt ReadInt ReadInt is the fourth procedure that we will discuss and is part of irvine.lib. ReadInt is a procedure that allows the user enter a signed, 16-bit binary integer in ASCII from Standard Input (the keyboard). Since this requires user input, you should print a prompt (a message that tells the user what to do) to Standard Output You should print an appropriate prompt on the display If AX contains data that you will need later, save it in Storage or on the Stack The 16-bit signed binary integer data is returned in AX. indata dw 24 dup (1) ;init to all 1's nvals equ (($-indata)/2) ;we used ($-array)/2 since there are 2 bytes/value prompt db Enter a number ==>,0 greet db You will have to enter 24 numbers., 0 The beginning of the code segment is similar to the following: extrn Readint:proc, WriteString:proc, crlf:proc ;The general setup for ReadInt is: lea dx,greet ;or mov dx,offset greet call Crlf lea dx,prompt ;or mov dx,offset greet push ax ;only if it contains useful data mov si,offset indata ;point to address of word size data mov cx, nvals ;load loop counter with number of words more: ;an external procedure to display prompt call ReadInt ;get the number call Crlf ;go to next line mov word ptr [si],ax ;put in array add si,2 ;increment 1 word loop more ;until cx = 0 pop ax ;get ax back ;do whatever has to be done here mov ax,4c00h ;normal MS-DOS exit int 21H Page 6

ELEC 242 Using Library Procedures - ReadString ReadString ReadString reads a string of characters from Standard Input and stores it as a null terminated string. This is the reverse of WriteString. We need to perform a number of steps to use this procedure. 1. We need to setup storage in memory (RAM) for the input data. Since the string is null terminated, make the array 1 byte larger than the number of characters you wish to store. 2. We need to define the size of the storage area. 3. Since the user must do something, provide a prompt to tell them what to do. You should print an appropriate prompt on the display telling the user what to do. You must have storage setup that is one byte larger than the number of characters Initialize DX to the base address of the string. Initialize CX to the maximum number of characters to accept AX contains the number of characters entered from Standard Input. The String is written to RAM. Your_Name db 26 dup (?) ;init to all 1's Num_Char equ $-indata-1 ;we use $-array-1 since we need an extra byte for the null prompt db Enter your name ==>,0 result db Your name has,0 nextmsg db characters.,0 The code segment is similar to the following: extrn WriteString: proc, ReadString: proc, \ WriteInt: proc, ReadInt: proc mov mov ax,@data ds,ax lea dx, prompt lea dx, Your_Name mov cx, Num_Char call ReadString lea dx, result mov bx,10 call Writeint lea dx, Nextmsg mov ah,4ch int 21h Page 7