Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
3
DATA DEFINITION AND TRANSFER
Course Code: CPE005 Program:CPE
Course Title: Computer Systems Organization with Assembly Language Date Performed:
Section: Date Submitted:
Name: Ruiz,mark daniel Instructor:
1. Objective:
This activity aims to demonstrate how characters and string of characters move from one location
to another.
DISPLAYING A STRING
There are two ways to display a string:
Using Service 09H
Required:
1. The string must be defined in DATA segment.
2. The string must be terminated by '$'.
3. AH = 09h
4. DX = Offset address of the beginning of the string
Example:
.DATA
STRING_NAME DB 'THE STRING TO BE DISPLAYED$'
.CODE
MOV AH , 09H
MOV DX , OFFSET STRING_NAME
INT 21H
Note:
If the terminating $ is omitted after the string, the operation displays characters in the
memory, until it finds a $ character, if any.
To move the cursor to the beginning of the next output line, put 0Dh and 0Ah after the string
and before the terminating $.
Example:
PROMPT DB 'PLEASE, ENTER YOUR NAME: ' , 0Dh , 0Ah , '$'
Another way of moving the cursor to the beginning of the next output line is to display ,
using DOS function 09H, a string of the form:
STRING1 DB 0Dh , 0Ah , '$'
Using Service 40H
Required:
1. Set AH = 40h
2. BX = 1
3. CX = string length
4. DX = offset address of the beginning of the string
Example:
.DATA
STRING_NAME DB 'THE STRING TO BE DISPLAYED'
STRINGLEN EQU $ – STRING_NAME
.CODE
MOV AH , 40H
MOV BX , 01H
MOV CX , STRINGLEN ; string length
MOV DX , OFFSET STRING_NAME
INT 21H
The EQU directive defines a value that the assembler can use to substitute in other
instructions.
An operand containing a dollar symbol, $, refers to the current value in the location
counter. Thus, in the above example $ - STRING_NAME evaluates to the number of bytes
between STRING_NAME and STRINGLEN which is the number of bytes (i.e., characters) in ‘THE
STRING TO BE DISPLAYED’
where:
a. Num1 = the maximum number of string characters to be read + 1
b. Num2 = Num1 + 1
c. The maximum value for Num1 is FFh i.e., 255
d. The last string character is the Carriage Return (0Dh).
The program will wait for the input. The user must press "Enter" key to end the inputting process. inp
Example:
Define an array called STRING to store a string of maximum length 50 characters to be used by the service
0Ah of INT 21h.
Actual string length is stored in this byte
To read a string from the keyboard into an array called BUFFER as defined above, we invoke DOS function
0AH as:
MOV AH , 0AH
MOV DX , OFFSET STRING
INT 21H
The operation echoes the entered characters on the screen and advances the cursor.
To display the above array generally by using DOS function 40H:
MOV AH, 40H
MOV BX, 01H ; file handle for the screen
MOVZX CX, STRING[1] ; Initialize CX with the string length
MOV DX, OFFSET STRING[2]
INT 21H
4. Resources:
Computer with 32-bit Operating System
TASM
5. Procedure:
Sample Program A.
1. Type the following program using Notepad.
dosseg
.model small
.stack
.data
prompt1 db 13,10,"Enter a character:$"
prompt2 db 13,10,"The character you entered is:$"
.code
main proc
mov ax,@data
mov ds,ax
lea dx,prompt1
mov ah,09h
int 21h
mov ah,01h
int 21h
mov bl,al
lea dx,prompt2
mov ah,09h
int 21h
mov dl,bl
mov ah,02h
int 21h
mov ax,4c00h
int 21h
main endp
end
Sample Program B.
1. Type the following program using Notepad.
.model small
.stack 100h
.data
byte1 db 1
byte2 db 0
word1 dw 1234h
word2 dw 0
string db "Stressed!", 0dh, 0ah,"$"
;---- this is a comment
.code
MAIN PROC
Mov ax, @data
Mov ds, ax
6. DATA ANALYSIS:
Table 3.2- Output of Sample Program A Table 3.3- Output of Sample Program B
PROBLEMS:
1. How many bytes are allocated for each of the following data definitions?
a. BYTE 20 DUP(0) = ______20_______ bytes
b. BYTE 20 DUP (?) = _______20______ bytes
c. BYTE 4 DUP(“East”) = ______4_______ bytes
d. WORD3 WORD ? = ______3_______ bytes
e. Array WORD 5 DUP(?) = ______5_______ bytes
2. Write a program that prompts and reads a user’s name USERNAME (of maximum length 30
characters). The program should display a message of the form:
OUTPUT:
Hello, What's your name? JM
Hello, JM
Congratulations! Your first program is working!
3. Modify ProgB such that the second string is printed “!dessertS” (“Stressed!” backwards).