CSC231 Add5.asm

From dftwiki3
Jump to: navigation, search

;;; add5.asm
;;; D. Thiebaut
;;; 
;;; takes 5 variables, and store sum 6th one.
;;;
;;; to assemble, run and debug:
;;;
;;;     nasm -f elf -F  stabs add5.asm
;;;     ld -o add5 add5.o
;;;     ddd add5  &
;;; -------------------------------------------------------------------

;%include files here...

EXIT    equ             1
WRITE   equ             4
STDOUT  equ             1
        
        ;; ------------------------------------------------------------
        ;; data areas
        ;; ------------------------------------------------------------

        section .data
a       dd      3
b       dd      5
c       dd      8
d       dd      1
e       dd      4
result  dd      0        
        
        ;; ------------------------------------------------------------
        ;; code area
        ;; ------------------------------------------------------------

        section .text
        global  _start

_start:
        nop
        nop
        mov     eax,dword[a]
        add     eax,dword[b]
        add     eax,dword[c]
        add     eax,dword[d]
        add     eax,dword[e]
        mov     dword[result],eax
        

        ;; exit()

        mov     eax,EXIT
        mov     ebx,0
        int     0x80            ; final system call