Tuesday, March 14, 2017

Write X86/64 ALP to convert 4-digit Hex number into its equivalent BCD number and 5-digit BCD number into its equivalent HEX number. Make your program user friendly to accept the choice from user for: (a) HEX to BCD b) BCD to HEX (c) EXIT. Display proper strings to prompt the user while accepting the input and displaying the result.(wherever necessary, use 64-bit registers)

                                            Savitribai Phule Pune University
                            Second Year of Computer Engineering (2015 Course)
                                                     210257: Microprocessor Lab

                                                                Assignment No.03

Problem Statement: Write X86/64 ALP to convert 4-digit Hex number into its equivalent BCD number and 5-digit BCD number into its equivalent HEX number. Make your program user friendly to accept the choice from user for:
(a) HEX to BCD b) BCD to HEX (c) EXIT.
Display proper strings to prompt the user while accepting the input and displaying the result.(wherever necessary, use 64-bit registers) 

;************************************************************
section .data
    menumsg db 10,10,'###### Menu for Code Conversion ######'
        db 10,'1: Hex to BCD'
        db 10,'2: BCD to Hex'
        db 10,'3: Exit'
        db 10,10,'Please Enter Choice::'
    menumsg_len equ $-menumsg
  

    hexinmsg db 10,10,'Please enter 4 digit hex number::'
    hexinmsg_len equ $-hexinmsg

    bcdopmsg db 10,10,'BCD Equivalent::'
    bcdopmsg_len equ $-bcdopmsg

    bcdinmsg db 10,10,'Please enter 5 digit BCD number::'
    bcdinmsg_len equ $-bcdinmsg

    hexopmsg db 10,10,'Hex Equivalent::'
    hexopmsg_len equ $-hexopmsg

;************************************************************

section .bss

    numascii resb 06  ;common buffer for choice, hex and bcd input
    outputbuff resb 02
    dispbuff resb 08

    %macro display 2
       mov rax,01
       mov rdi,01
       mov rsi,%1
       mov rdx,%2
       syscall
    %endmacro

       %macro accept 2
      mov rax,0
      mov rdi,0
      mov rsi,%1
      mov rdx,%2
      syscall
       %endmacro
;************************************************************
section .text

    global _start
_start:

menu:    display menumsg,menumsg_len
    accept numascii,2

    cmp byte [numascii],'1'
    je hex2bcd_proc



    cmp byte [numascii],'2'
    je bcd2hex_proc
  

    cmp byte [numascii],'3'
    je exit
    jmp _start

exit:
    mov rax,60
    mov rbx,0
    syscall
;************************************************************
hex2bcd_proc:
    display hexinmsg,hexinmsg_len
    accept numascii,5
    call packnum
    mov ax,bx  
    mov rcx,0
    mov bx,10        ;Base of Decimal No. system
h2bup1:    mov dx,0
    div bx
    push rdx
    inc rcx
    cmp ax,0
    jne h2bup1
    mov rdi,outputbuff

h2bup2:    pop rdx
    add dl,30h
    mov [rdi],dl
    inc rdi
    loop h2bup2
  
    display bcdopmsg,bcdopmsg_len
    display outputbuff,5
    jmp menu
;************************************************************
bcd2hex_proc:
    display bcdinmsg,bcdinmsg_len
    accept numascii,6

    display hexopmsg,hexopmsg_len

    mov rsi,numascii
    mov rcx,05
    mov rax,0
    mov ebx,0ah

b2hup1:    mov rdx,0
    mul ebx
    mov dl,[rsi]
    sub dl,30h
    add rax,rdx
    inc rsi
    loop b2hup1
    mov ebx,eax
    call disp32_num
    jmp menu
;************************************************************
packnum:
    mov bx,0
    mov ecx,04
    mov esi,numascii
up1:
    rol bx,04
    mov al,[esi]
    cmp al,39h
    jbe skip1
    sub al,07h
skip1:    sub al,30h
    add bl,al
    inc esi
    loop up1
    ret

;************************************************************
disp32_num:
    mov rdi,dispbuff    ;point esi to buffer
    mov rcx,08        ;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 [rdi],dl        ;store ASCII code in buffer
    inc rdi            ;point to next byte
    loop dispup1        ;decrement the count of digits to display
                ;if not zero jump to repeat

    display dispbuff+3,5    ;Dispays only lower 5 digits as upper three are '0'
  
    ret
;******************OUTPUT****************************************


;###### Menu for Code Conversion ######
;1: Hex to BCD
;2: BCD to Hex
;3: Exit

;Please Enter Choice::1


;Please enter 4 digit hex number::000F


;BCD Equivalent::15

;###### Menu for Code Conversion ######
;1: Hex to BCD
;2: BCD to Hex
;3: Exit

;Please Enter Choice::2


;Please enter 5 digit BCD number::00015


;Hex Equivalent::0000F

Monday, March 13, 2017

Write x86 ALP to find the factorial of a given integer number on a command line by using recursion. Explicit stack manipulation is expected in the code.

                                            Savitribai Phule Pune University
                            Second Year of Computer Engineering (2015 Course)
                                                     210257: Microprocessor Lab

                                                                Assignment No.09

Problem Statement: Problem Statement: Write x86 ALP to find the factorial of a given integer number on a command line by using recursion. Explicit stack manipulation is expected in the code.

;**************************************************************
section .data

    nummsg db "***Program to find Factorial of a number*** ",10
           db "Enter the number : ",
    nummsg_len equ $-nummsg

    resmsg db "Factorial is : "
    resmsg_len equ $-resmsg

    thankmsg db 10,"Thank you ",10
    thankmsg_len equ $-thankmsg

    zerofact db " 00000001 "
    zerofactlen equ $-zerofact


;************************************************************
section .bss

    dispbuff resb 16
    result resb 4
    num resb 1
    num1 resb 1
    numascii resb 3

    %macro display 2
       mov rax,01
       mov rdi,01
       mov rsi,%1
       mov rdx,%2
       syscall
    %endmacro

       %macro accept 2
      mov rax,0
      mov rdi,0
      mov rsi,%1
      mov rdx,%2
      syscall
       %endmacro    


;************************************************************
section .text
global _start
_start:
  
    display nummsg,nummsg_len
    accept numascii,3            ;accept number from user
    call packnum8_proc            ;convert number from ascii to hex
    mov [num],bl
  
    display resmsg,resmsg_len

    mov al,[num]            ;store number in accumulator
    cmp al,01h          
    jbe endfact

    mov bl,[num]
    call proc_fact
    mov rbx,rax
    call disp64_proc
    jmp exit
  

endfact:
    display zerofact,zerofactlen
  
exit:    display thankmsg,thankmsg_len

    mov rax,60
    mov rdi,0
    syscall
    ret

;************************************************************
disp64_proc:
    mov rdi,dispbuff    ;point esi to buffer
    mov rcx,16        ;load number of digits to display
dispup1:
    rol rbx,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 [rdi],dl        ;store ASCII code in buffer
    inc rdi            ;point to next byte
    loop dispup1        ;decrement the count of digits to display
                ;if not zero jump to repeat

    display dispbuff,16    ;
  
    ret
;************************************************************
packnum8_proc:
    mov bx,0
    mov ecx,02
    mov esi,numascii
up1:
    rol bl,04
    mov al,[esi]
    cmp al,39h
    jbe skip1
    sub al,07h
skip1:    sub al,30h
    add bl,al
    inc esi
    loop up1
    ret
;***********************Recursion*************************************
;There are two kinds of recursion: direct and indirect. 

;In direct recursion, the procedure calls itself and
;in indirect recursion, the first procedure calls a second ;procedure,which in turn, calls the first procedure.

proc_fact:
    cmp bl, 1
    jne do_calculation
    mov ax, 1
    ret
  
do_calculation:
    push rbx  
    dec bl
    call proc_fact
    pop rbx
    mul bl
    ret
;****************************************8
;[root@localhost vikas]# cd MIT2016/
;[root@localhost MIT2016]# nasm -f elf64 factorial.asm
;[root@localhost MIT2016]# ld -o factorial factorial.o
;[root@localhost MIT2016]# ./factorial
;***Program to find Factorial of a number***
;Enter the number : 04
;Factorial is : 0000000000000018
;Thank you
;[root@localhost MIT2016]#

Write 80386 ALP to implement multitasking. Where each task is supposed to change the color of the text displayed at the center of the screen

                                            Savitribai Phule Pune University
                            Second Year of Computer Engineering (2015 Course)
                                                     210257: Microprocessor Lab

                                                                Assignment No.14

Problem Statement: Write 80386 ALP to implement multitasking. Where each task is supposed to change the color of the text displayed at the center of the screen.

;****************************************************************

code segment
              
     assume cs:code,ds:code
start: mov ax,cs
     mov ds,ax
       mov cl,0
       mov ch,0

task1: inc cl
     cmp cl,09
       je exit
     mov ax,0b800h
       mov es,ax
       mov si,1830

       mov al,'*'
     mov ah,93h
     mov es:[si],ax
     inc bl
     mov al,bl
     add al,30h
     mov ah,93h
     inc si
      inc si

       mov es:[si],ax
       call delay

     jmp task2



task2: inc ch
     cmp ch,09
     je exit
     mov ax,0b800h
     mov es,ax
     mov si,840
     mov al,'$'
      mov ah,0A1h
     mov es:[si],ax
     inc bh
     mov al,bh
     add al,30h
     mov ah,0A1h
     inc si
     inc si

     mov es:[si],ax
       call delay

    jmp task1


    delay proc near
    mov ax,0fffh
    d2:mov dx,0fffh
   d1:nop
     nop
     nop
     nop
     dec dx
    jnz d1
    dec ax
    jnz d2
    ret
    endp



exit:
    mov ah,4ch
    int 21h

code ends
end start


Write a TSR to generate the pattern of the frequency tones by reading the Real Time Clock (RTC). The duration of the each tone is solely decided by the programmer.

                                        Savitribai Phule Pune University
                            Second Year of Computer Engineering (2015 Course)
                                                     210257: Microprocessor Lab

                                                                Assignment No.13



Problem Statement: Write a TSR to generate the pattern of the frequency tones by reading the Real Time Clock (RTC). The duration of the each tone is solely decided by the programmer.  

;*************************************************************

code segment
assume cs:code
org 100h                ;prog seg prefix addrss
jmp initze              ;hex no of 256
savint dd ?             ;for saving address of es:bx
count dw 0000h          ;count of tics

hours db ?
mins db ?
sec db ?

testnum:
        push ax    ;store all the contents of register
        push bx    ;(not to change original values of register)
        push cx
        push dx
        push cs
        push es
        push si
        push di

        mov ax,0b800h   ;starting address of display
        mov es,ax
        mov cx,count
        inc cx
        mov count,cx
        cmp cx,011h
      
      jne exit

        mov cx,0000h
        mov count,cx
        call time
exit:
        pop di
        pop si
        pop es
        pop ds
        pop dx
        pop cx
        pop bx
        pop ax
        jmp cs:savint   ;jump to normal isr

;------------------convert procedure--------------------
convert proc
        and al,0f0h
        ror al,4
        add al,30h
        call disp
        mov al,dh
        and al,0fh
        add al,30h
        call disp
        ret
endp

;------------------------time procedure----------------
time proc
        mov ah,02h      ;getting current time system clk
        int 1ah
        mov hours,ch    ;HH->ch, MM->cl, SS->dh
        mov mins,cl
        mov sec,dh

       ; mov bx,0E00h    ;location for displaying clk
  
       mov bx,3984
        mov al,hours       ;Display Hours
        mov dh,hours
        call convert
        mov al,':'
        call disp

        mov al,mins       ;Display Mins
        mov dh,mins
        call convert
        mov al,':'
        call disp


        mov al,sec       ;Display Seconds
        mov dh,sec
        call convert
    
       call tone
 
       ret
         endp


;-----------------------display procedue----------------
disp proc
        mov ah,9Ch      ;for setting attribute
                 ;ATTRIBUTE BYTE  BL  R  G  B  I  R  G  B  
                                         ;BACKGROUND FOREGROUND
       mov es:bx,ax    ;write into vedio buffer
        inc bx
        inc bx
        ret
endp

;--------------- frequency tone procedure-------------------

tone proc

       mov     al, 182         ; Prepare the speaker for the
        out     43h, al         ;  note.
        mov     ax, 4560        ; Frequency number (in decimal)                              
        out     42h, al         ; Output low byte.
        mov     al, ah          ; Output high byte.
        out     42h, al
        in      al, 61h         ; Turn on note (get value from
                                ;  port 61h).
        or      al, 00000011b   ; Set bits 1 and 0.
        out     61h, al         ; Send new value.
        mov     bx, 25          ; Pause for duration of note.
.pause1:
        mov     cx, 65535
.pause2:
        dec     cx
        jne     .pause2
        dec     bx
        jne     .pause1
        in      al, 61h         ; Turn off note (get value from
                                ;  port 61h).
        and     al, 11111100b   ; Reset bits 1 and 0.
        out     61h, al         ; Send new value.  
       ret
endp
;------------------initialization------------------------
initze:
        push cs
        pop ds
        cli             ;clear int flag

        mov ah,35h      ;35 for get orignal add
        mov al,08h      ;intrrupt no
        int 21h
        mov word ptr savint,bx
        mov word ptr savint+2,es

        mov ah,25h              ;25 for set int add
        mov al,08h
        mov dx,offset testnum   ;new add for intrrupt
        int 21h

        mov ah,31h              ;make prog resident(request tsr)
        mov dx,offset initze    ;size of program

        sti                    ;set intrrupt flag
        int 21h               
code ends
end



Thursday, March 9, 2017

Write X86/64 ALP to perform non-overlapped and overlapped block transfer (with and without string specific instructions). Block containing data can be defined in the data segment(i.e.overlapped Block Transfer)

                                                    Savitribai Phule Pune University
                            Second Year of Computer Engineering (2015 Course)
                                                     210257: Microprocessor Lab

                                                                Assignment No.2B

Problem Statement: Write X86/64 ALP to perform non-overlapped and overlapped block transfer (with and without string specific instructions). Block containing data can be defined in the data segment. 
;***********************************************************
;Assignmnet No. 2B
;Write X86/64 ALP to perform non-overlapped and overlapped block ;transfer (with and without string specific instructions). Block ;containing data can be defined in the data segment.
;..............................................................
; overlapped Block Transfer
;***********************************************************

section .data
    menumsg db 10,'##Menu for overlapped Block Transfer##',10
        db 10,'1.Block Overlap without using string instructions'
        db 10,'2.Block Overlap with using string instructions'
        db 10,'3.Exit',10,10
    menumsg_len equ $-menumsg
   

    blk_bfrmsg db 10,10,'Block contents before Overlap'
    blk_bfrmsg_len equ $-blk_bfrmsg

    blk_afrmsg db 10,'Block contents after Overlap',10
    blk_afrmsg_len equ $-blk_afrmsg

    srcmsg db 10,'Source block contents::'
    srcmsg_len equ $-srcmsg

    posmsg db 10,10,10,'Enter position to overlap::'
    posmsg_len equ $-posmsg
   
    spacechar db 20h
    spchlength equ $-spacechar

    srcblk db 01h,02h,03h,04h,05h,00h,00h,00h,00h,00h

;**********.bss Section**********************


section .bss
    optionbuff resb 02
    dispbuff resb 02
    numascii resb 03
    pos resb 00

%macro display 2
    mov rax,01
    mov rdi,01
    mov rsi,%1
    mov rdx,%2
    syscall
%endmacro

%macro accept 2
    mov rax,00
    mov rdi,00
    mov rsi,%1
    mov rdx,%2
    syscall
%endmacro

;**********Text Section**********************

section .text
    global _start
_start:
   
    display blk_bfrmsg,blk_bfrmsg_len
   
    call disp_src_blk_proc


    display posmsg,posmsg_len
   
    accept numascii,3

    call packnum_proc


menu:    display menumsg,menumsg_len
   
         accept optionbuff,02

         cmp byte [optionbuff],31H
         je wos
   
         cmp byte [optionbuff],32H           
         je ws      
exit:   
    mov rax,60        ;Exit
    mov rbx,00
    syscall
   
;**********Display Block Procedure**********************

disp_src_blk_proc:
        display srcmsg,srcmsg_len
        mov rsi,srcblk
        mov rcx,05h
        add cl,[pos]
       
    up1:push rcx
        mov bl,[rsi]
        push rsi
       
        call disp8_proc

        display spacechar,spchlength
        pop rsi
        inc rsi
        pop rcx
        loop up1
        ret

;************Without String Procedure***************
wos:
    mov rsi,srcblk+4
    mov rdi,rsi
    add rdi,[pos]

    mov rcx,05
blkup1:
    mov al,[rsi]
    mov [rdi],al
    dec rsi
    dec rdi
    loop blkup1

    display blk_afrmsg,blk_afrmsg_len
    call disp_src_blk_proc

    jmp exit
   
;************Using String Procedure****************
ws:   
    mov esi,srcblk+4
    mov edi,esi
    add edi,[pos]

    mov ecx,05

    std
    rep movsb

    display blk_afrmsg,blk_afrmsg_len
    call disp_src_blk_proc

    jmp exit

;************Display Procedure********************
disp8_proc:
    mov ecx,2
    mov edi,dispbuff
 dup1:
       rol bl,4
       mov al,bl
       and al,0fh
       cmp al,09
       jbe dskip
       add al,07h
dskip: add al,30h
       mov [edi],al
       inc edi
       loop dup1

    display dispbuff,2
    ret
 

;************Packnum Procedure********************
packnum_proc:
    mov bx,0
    mov ecx,2   
    mov esi,numascii
   
up2:    rol bl,4
    mov al,[esi]
    sub al,30h
    cmp al,09h
    jbe skip5
    sub al,07h
skip5:
    add bl,al
    inc esi
    loop up2
    mov [pos],bl
    ret
;*************Output*******************************

;[root@localhost MIT2016]# nasm -f elf64 Ass2B.asm
;[root@localhost MIT2016]# ld -o Ass2B Ass2B.o
;[root@localhost MIT2016]# ./Ass2B


;Block contents before Overlap
;Source block contents::01 02 03 04 05


;Enter position to overlap::02

;## Menu for overlapped Block Transfer ##

;1.Block Overlap without using string instructions
;2.Block Overlap with using string instructions
;3.Exit

;1

;Block contents after Overlap

;Source block contents::01 02 01 02 03 04 05 


[root@localhost MIT2016]#










                                                                                                           

Write X86/64 ALP to perform non-overlapped and overlapped block transfer (with and without string specific instructions). Block containing data can be defined in the data segment without string specific instructions). Block containing data can be defined in the data segment.(i.e.Non-overlapped Block Transfer)

                                                    Savitribai Phule Pune University
                            Second Year of Computer Engineering (2015 Course)
                                                     210257: Microprocessor Lab

                                                                Assignment No.2A

Problem Statement: Write X86/64 ALP to perform non-overlapped and overlapped block transfer (with and without string specific instructions). Block containing data can be defined in the data segment. 

;***************************************************************
;Assignmnet No. 2A
;Write X86/64 ALP to perform non-overlapped and overlapped block ;transfer (with and without string specific instructions). Block ;containing data can be defined in the data segment.
;..........................................................
; Non-overlapped Block Transfer
;***************************************************************
section .data
 menumsg db 10,'##Menu for Non-overlapped Block Transfer##',10
       db 10,'1.Block Transfer without using string instructions'
       db 10,'2.Block Transfer with using string instructions'
       db 10,'3.Exit',10
 menumsg_len equ $-menumsg
  
 blk_bfrmsg db 10,'Block contents before transfer'
 blk_bfrmsg_len equ $-blk_bfrmsg

 blk_afrmsg db 10,'Block contents after transfer'
 blk_afrmsg_len equ $-blk_afrmsg

 srcmsg db 10,'Source block contents::'
 srcmsg_len equ $-srcmsg

 dstmsg db 10,'Destination block contents::'
 dstmsg_len equ $-dstmsg

 srcblk db 01h,02h,03h,04h,05h
 dstblk db 00,00,00,00,00
  
 spacechar db 20h
 spchlength equ $-spacechar
  
;****************.bss Section***************************
section .bss
    optionbuff resb 02
    dispbuff resb 02

%macro display 2
    mov rax,01
    mov rdi,01
    mov rsi,%1
    mov rdx,%2
    syscall
%endmacro

%macro accept 2
    mov rax,00
    mov rdi,00
    mov rsi,%1
    mov rdx,%2
    syscall
%endmacro

;*******************.text Section**************************
section .text
    global _start
_start:
  
    display blk_bfrmsg,blk_bfrmsg_len
  
    call dispsrc_blk_proc

    call dispdest_blk_proc

   menu: display menumsg,menumsg_len
  
         accept optionbuff,02

         cmp byte [optionbuff],31h
  
         je wos
  
         cmp byte [optionbuff],32h          

         je ws

  
exit:    mov rax,60        ;Exit
         mov rbx,00
         syscall
  
;**************Display Source Block Procedure****************
  
dispsrc_blk_proc:
        display srcmsg,srcmsg_len
        mov rsi,srcblk
        mov rcx,05h
      
    up1:push rcx
        mov bl,[rsi]
        push rsi
      
        call disp8_proc

        display spacechar,spchlength
        

pop rsi
        inc rsi
        pop rcx
        loop up1
        ret

;**************Display Destination Block Procedure*************

dispdest_blk_proc:
        display dstmsg,dstmsg_len
        mov rdi,dstblk
        mov rcx,05
      
    up2:push rcx
        mov bl,[rdi]
        push rdi
      
        call disp8_proc

        display spacechar,spchlength
                                                                         pop rdi
        inc rdi
        pop rcx
        loop up2
        ret

;**************Without String Procedure************
wos:
    mov rsi,srcblk
    mov rdi,dstblk
    mov rcx,05                                                                                                                    

         again: mov bl,[rsi]
                mov [rdi],bl
                inc rsi
                inc rdi
                loop again

         display blk_afrmsg,blk_afrmsg_len
         call dispsrc_blk_proc
         call dispdest_blk_proc
         jmp menu
                                                              ;************Using String Procedure****************  

ws:
    mov rsi,srcblk
    mov rdi,dstblk
    mov rcx,05
                                                                
     cld                                                              rep movsb

    display blk_afrmsg,blk_afrmsg_len
    call dispsrc_blk_proc
    call dispdest_blk_proc
    jmp menu

;************Display Procedure********************
 

disp8_proc:
    mov rsi,dispbuff
    mov rcx,02


dup1:
    rol bl,4
    mov dl,bl
    and dl,0Fh
    cmp dl,09H
    jbe dskip
    add dl,07h

dskip:add dl,30h
      mov [rsi],dl
      inc rsi
      loop dup1

      display dispbuff,02
  
      ret

;*************Output*******************************
;[root@localhost A2]# nasm -f elf64 Ass2A.asm
;[root@localhost A2]# ld -o Ass2A Ass2A.o
;[root@localhost A2]# ./Ass2A

;Block contents before transfer
;Source block contents::01 02 03 04 05
;Destination block contents::00 00 00 00 00

;##### Menu for Non-overlapped Block Transfer #####

;1.Block Transfer without using string instructions
;2.Block Transfer with using string instructions
;3.Exit
;1

;Block contents after transfer
;Source block contents::01 02 03 04 05
;Destination block contents::01 02 03 04 05

;##### Menu for Non-overlapped Block Transfer #####

;1.Block Transfer without using string instructions
;2.Block Transfer with using string instructions
;3.Exit
;3
;[root@localhost A2]# 











                                                                                                           

Write X86/64 ALP to count number of positive and negative numbers from the array.

                                                    Savitribai Phule Pune University
                            Second Year of Computer Engineering (2015 Course)
                                                     210257: Microprocessor Lab

                                                                Assignment No. 1 

Problem Statement: Write X86/64 ALP to count number of positive and negative numbers from the array.

;*************************************************************
section .data

nline db 10,10
nline_len equ  $-nline

arr dd  -11111111H, 22222222H, -33333333H, -44444444H, -55555555H
arr_size equ 5

pmsg db   10,10,"The no. of Positive elements in 32-bit array:"
pmsg_len equ $-pmsg

nmsg  db  10,10,"The no. of Negative elements in 32-bit array:"

nmsg_len equ $-nmsg

;*************************************************************
section  .bss

p_count  resq   01
n_count  resq   01
dnumbuff resb   02


%macro display 2
    mov rax,01
    mov rdi,01
    mov rsi,%1
    mov rdx,%2
    syscall
%endmacro

;***********************************************************

section .text
global   _start
_start:

    mov    esi, arr
    mov    ecx,5         ;Arraay counter i.e.5   
    mov    ebx,0;        ; counter for     +ve nos.
    mov    edx,0;        ; counter for    -ve nos.

next_num:
    mov    eax,[esi]    ; take no. in RAX
    rcl    eax,1        ; rotate left 1 bit to check for sign bit
    jc    negative

positive:
    inc    ebx            ; no carry, so no. is +ve
    jmp    next

negative:
    inc    edx            ; carry, so no. is -ve

next:
    add  esi,4                ; 32 bit nos i.e. 4 bytes
    loop next_num

    mov [p_count], ebx        ; store positive count
    mov [n_count], edx        ; store negative count

    display pmsg, pmsg_len
    mov ebx,[p_count]         ; load value of p_count in rax
    call disp8_proc           ; display p_count

    display nmsg, nmsg_len
    mov ebx,[n_count]        ; load value of n_count in rax
    call  disp8_proc         ; display n_count

    display    nline, nline_len

  exit: 

    mov rax,60        ;Exit
    mov rbx,00
    syscall


;**********************************************************
disp8_proc:
    mov edi,dnumbuff    ;point edi to buffer
    mov ecx,02        ;load number of digits to display

dispup1:
    rol bl,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

    display dnumbuff,2    

    ret

;****************Output**************************************
;[root@localhost A1]# nasm -f elf64 A1.asm
;[root@localhost A1]# ld -o A1 A1.o
;[root@localhost A1]# ./A1


;The no. of Positive elements in 32-bit array :    01

;The no. of Negative elements in 32-bit array :    04

;[root@localhost A1]#