Lab Exercise 5

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

Lab on Displaying on the monitor

Displaying text on the monitor


Write an assembly program that displays “hello world”
.MODEL SMALL ; tells the assembler that you intend to use the small memory model -
;one code segment, one data segment and one stack segment
.STACK 64 ; is telling the assembler the size of the stack, so MASM can warn you
; when the rest of the program would clash with the ;
;stack.
.DATA ; Here we can declare our variable

MSG DB 'Welcome to Assembly language Programming$' ; Stings must be terminated with


; a the $ symbol
.CODE ; ;The actual code or program starts here.
MAIN PROC DISPLAY ;Procedure starts here
MOV AX, @DATA
MOV DS, AX

LEA DX, MSG ;Load the effective address where the message is stored
MOV AH,09
INT 21H Used to display on the monitor

MOV AH, 4CH Return to OS


INT 21H
MAIN ENDP
END MAIN

1
Program 1: To display a string on the monitor
========================================
.MODEL SMALL
.STACK 64
.DATA
MSG DB 'Welcome to Assembly language Programming$'
.CODE
MAIN PROC
MOV AX, @DATA
MOV DS, AX

LEA DX, MSG


MOV AH,09
INT 21H

MOV AH, 4CH


INT 21H
MAIN ENDP
END MAIN

Program two
To accept two numbers from the keyboard and display the sum on the monitor

;This program accepts two inputs from the keyboard and display the sum on the monitor.
.model small
.stack 100h

.data
msg1 db ‘Enter the first number $’

2
msg2 db ‘Enter the Second Number $’
msg3 db ‘The sum of the two numbers is $’
num1 db ?
num2 db ?
.code
main proc
mov ax, @data
mov ds, ax
; display the first message
mov ah, 09h
lea dx, mag1
int 21
; input the character
mov ah, 01h
int 21
; the value entered will be stored in al register and it is in ASCII format. We need to subtract 48
to get the ;actual value.
Sub al, 48
mov num1, al

mov ah, 09h


lea dx, msg2
int 21

mov ah,01h
int 21
sub al,48
mov num2, al
mov ah, 09h
3
lea dx, msg3
int 21
; add num1, num2 ; it is illegal to add values both source and destination in memory
mov al, num1
add al, num2

mov dl, al
add dl, 48
mov ah, 02h
int 21h

mov ah, 4ch


int 21h
main endp
end main
======================================================
.model small
.stack 100h

.data
msg1 db 'Enter the first number $'
msg2 db 0dh,0ah,'Enter the Second Number $'
msg3 db 0dh,0ah,'The sum of the two numbers is= $'
num1 db ?
num2 db ?
.code
main proc

4
mov ax, @data
mov ds, ax
; display the first message
mov ah, 09h
lea dx, msg1
int 21h
; input the character
mov ah, 01h
int 21h
; the value entered will be stored in al register and it is in ASCII format. We need to subtract 48
to get the ;actual value.
Sub al, 48
mov num1, al

mov ah, 09h


lea dx, msg2
int 21h

mov ah,01h
int 21h
sub al,48
mov num2, al
mov ah, 09h

lea dx, msg3


int 21h
; add num1, num2 ; it is illegal to add values both source and destination in memory
mov al, num1
add al, num2
5
mov dl, al
add dl,48 ; We added 48 to display the actual value.
mov ah, 02h
int 21h

mov ah, 4ch ;return


int 21h
main endp
end main

You might also like