Write an Assembly Language Programs (ALP) to count positive and negative numbers from an array
Second Year Computer Engineering Microprocessor Programs:
Microprocessor Lab:
Practical 1:
1.Write an Assembly Language Programs (ALP) to count positive and negative numbers from an array:
---------------------------------------------------------------------------------------------------------------------------------%macro print 2
mov rax,1
mov rdi,1
mov rsi,%1
mov rdx,%2
syscall
%endmacro
section .data
msg db "Counting +ve and -ve elements of an array.",10
msglen equ $-msg
msg1 db "Positive nos. are : "
msglen1 equ $-msg1
msg2 db "Negetive nos. are : "
msglen2 equ $-msg2
array dq 1234h,90ffh,8700h,8800h,8a9fh,0a0dh,0200h
pcnt db 0
ncnt db 0
newline db 0xa
section .bss
dispbuff resb 2
section .txt
global _start
_start:
print msg,msglen
mov rsi,array
mov rcx,05
again:
bt qword[rsi],63
jnc pnxt
inc byte[ncnt]
jmp pskip
pnxt: inc byte[pcnt]
pskip: inc rsi
loop again
print msg1,msglen1
mov bl,[pcnt]
call disp_result
print newline,1
print msg2,msglen2
mov bl,[ncnt]
call disp_result
print newline,1
mov rax,60
mov rdi,0
Syscall
disp_result:
mov rdi,dispbuff
mov rcx,02
dispup1:
rol bl,4
mov dl,bl
and dl,0fh
add dl,30h
cmp dl,39h
jbe dispskip1
add dl,07h
dispskip1:
mov [rdi],dl
inc rdi
loop dispup1
print dispbuff,2
ret
----------------------------------------------------------------------------------------------------------------------------------
;********************************************Output*************************************
;admin1@admin:~$ nasm -f elf64 Num64.asm
;admin1@admin:~$ ld -o Num64 Num64.o
;admin1@admin:~$ ./Num64
;Counting +ve and -ve elements of an array.
;Positive nos. are : 03
;Negetive nos. are : 02
Comments
Post a Comment