;WRITE ALP FOR ADDITION OF ARRAY ELEMENTS in HEX(ADDITION OF N HEX NUMBER)

%macro print 2	;macro to print
    mov rax,1
    mov rdi,1
    mov rsi,%1
    mov rdx,%2
    syscall
%endmacro

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

SECTION .data
    msg1: db "Enter quantity of numbers to add: ",10
    len1: equ $-msg1
    msg2: db "Enter the hexadecimal numbers: ",10
    len2: equ $-msg2
    msg3: db 10d,"The sum is: "
    len3: equ $-msg3
    msg4: db " ",10
    len4:equ $-msg4

SECTION .bss
    input: resb 100
    result: resb 4
    count1: resb 2
    count2: resb 2
    count: resb 2
    num: resb 3

SECTION .text
    global _start
    _start:

   	 print msg1,len1   	;calling macro to print
   	 accept num,3      	;calling macro to accept
   	 call convert      	;calling procedure to convert ASCII to hex
   	 mov byte[count1],bl
   	 mov byte[count2],bl

   	 print msg2,len2
   	 mov r9,input
   	 array:      	;accept numbers and store it in the array	 
  			 accept num,3
  			 call convert
  			 mov [r9],bl
  			 inc r9
  			 dec byte[count1]
  			 jnz array
   	 mov r9,input
   	 mov al,00
   	 mov ah,00
   	 call add 	;calling procedure to add the numbers
   	 print msg3,len3
   	 print result,4
   	 print msg4,len4

   	 mov rax,60
   	 mov rdi,0
   	 syscall
 
convert: 	;procedure to convert ASCII to hex
    mov ch,02
    mov bl,00
    mov r10,0
    loop:
   		 mov al,[num+r10]
   		 cmp al,61H	;comparing for lower case letters
   		 jb next
   		 sub al,57H
  		 jmp next2
    next:
   		 cmp al,41h	;comparing for upper case letters
   		 jb next1
   		 sub al,37H
   		 jmp next2
    next1:
			 sub al,30H  ;comparing for numbers
    next2:
			 shl bl,04H
			 add bl,al
			 inc r10
			 dec ch
			 jnz loop
ret

add:  	;procedure to add and convert hex to ASCII
    mov bl,[r9]
    add ax,bx 	;to add numbers in the array
    inc r9
    dec byte[count2]
    jnz add
    ;to convert addition result
    mov r10,result
    mov byte[count],4
    l1:           	;to convert to ASCII
   		 rol ax,04H
   		 mov dl,al
   		 and dl,0FH
   		 cmp dl,09H
   		 jbe l2  
   		 add dl,07H
   	 l2:
   		 add dl,30H  
   		 mov[r10],dl
  		 inc r10
   		 dec byte[count2]
   		 jnz l1
ret

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: