Tuesday, 5 April 2016

Assembly Language: Finding the largest number

Q: Write an ALP to find the largest number in a given set of  numbers.


Assembler: Nasm
OS : Ubuntu 14.04 LTS(64 bit Linux)


Code

 
SECTION .data

 msg1: db ' ',10
 len1: equ $-msg1
 msg: db "The Largest number is:",10
 len: equ $-msg
 c : db 5h
 array : db 0x11,0x42,0xFE,0xAB,ox77

SECTION .bss
 count : resb 3
 array resd 8

 %macro write 2
 mov eax,4
 mov ebx,1
 mov ecx,%1
 mov edx,%2
 int 80h
 %endmacro

global _start
SECTION .txt
_start:
 mov esi,array
u:      
 mov al,[esi]
 INC esi
 cmp al,byte[esi]
 jbe l2
 xchg bl,al
l2:
 DEC byte [c]
 jnz u
 call convert 
 write msg,len
 write result,2

 mov eax,1
 mov ebx,0
 int 80h

convert:

mov esi,result
mov byte[count],02

up: rol bl,04
mov bl,al
AND bl,0Fh
CMP bl,09
jbe l1
ADD bl,07h
l1: ADD bl,30h
mov [esi],bl
INC esi
DEC byte[count]
jnz up
RET



No comments:

Post a Comment