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

Institute of space and technology

KICSIT, KAHUTA CAMPUS (Y- CROSS)

DEPARTMENT OF COMPUTER SCIENCE

Assignment

3
Computer Organization & Assembly Language
“LAB”

Semester: BSCS 3
Submitted to:
Mam Muneeba Mubarik
Submitted From:
Maria Kabeer Satti
Roll No: 212201007

DATE: 10-December-2022
Question no 1:

Program to reverse the hard coded string

Answer:

dosseg
.model small
.stack 100h
.data
arr db "abcdef$"
.code
main proc
mov ax,@data
mov ds,ax

mov si,offset arr


mov cx,6

l1:
mov ax,[si]
push ax
inc si
loop l1

mov cx,6
l2:
pop dx

mov ah,2
int 21h
inc si

loop l2

mov ah,4ch
int 21h

main endp
end main

OUTPUT:
Question no 2:

Program that input the string from user and reverse it

Answer:

dosseg
.model small
.stack 100h
.data
arr db 20 dup("$")
.code
main proc
mov ax,@data
mov ds,ax
mov bl,0
mov si,offset arr
input:
mov ah,1
int 21h
cmp al,13
je print
mov [si],al
inc si
inc bl
jmp input
print:
mov cl,bl
print1:
dec si
mov dx,[si]
mov ah,2
int 21h
loop print1

mov ah,4ch
int 21h
main endp
end main

OUTPUT:

Question no 3:

Program that take 7 numbers in array as: 7 1 5 3 8 2 4 and


sort the array in ascending order as : Sorted array = 1 2 3 4 5
78
Answer:

output macro s
mov dx,offset s
mov ah,9
int 21h
endm
dosseg
.model small
.stack 100h
.data
msg1 db "unsorted array =$ "
msg2 db "Sorted array =$ "
arr db 7 dup(?)
.code

main proc

mov ax,@data
mov ds,ax

mov si,offset arr


mov cx,7
output msg1

arrayinput:
mov ah,1
int 21h
mov [si],al
mov dl,32
mov ah,2
int 21h
inc si
loop arrayinput

mov cx,7
dec cx

l1:
mov bx,cx
mov si,0
comploop:
mov al,arr[si]
mov dl,arr[si+1]
cmp al,dl
jc noswap
mov arr[si],dl
mov arr[si+1],al
noswap:
inc si
dec bx
jnz comploop
loop l1
mov dl,10
mov ah,2
int 21h
mov dl,13
mov ah,2
int 21h
output msg2
mov cx,7
mov si,offset arr
print:
mov dx,[si]
mov ah,2
int 21h
mov dl,32
mov ah,2
int 21h
inc si
loop print

mov ah,4ch
int 21h

main endp
end main

OUTPUT:

You might also like