;an ALP for 64 bit array addition
%macro dispmsg 2
mov rax,1
mov rdi,1
mov rsi,%1
mov rdx,%2
syscall
%endmacro
section .data
msg1 db 10,13,"how many nos you want to add",10,13
msg1len: equ $-msg1
msg2 db 10,13,"enter nos for addition",10,13
msg2len: equ $-msg2
msg3 db 10,13,"addition is :-",10,13
msg3len: equ $-msg3
carry db 0
section .bss
cnt resb 2
num resb 200
sum resb 200
section .text
global _start
_start:
dispmsg msg1,msg1len
;accept count
mov rax,0
mov rdi,0
mov rsi,cnt
mov rdx,3
syscall
;convert count
mov rcx,02
mov rsi,cnt
mov bl,0
lp4:rol bl,04
mov al,[rsi]
cmp al,39h
jg a
sub al,30h
jmp a1
a:sub al,37h
a1:add bl,al
inc rsi
loop lp4
mov [cnt],bl
dispmsg msg2,msg2len
;accept input from user
lp2:call acceptnum
call convertnum
add [sum],rbx
jc p
jmp skip
p:inc byte[carry]
skip:dec byte[cnt]
jnz lp2
;CNVERT OUTPUT TO ASCII NUM
call hextoascii
;DISPLAY OUTPUT
dispmsg msg3,msg3len
call displaynum
;TERMINATE PROGRAM
mov rax,60
mov rbx,0
syscall
;PROCEDURE TO CANVERT RESULT ONTO ASCII
hextoascii:
mov al,byte[carry]
cmp al,09h
jg aaaa
add al,30h
jmp aaaa1
aaaa:add al,37h
aaaa1:mov byte[carry],al
mov rbx,[sum]
mov rsi,sum
mov rcx,16
lp3:rol rbx,04
mov al,bl
and al,0fh
cmp al,09h
jg aaa
add al,30h
jmp aaa1
aaa:add al,37h
aaa1:mov[rsi],al
inc rsi
loop lp3
ret
;PROCEDURE TO DISPLAY OUTPUT
displaynum:
mov rax,1
mov rsi,carry
mov rdx,1
syscall
mov rax,1
mov rdi,1
mov rsi,sum
mov rdx,17
syscall
ret
;PROCEDURE TO ACCEPT INPUT
acceptnum:
mov rax,0
mov rdi,0
mov rsi,num
mov rdx,17
syscall
ret
;PROCEDURE TO CINVERT INPUT IN HEX
convertnum:
xor rbx,rbx
xor rax,rax
mov rcx,16
mov rsi,num
lp1:rol rbx,04
mov al,[rsi]
cmp al,39h
jg aa
sub al,30h
jmp aa1
aa:sub al,37h
aa1:add rbx,rax
inc rsi
loop lp1
ret
Blogger Comment
Facebook Comment