Académique Documents
Professionnel Documents
Culture Documents
3
DATA DEFINITION AND TRANSFER
Course Code: CPE005 Program: BS ECE
Course Title: Computer Systems Organization with Assembly Date Performed:
Language 7/27/16
Section: EC31FB2 Date Submitted:
Name: Instructor:
ORA’A,JOHN GILBERT D. ENGR. VERLYN VICENTE
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
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
6. DATA ANALYSIS:
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”) = 16 bytes
d. WORD3 WORD ? = 16 bytes
e. Array WORD 5 DUP(?) = 80 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!
dosseg
.model small
.stack 100h
.data
.code
Start:
Mov ax,@data
mov ds,ax
mov es,ax
mov ah,00h
int 10h
mov si,002
lea dx,prompt4[SI]
mov ah,09h
int 21h
3. Modify ProgB such that the second string is printed “!dessertS” (“Stressed!” backwards).
.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
dosseg
.model small
.stack 100h
.data
prompt1 db 13,10,"Enter a string: $"
prompt2 db 24 dup("$")
prompt3 db 13,10,"$"
.code
main proc
mov ax,@data
mov ds,ax
mov es,ax
mov al,03h
mov ah,00h
int 10h
mov dx,offset prompt1
mov ah,09h
int 21h
mov si,02h
lea dx,prompt2[si]
mov ah,09h
int 21h
mov bl,prompt2[1]
mov dx,offset[prompt2+2]
mov ah,09h
int 21h
mov al,bl
mov dh,2h
mov dl,al
mov bh,0
mov ah,2h
int 10h
mov si,02h
lea dx,prompt2[si]
mov ah,09h
int 21h
mov ax,4c00h
int 21h
main endp
end