Please disable adblock to view this page.

← Go home

Adding array of N hexadecimal numbers (Assembly x86)

April 23, 2016
Published By : Pratik Kataria
Categorised in: ,

section .data
msg db 10,13,”Enter single digit count of numbers to add:”
msgl equ $-msg
msg1 db 10,13,”Enter four digit number:”
msgl1 equ $-msg1
msg2 db 10,13,”Addition is:”
msgl2 equ $-msg2

nwline db 10

cnt db 0
cnt1 db 0
arr times 80 db 0

section .bss
num resb 5
numcnt resb 2
disp_buff resb 4

%macro accept 2
mov eax,3
mov ebx,0
mov ecx,%1
mov edx,%2
int 80h

%macro disp 2
mov eax,4
mov ebx,1
mov ecx,%1
mov edx,%2
int 80h

section .text
global _start


disp msg,msgl
accept numcnt,2
mov al,[numcnt]
sub al,30h
mov [cnt],al
mov [cnt1],al
mov esi,arr

disp msg1,msgl1
accept num,5
call ascii_to_original
mov [esi],bx
add esi,2
dec byte[cnt]
jnz l1
disp msg2,msgl2
mov eax,0
mov esi,arr
mov bx,[esi]
add ax,bx
add esi,2
dec byte[cnt1]
jnz l6
mov bx,ax
call original_to_ascii
disp nwline, 1
mov eax,1
mov ebx,0
int 80h

mov edi,num
mov ecx,4
mov ebx,0

rol bx,4
mov al,[edi]
cmp al,39h
jbe l3
sub al,07h

sub al,30h
mov ah,0
add bx,ax
inc edi
loop l2

mov ecx,4
mov esi,disp_buff

rol bx,4
mov dl,bl
and dl,0fh
cmp dl,09h
jbe l5
sub dl,07h

add dl,30h
mov [esi],dl
inc esi
loop l4
disp disp_buff,4

View Article Page