0% found this document useful (0 votes)
31 views4 pages

BC220205122 CS401

The document describes a program written in assembly language that takes an input array of numbers, finds the greatest number, subtracts each number from the greatest to create a new array, and then sorts the new array using an inner loop swap algorithm.

Uploaded by

rhanzla1220
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)
31 views4 pages

BC220205122 CS401

The document describes a program written in assembly language that takes an input array of numbers, finds the greatest number, subtracts each number from the greatest to create a new array, and then sorts the new array using an inner loop swap algorithm.

Uploaded by

rhanzla1220
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/ 4

CS 401

Assignment # 01
Student ID: BC220205122
Solution:
Code:
[org 0x0100]
jmp start

id: db 2,2,0,2,0,5,1,2,2
greater: db 0
subtractResult: db 0,0,0,0,0,0,0,0,0
sortResult: db 0,0,0,0,0,0,0,0,0
swap: db 0

start:
mov cx, 9
mov bl, 0
mov si, id

up:
mov al, [si]
cmp al, bl
jl next
mov bl, al

next:
inc si
dec cx
jnz up

mov [greater], bl
mov si, id
mov di, 0
mov cx, 9
mov bl, 0

subroutine:
mov al, [si]
mov bl, [greater]
sub bl, al
mov [subtractResult + di], bl
mov [sortResult + di], bl
inc si
inc di
dec cx
jnz subroutine

mov bx, sortResult


mov cx, 8

main:
mov si, 0
mov byte [swap], 0
inner:
mov al, [bx + si]
cmp al, [bx + si + 1]
jbe noswap

mov dl, [bx + si +1]


mov [bx + si], dl
mov [bx + si +1], al
mov byte [swap], 1

noswap:
add si, 1
cmp si, cx
jne inner
cmp byte [swap], 1
je main
mov ax, 0x4c00
int 0x21

Screenshot:

You might also like