In: Computer Science
ACTIVITY #1: Defining Strings
√ Write an assembly program that display your name, your id, and
your college name on the screen.
√ Remember: the format of the assembly program should be like
this.
TITLE your title (FileName.asm)
.MODEL FLAT
.386
.STACK 64
.DATA
str1 DB "My name: Essam Alnatsheh",13,10,'$'
.CODE
main PROC
mov ax,@data
mov ds,ax
mov ah,09h
mov dx, offset str1
int 21h
mov ah,4Ch ; terminate process
mov al,0 ; return code
int 21h
main ENDP
END main
Question 1: What is the purpose of:
mov ax,@data
mov ds,ax
Answer:
√ Ask the instructor to evaluate your code.
√ Enter, assemble, link, and run your program to be sure it’s
correct.
√ Write your code in this space.
ACTIVITY #2: Using the DUP Operator
Question 3: Write an Assembly program that display your name and
your nationality as two lines on the screen. Using the DUP
operator, display a line of '**- - - - -**- - - - -' before and
after the previous text. Use interrupts (21h) to display the string
values and use it to terminate the program.
Ask the instructor to evaluate your code and write your code in
this space.
ACTIVITY #3: Using x86 Registers
Question 4: Write an Assembly program that subtracts three integers
(defined as byte variables and with values 9, 5, and 3) using only
8-bit registers. Insert int 21h statements to display the result’s
value using ASCII code and use it to terminate the program.
Question 1
student.asm
.MODEL FLAT
.STACK 64
.DATA
str1 DB "My Name : Essam Alnatsheh",13,10,'$'
str2 DB "My id : CSE123",13,10,'$'
str3 DB "My College Name: IIT
Chennai,India",13,10,'$'
.CODE
main PROC
mov ax,@data
mov ds,ax
mov ah,09h
mov dx, offset str1
int 21h
mov ah,09h
mov dx, offset str2
int 21h
mov ah,09h
mov dx, offset str3
int 21h
mov ah,4Ch ; terminate process
mov al,0 ; return code
int 21h
main ENDP
END main
Reason for instructions
mov ax,@data
mov ds,ax
8086 programs are stored in
different segments in memory.The different segments are DATA
SEGMENT, CODE SEGMENT, STACK SEGMENT and EXTRA SEGMENT.Purpose of
each segments are
DATA SEGMENT: where variables,arrays and constants are stored[data
for the program is stored]
CODE SEGMENT : where binary code of executable instructions are
stored
STACK SEGMENT: where content of stack are stored
EXTRA SEGMENT.:It is also used for storing data
There are four segment registers
CS,DS,SS and ES are used for handling these segments. Each of these
registers are initialized with base address of corresponding
segment.
CS segment register: for handling CODE SEGMENT
DS segment register: for handling DATA SEGMENT
SS segment register: for handling STACK SEGMENT
ES segment register: for handling EXTRA SEGMENT
In our program instructions
mov ax,@data
mov ds,ax
loads base address of DATA SEGMENT to ax register and then DS
register stored with the value of ax(base address of DATA SEGMENT).
A segment register cannot be loaded an address directly. so we use
these two instruction.
Output 1
Question 3
student1.asm
.MODEL FLAT
.STACK 64
.DATA
str1 DB "My Name : Essam Alnatsheh",13,10,'$'
str2 DB "My Nationalit : United State of
America",13,10,'$'
msg1 DB 2 dup('*'),'$'
msg2 DB 5 dup('- '),'$'
msg3 DB 13,10,'$'
.CODE
main PROC
mov ax,@data
mov ds,ax
mov ah,09h
mov dx, offset msg1
int 21h
mov ah,09h
mov dx, offset msg2
int 21h
mov ah,09h
mov dx, offset msg1
int 21h
mov ah,09h
mov dx, offset msg2
int 21h
mov ah,09h
mov dx, offset msg3
int 21h
mov ah,09h
mov dx, offset str1
int 21h
mov ah,09h
mov dx, offset str2
int 21h
mov ah,09h
mov dx, offset msg1
int 21h
mov ah,09h
mov dx, offset msg2
int 21h
mov ah,09h
mov dx, offset msg1
int 21h
mov ah,09h
mov dx, offset msg2
int 21h
mov ah,09h
mov dx, offset msg3
int 21h
mov ah,4Ch ; terminate process
mov al,0 ; return code
int 21h
main ENDP
END main
Output 2
Question 4
student3.asm
.MODEL FLAT
.STACK 64
.DATA
num DB 9,5,3
msg DB "Result=",'$'
.CODE
main PROC
mov ax,@data
mov ds,ax
mov si, offset num
mov dl,[si]
inc si
sub dl,[si]
inc si
sub dl,[si]
push dx
mov ah,09h
mov dx, offset msg
int 21h
pop dx
add dl,30h
mov ah,02h
int 21h
mov ah,4Ch ; terminate process
mov al,0 ; return code
int 21h
main ENDP
END main
Output 4