%macro s 4 mov rax,%1; mov rdi,%2; mov rsi,%3; mov rdx,%4; syscall %endmacro section .data msg db "Addition of numbers is " msgLen equ $-msg arr db 8,1,3,7,5 ;declare the numbers in the array newline db "",10 section .bss sum resw 2 temp resb 2 section .text global _start _start: s 1,1,msg,msgLen mov rsi, arr ;move the register source index to the first element in the array mov ax, 00h ;initialize contents of accumulator and register b to 0 mov bx, 00h mov cx, 5 ;set the counter to 5 up2: mov bl, byte[rsi] add ax, bx jnc skip inc ah skip: inc rsi ;go to the next location dec cx ;decrement the counter jnz up2 mov word[sum],ax mov bp, 4 mov ax, word[sum] up: ;simple hex to ascii conversion rol ax, 4 mov bx, ax and ax, 0fh cmp al, 09 jbe down add al, 07 down: add al, 30h mov [temp], al s 1, 1,temp, 1 mov ax, bx dec bp jnz up s 1,1,newline,1 ;print the newline character mov rax, 60 ;exit sequence mov rdi,0 syscall
To embed this project on your website, copy the following code and paste it into your website's HTML: