Write an ALP to fond the largest of given byte/Word/Dword/64-bit numbers.

Write an ALP to fond the largest of given byte/Word/Dword/64-bit numbers

;     Find largest number from the array of 32-bit numbers.
;    Program first displays all the elements of array.
;    Then it search for largest number and display the same.

section .data

wel_msg db ‘Welcome to find largest number by MBS!’,10
wel_len: equ $-wel_msg

arr_msg db ‘Array Elements Are:: ‘,10
arr_len : equ $-arr_msg

larg_msg db ‘Largest Number is::’
larg_len: equ $-larg_msg

thankmsg db 10,’THANK YOU BY SSIERAS RAHATA’,10
thank_len : equ $-thankmsg

nwline db 10

array dd 0fa100001h,0b200002h,0fff0003h,0d400004h, 0500005h        ;array elements
arrcnt dd 05h

section .bss
dnum_buff resb 8
large resd 1

%macro dispmsg 2
mov eax,4    ;System call for write
mov ebx,1    ;standard output stream
mov ecx,%1    ;message start address
mov edx,%2    ;message length
int 80h
%endmacro

section .text
global _start
_start:
dispmsg wel_msg,wel_len
dispmsg arr_msg,arr_len
mov esi,array
mov ecx,[arrcnt]

up1:    mov ebx,[esi]
push ecx
call disp_num
dispmsg nwline,1
pop ecx
add esi,04    ;Point to next element

loop up1

mov esi,array
mov ecx,[arrcnt]
mov eax,[esi]
dec ecx

lup1:    add esi,04    ;Point to next element
cmp eax,[esi]
ja lskip1
xchg eax,[esi]
lskip1:
loop lup1
mov [large],eax

dispmsg larg_msg,larg_len
mov ebx,[large]
call disp_num

dispmsg thankmsg,thank_len

exit:    mov eax,01
mov ebx,0
int 80h

disp_num:
mov edi,dnum_buff    ;point esi to buffer

mov ecx,8        ;load number of digits to display

dispup1:
rol ebx,4        ;rotate number left by four bits
mov dl,bl        ;move lower byte in dl
and dl,0fh        ;mask upper digit of byte in dl
add dl,30h        ;add 30h to calculate ASCII code
cmp dl,39h        ;compare with 39h
jbe dispskip1        ;if less than 39h akip adding 07 more
add dl,07h        ;else add 07

dispskip1:
mov [edi],dl        ;store ASCII code in buffer
inc edi            ;point to next byte
loop dispup1        ;decrement the count of digits to display
;if not zero jump to repeat

dispmsg dnum_buff,8
ret

OUTPUT:

cg-151@cg151:~/Final MA/A5$ nasm -f elf largest32.asm
cg-151@cg151:~/Final MA/A5$ ld -m elf_i386 -o largest32 largest32.o
cg-151@cg151:~/Final MA/A5$ ./largest32
Welcome to find largest number by MBS!
Array Elements Are::
FA100001
0B200002
0FFF0003
0D400004
00500005
Largest Number is::FA100001
THANK YOU BY SSIERAS RAHATA
cg-151@cg151:~/Final MA/A5$

Leave a Reply

Your email address will not be published. Required fields are marked *