Working complete PC
Source Code Diskette (created in the Introduction to TASM module)
Student Diskette, "New Boot A Ver 2.0+"
Student CD-ROM, "QBOOT" (any version)
The student will become familiar with the Borland Turbo Assembly language compiler including:
designing a blank source code file,
building a source file,
building the object file,
building the executable.
The student will learn how to design executable assembly lanugage programs and how to compile and link the source code text file into an executable. The student will become familiar with some basic compiler "dot" directives and some simple machine language instructions.
The student will need a copy of Borland's Turbo Assembly Lanugage software, preferably version 5.0.
After launching QBOOT by pressing [F8] say yes to all CONFIG.SYS prompts and all AUTOEXEC.BAT prompts except the last one to launch Windows 3.11.
Change to the K: drive and insert the source code diskette created in the Introduction to TASM module. Copy BLANK.ASM from the diskette to the root of the K: drive and then run "edit blank.asm" All assembly language source files should have the file extention .ASM so that the compilers can easily recognize them.
In EDIT's main field, the following source code should be present:
.model tiny .stack 200h .data .code main proc mov ax, @data mov ds, ax terminate: mov ax, 4C00h int 21h main endp end main
Press [Alt]+[F] to open the File menu and then press [A] to save the file with a new name. Name the file USERIN.ASM. Make the following changes:
.model tiny .stack 200h .data promptmsg db "Enter Text: $" outmsg db 0Dh, 0Ah, "You typed: $" maxlen db 80 strlen db 0 inbuf db 81 dup('$') .code main proc mov ax, @data mov ds, ax start: mov ah, 9 mov dx, offset promptmsg ;address of the string to be displayed int 21h mov ah, 0Ah ;function 0Ah: get input string from heyboard mov dx, offset maxlen ;address of the start of the input buffer int 21h mov ah, 9 mov dx, offset outmsg ;address of the string to be displayed int 21h mov ah, 9 mov dx, offset inbuf ;address of the string to be displayed int 21h terminate: mov ax, 4C00h ;function 4C = quit program int 21h main endp end main
Press [Alt]+[F] then [S] to save the changes. The highlighted lines are the ones that were added to the original BLANK.ASM. The first change creates the new variables named "promptmsg", "outmsg", "maxlen", "strlen", and "inbuf."
The next set of changes are divided into four discrete calls to DOS. The first one displays the prompt "Enter Text: " on screen. The next one calls DOS function 0Ah which will accept user input from the keyboard and display each key on screen at the cursor location as it is typed in by the user. This function requires a prearranged input buffer in RAM that must hold the maximum number of characters that the user is allowed to type in the first byte, DOS returns the actual number of characters that the user typed in the second byte, and the actual characters typed are returned in the bytes after that.
Here is an example in RAM of an input buffer allowed to receive 8 characters from the user prior to calling DOS to receive the input:
Here is the same example in RAM of an input buffer allowed to receive 8 characters from the user AFTER calling DOS to receive the input and the user typed "Hello" then [Enter]:
The actual string length has been recorded at the variable's offset + 1, and the actual characters start at the variable's offset + 2. Note that the ASCII code 13 (0Dh) is stored from the [Enter] key but is not included in the length byte. Note that the way the variable was declared maxlen is the variable's base name and can be accessed individually. The second byte of the buffer (variable + 1) is also explicitly named "strlen" and can also be accessed individually. The actual string of characters has also been explicitly named "inbuf" and can be directly accessed by that name. This makes it easy to write the code to refer to each piece of information as it is needed. Also note that the input buffer was initialized with the compiler function "80 dup('$')" This tells the compiler to create 80 bytes of dollar signs. This is very useful if a huge buffer is needed making it easy to create a huge empty variable without having to type it all in. By initializing the buffer with dollar signs, it is ready to be passed to the DOS function number 9 no matter how many characters the user actually types. Of course it fails if they actually type in a dollar sign!
The next section is another function 9 call to DOS that will display the string "You typed: ". Note that it is preceded by hexadecimal 0Dh and 0Ah. These two are generated when the user presses the [Enter] key and are the ASCII codes for the "Carriage Return" which moves the cursor to the far left, and the "Line Feed" which scrolls the screen up one line. This moves the cursor to the far left of the next line because the user input function will not do this by itself. This is followed by the function 9 call that will display the contents of the inbuf variable, displaying what the user actually typed.
Now copy the file to the source code floppy, then compile the program:
K:\>copy userin.asm b: 1 file(s) copied K:\>tasm /zi userin Turbo Assembler Version 4.1 Copyright (c) 1988, 1996 Borland International Assembling file: userin.ASM Error messages: None Warning messages: None Passes: 1 Remaining memory: 335k K:\>_
Link the program:
K:\>tlink /v userin Turbo Link Version 126.96.36.199. Copyright (c) 1987, 1996 Borland International K:\>_
Now execute the program:
K:\>userin Enter Text: _
Type some input at the prompt then press [Enter]:
K:\>userin Enter Text: This is a test! You typed: This is a test! K:\>_
This concludes the simple execution of a program that can gather input from a user. In the next program the user input will be actually interpreted and used by the program.
Copyrightę2000-2006 Brian Robinson ALL RIGHTS RESERVED