Adding array of N hexadecimal numbers (Assembly x86)
April 23, 2016
Categorised in: Assembly Codes, MIT Codes
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 %endmacro %macro disp 2 mov eax,4 mov ebx,1 mov ecx,%1 mov edx,%2 int 80h %endmacro section .text global _start _start: disp msg,msgl accept numcnt,2 mov al,[numcnt] sub al,30h mov [cnt],al mov [cnt1],al mov esi,arr l1: 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 l6: 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 ascii_to_original: mov edi,num mov ecx,4 mov ebx,0 l2: rol bx,4 mov al,[edi] cmp al,39h jbe l3 sub al,07h l3: sub al,30h mov ah,0 add bx,ax inc edi loop l2 ret original_to_ascii: mov ecx,4 mov esi,disp_buff l4: rol bx,4 mov dl,bl and dl,0fh cmp dl,09h jbe l5 sub dl,07h l5: add dl,30h mov [esi],dl inc esi loop l4 disp disp_buff,4 ret
Pratik Kataria is currently learning Springboot and Hibernate.
Technologies known and worked on: C/C++, Java, Python, JavaScript, HTML, CSS, WordPress, Angular, Ionic, MongoDB, SQL and Android.
Softwares known and worked on: Adobe Photoshop, Adobe Illustrator and Adobe After Effects.