CSC231 prog2.asm
--D. Thiebaut 15:03, 4 March 2011 (EST)
;;; prog2.asm
;;; D. Thiebaut
;;; a simple demo program to add 2 numbers
;;; together, and store the sum in a 3rd variable
;;;
;;; Assemble, link and run as follows:
;;; nasm -f elf asm_io.asm (do this only once)
;;; nasm -f elf prog2.asm
;;; gcc -o prog2 driver.c prog2.o asm_io.o
;;; ./prog2
;;;
%include "asm_io.inc"
%assign SYS_EXIT 1
;; -------------------------
;; data segment
;; -------------------------
section .data
a dd 3
b dd 5
result dd 0
;; -------------------------
;; code area
;; -------------------------
section .text
global asm_main
asm_main:
mov eax,[a]
add eax,[b]
mov [result],eax
mov eax,[result] ; pass result to print_int
call print_int ; and print value
call print_nl ; call the function that prints
; a new blank line
;; return to C program
ret