[go: up one dir, main page]

0% found this document useful (0 votes)
48 views5 pages

Lab Manual For Assembly Language12

This document contains assembly language code for several tasks like printing hello world, adding two numbers, determining if a number is even or odd, and displaying a variable value. The code shows how to use DOS functions, define variables, perform arithmetic operations, conditional jumps, and call procedures in assembly language.

Uploaded by

mersimoybekele88
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views5 pages

Lab Manual For Assembly Language12

This document contains assembly language code for several tasks like printing hello world, adding two numbers, determining if a number is even or odd, and displaying a variable value. The code shows how to use DOS functions, define variables, perform arithmetic operations, conditional jumps, and call procedures in assembly language.

Uploaded by

mersimoybekele88
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Assembly language code for Lab practice

Assembly language code for Lab practice .data


; To print hello world greeting db 'Hello, world!','$' ; A sample
org 100h; directive is particularly useful string
for segment-based addressing: filename db 'sample.txt','$' ; File name
.model small ; .model small: Specifies the for demonstration
memory model for the program. .code
.stack 200 ; .stack 200: Allocates 200 mov ax, @data
bytes of stack space.
.data ; .data: The data section where we mov ds, ax
define variables. ; Display a message using DOS function 9
greeting db 'hello world !','$' ; greeting db
'hello world !','$': Declares a null-
(print string)
terminated string called “greeting” with the mov ah, 9
value “hello world !”. the dollar sign
mov dx, offset greeting
specifies the size or length of the memory
space and used to terminate string int 21h
.code ; .code: The code section where we
; Read a character from standard input
write the actual program instructions.
mov ax,@data ; mov ax,@data: load the (keyboard) using DOS function 1
address of the data segment to the AX
; The character read is now in AL register
register.
mov ds,ax ; Sets the data segment register (DS) mov ah, 1
to the value in AX. int 21h
mov ah,9 ; it prepares the system to display a ; Write the character to standard output
string (usually stored in memory) using the DOS (console) using DOS function 2
interrupt int 21h.
mov ah, 2
mov dx,offset greeting ; int 21h
The offset keyword is used to obtain the
memory address (offset) of a variable or ; Create a new file using DOS function 3
label. Loads the offset of the “greeting” (create or truncate)
string into the DX register.
int 21h ; Invokes the DOS interrupt 21h to mov ah, 3
terminate the program. mov al, 0 ; Create or truncate mode
mov ah,4ch ; Sets AH to 4Ch, which is the
mov dx, offset filename
DOS function for program termination.
int 21h
int 21h
end
; Write a string to the file using DOS
@@@@@@@@@@@@@@@@@@
function 40h (write to file)
.stack 200

1
Assembly language code for Lab practice

mov ah, 40h int 21h


mov bx, 1 ; File handle (1 for standard mov ax,4c00h; This value represents
output) the DOS exit function (terminate program).
mov dx, offset greeting int 21h
mov cx, 13 ; Number of bytes to write ret
int 21h @@@@@@@@@@@@@@@@@@
; Close the file using DOS function 3 ; To print Z to A using jump
(close file) org 100h
mov ah, 3 .model small
mov al, 0 ; Close mode .code
int 21h mov bl,5ah; The value 5ah(hexadecimal
; Terminate the program using DOS value ) represents the decimal number 90.
function 4Ch (exit) up:; marks the beginning of a loop.
mov ah, 4Ch
int 21h mov ah,02h; mov ah, 02h: Sets the value
of AH to 02h, indicating a DOS function
end call to display a character.
@@@@@@@@@@@@@@@@@@
mov dl,bl; mov dl, bl: Copies the value
To print letter A from BL into DL.
org 100h
int 21h; Invokes the DOS interrupt
.model small
21h to display the character stored in DL.
.code
dec bl; decreases the value of BL by 1 in
mov bl,41h; Moves the hexadecimal each iteration.
value 41h (which corresponds to the ASCII cmp bl,41h; compares the value
character ‘A’) into the BL register. of BL with 41h (hexadecimal). If BL is greater
mov ah,02h; Moves the hexadecimal than or equal to 41h, the loop continues.
value 02h into the AH register.This value is jge up ;greater than or equal
used for the DOS function call (interrupt mov ax,4c00h
21h) to display a character. int 21h
ret
mov dl,bl; Copies the value
@@@@@@@@@@@@@@@@@@
from BL (which is ‘A’) into
the DL register.

2
Assembly language code for Lab practice

;Write a program to add two numbers mov ah,09h


using procedure. lea dx,msg2
int 21h
mov ah,01
org 100h int 21h
.code mov bl,al
sub bl,30h
call summ mov ah,09h
ret lea dx,msg3
int 21h
summ proc add cl,bl
mov ax,3h add cl,30h
mov dl,cl
mov bx,2h mov ah,02h
add ax,bx int 21h
ret
add ax,30h
mov dx,ax Output:
mov ah,02h
int 21h
ret
summ endp
end
@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@
;Write a program which input two
numbers and add them. ;write a program in assembly language
which displays the value of a variable.
org 100h org 100h
.model small .model small
.data .data
msg1 db: “Enter 1st number”, 0dh,0ah,’$’ var db 2
msg2 db:0ah,0dh,”Enter 2nd number”, .code
0dh,0ah,’$’ mov dl,var
msg3 db: 0ah,0dh,”Result:$” mov ah,02h
.code add dl,30h
mov ah,09h int 21h
lea dx,msg1 ret
int 21h
mov ah,01 @@@@@@@@@@@@@@@@@@@
int 21h .MODEL SMALL
mov cl,al
sub cl,30h .STACK 100H

3
Assembly language code for Lab practice

.DATA CMP AL,'6'


MSG DB 'ENETER THE NUMBER AND I JE EVEN ;AL=2
TELL IS IT EVEN OR ODD :$'
MSG1 DB 10,13,' EVEN$' CMP AL,'8'
MSG2 DB 10,13,' ODD$' JE EVEN ;AL=4
.CODE
MAIN PROC CMP AL,'0'
MOV AX,@DATA JE EVEN ;AL=4
MOV DS,AX
MOV AH,9H CMP AL,'9'
MOV DX,OFFSET MSG JE ODD ;AL=3
INT 21H
EVEN:
MOV AH,1 LEA DX,MSG1
INT 21H MOV AH,9
INT 21H
CMP AL,'1' JMP EXIT
JE ODD ;AL=1
CMP AL,'3' ODD:
JE ODD ;AL=3 LEA DX,MSG2
MOV AH,9
CMP AL,'2' INT 21H
JE EVEN ;AL=2
CMP AL,'4' EXIT:
JE EVEN ;AL=4 MOV AH,4CH
CMP AL,'7' INT 21H
JE ODD ;AL=1 MAIN ENDP
END MAIN
CMP AL,'5' .model small
.stack 100h
JE ODD ;AL=3
.data

4
Assembly language code for Lab practice

num db 10 ; Change this value jmp exit


to the desired number
odd:
.code ; Display message for odd number
main proc mov ah, 09h
mov ax, @data lea dx, odd_msg
mov ds, ax int 21h

mov al, num exit:


and al, 1 ; Check the least mov ah, 4Ch
significant bit (LSB)
int 21h

cmp al, 0
even_msg db "The number is even.",
je even 0Dh, 0Ah, "$"
jmp odd odd_msg db "The number is odd.",
0Dh, 0Ah, "$"
even:
; Display message for even main endp
number end main
mov ah, 09h
lea dx, even_msg
int 21h

You might also like