Activity No 3 Data Definition and Transfer
Activity No 3 Data Definition and Transfer
3
DATA DEFINITION AND TRANSFER
Course Code: CPE021 Program:
Course Title: Computer Architecture and Organization Date Performed:
Section: Date Submitted:
Name: 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’
lea dx,prompt1
mov ah,09h
int 21h
mov ah,01h
int 21h
movbl,al
lea dx,prompt2
mov ah,09h
int 21h
movdl,bl
mov ah,02h
int 21h
mov ax,4c00h
int 21h
main endp
end
6. DATA ANALYSIS:
Table 3.2- Output of Sample Program A Table 3.3- Output of Sample Program B
7. PROBLEMS:
1. How many bytes are allocated for each of the following data definitions?
a. BYTE 20 DUP(0)= _____________ bytes
b. BYTE 20 DUP (?)= _____________ bytes
c. BYTE 4 DUP(“East”)= _____________ bytes
d. WORD3 WORD ?= _____________ bytes
e. Array WORD 5 DUP(?)= _____________ bytes
2. Create 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).
8. CONCLUSIONS