MA: addition of 2 numbers


section .data
    input:db 'enter the number',10   ;
  
    inputLen:  equ $-input           ;
                                  ;
    display:db 'entered number is:',10   ;
  
    displayLen:  equ $-display       ;

    addition:db 'addtion of number is',10;
    additionLen: equ $-addition;

                                  ;


section .bss
a resb 3  
b resb 3
r resb 3


section .text
    global _start

_start:
    mov rax,1         ;string:enter number
    mov rdi,1            ;file discriptor
    mov rsi,input        ;input
    mov rdx,inputLen     ;lenght of input
                         ;
    syscall              ; Call the kernel

  
    mov rax,0         ;input
    mov rdi,0            ;standard input
    mov rsi,a       ;
    mov rdx,2          ;read only first two number
                         ;
    syscall              ;Call the kernel........

         
    mov rax,1         ;string2
    mov rdi,1            ;
    mov rsi,input        ;
    mov rdx,inputLen     ;
                         ;
    syscall              ; Call the kernel

    mov rax,0         ;input2
    mov rdi,0            ;
    mov rsi,b        ;
    mov rdx,2     ;
                         ;
    syscall              ; Call the kernel.....

     

    XOR RAX,RAX ;addition of 2 numbers
    MOV AL,[a]
    sub al,30h
    MOV BL,[b]
    sub bl,30h
    ADD AL,BL
    ADD al,30h
    MOV [r],AL
    syscall

    mov rax,1         ;string2
    mov rdi,1            ;
    mov rsi,addition      ;
    mov rdx,additionLen    ;
    syscall

    mov rax,1
    mov rdi,1
    mov rsi,r
    mov rdx,3


    syscall   
    mov rax,60                ; The system call for exit (sys_exit)
    mov rbx,0                ; Exit with return code of 0 (no error)
    syscall            ;


[apcoer@localhost ~]$ nasm -f elf64 add.asm
[apcoer@localhost ~]$ ld -o add add.o
[apcoer@localhost ~]$ ./add
enter the number
1
enter the number
2
addtion of number is
3

Comments

Popular posts from this blog

NASM: program to find largest number from an array of 32-bit numbers(hard-coded)

Rules for drawing a FLOWCHART