Addition.asm
%macro print 2
mov rax,1
mov rdi,1
mov rsi,%1
mov rdx,%2
syscall
%endmacro
%macro read 2
mov rax,0
mov rdi,0
mov rsi,%1
mov rdx,%2
syscall
%endmacro
SECTION .data
msg1: db"Enter how many numbers you want to add??",0xA
len1: equ $-msg1
msg2: db"Enter the number::",0xA
len2: equ $-msg2
msg3: db"Addition of the numbers::"
len3: equ $-msg3
SECTION .bss
number: resb 20
count: resb 1
result : resb 20
reserveh : resb 2
reservel : resb 2
SECTION .text
global main:
main:
print msg1,len1
read number,20
call convert_Number
mov [count],bl
loop6:
print msg2,len2
read number,20
call convert_Number
add [reservel],bl
adc byte[reserveh],0
dec byte[count]
jnz loop6
mov bl,[reservel]
mov bh,[reserveh]
mov [result],bx
call convert_Result
print msg3,len3
print result,20
mov rax,60
mov rdi,0
syscall
convert_Number:
mov esi,number
mov bl,00
mov ecx,2
loop1:
rol bl,04
mov al,[esi]
cmp al,39h
jbe loop2
sub al,07h
loop2:
sub al,30h
add bl,al
inc esi
loop loop1
RET
convert_Result:
mov esi,result
mov ecx,4
loop3:
rol bx,04
mov al,bl
and al,0Fh
cmp al,09h
jbe loop4
add al,07h
loop4:
add al,30h
mov [esi],al
inc esi
loop loop3
RET
%macro print 2
mov rax,1
mov rdi,1
mov rsi,%1
mov rdx,%2
syscall
%endmacro
%macro read 2
mov rax,0
mov rdi,0
mov rsi,%1
mov rdx,%2
syscall
%endmacro
SECTION .data
msg1: db"Enter how many numbers you want to add??",0xA
len1: equ $-msg1
msg2: db"Enter the number::",0xA
len2: equ $-msg2
msg3: db"Addition of the numbers::"
len3: equ $-msg3
SECTION .bss
number: resb 20
count: resb 1
result : resb 20
reserveh : resb 2
reservel : resb 2
SECTION .text
global main:
main:
print msg1,len1
read number,20
call convert_Number
mov [count],bl
loop6:
print msg2,len2
read number,20
call convert_Number
add [reservel],bl
adc byte[reserveh],0
dec byte[count]
jnz loop6
mov bl,[reservel]
mov bh,[reserveh]
mov [result],bx
call convert_Result
print msg3,len3
print result,20
mov rax,60
mov rdi,0
syscall
convert_Number:
mov esi,number
mov bl,00
mov ecx,2
loop1:
rol bl,04
mov al,[esi]
cmp al,39h
jbe loop2
sub al,07h
loop2:
sub al,30h
add bl,al
inc esi
loop loop1
RET
convert_Result:
mov esi,result
mov ecx,4
loop3:
rol bx,04
mov al,bl
and al,0Fh
cmp al,09h
jbe loop4
add al,07h
loop4:
add al,30h
mov [esi],al
inc esi
loop loop3
RET
No comments:
Post a Comment