ASSIGNMENT 4
section .data
msg db 10,"The maximum number from given array : ",
len equ -newline
arr dw 2h,54h,4h,5h,7h
section .bss
cnt resb 1
buff resb 16global _start
section .data
imsg db 10,'Enter the String : '
len1 equ -omsg
nl db 10
len_nl equ -buf
len resb 1
%macro print 2
mov rax, 1
mov rdi, 1
mov rsi, %1
mov rdx, %2
syscall
%endmacro
%macro accept 2
mov rax, 0
mov rbx, 0
mov rcx, %1
mov rdx, %2
syscall
%endmacro
%macro exit 0
mov rax, 60
mov rdi, 0
syscall
%endmacro
section .text
_start:
print imsg, len1 ;display input prompt msg
accept buf, buf_len
dec al ;Decrementing coubt for avoiding string termination character
mov [len], al ;Save Length
print omsg, len2 ;display output msg
mov bl, [len] ;Restore length
call display ;call display procedure
print nl, len_nl
exit
display:
mov rdi, dispbuff ;point rdi to buffer
mov rcx, 2 ;load number of digits to display
disp1:
rol bl, 4 ;rotate number to left by nibble
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 skip ;if less than 39h skip adding 07
add dl, 07h ;else add 07
skip:
mov [rdi], dl ;store ASCII code in buff
inc rdi ;point to next byte
loop disp1 ;decrement count of digits to display
print dispbuff, 2 ;display max number
ret
%macro print 2
mov rax,1
mov rdi,1
mov rsi,%1
mov rdx,%2
syscall
%endmacro
section .text
global _start
_start:
mov byte[cnt], 5
mov rsi, arr
mov al, 0
lp:
cmp al, [rsi]
jg skip
xchg al, [rsi]
skip:
inc rsi
dec byte[cnt]
jnz lp
call disp
print msg, len
print buff, 16
print newline, nlen
mov rax, 60
mov rdi, 0
syscall
disp:
mov rbx, rax
mov rdi, buff
mov cx, 16
up1:
rol rbx, 04
mov al, bl
and al, 0fh
cmp al, 09h
jg add_37
add al, 30h
jmp skip1
add_37:
add al, 37h
skip1:
mov [rdi], al
inc rdi
dec cx
jnz up1
ret