CSC231 prog1.asm
--D. Thiebaut 15:00, 4 March 2011 (EST)
;;; prog1.asm
;;; D. Thiebaut
;;; a simple demo program to test I/O with
;;; a C "wrapper" program
;;;
;;; Assemble, link and run as follows:
;;; nasm -f elf asm_io.asm (do this only once)
;;; nasm -f elf prog1.asm
;;; gcc -o prog1 driver.c prog1.o asm_io.o
;;; ./prog1
;;;
%include "asm_io.inc"
%assign SYS_EXIT 1
;; -------------------------
;; data segment
;; -------------------------
section .data
msg db "Hello! Please enter an integer number: ",0
msg2 db "You have entered ",0
x dd 0
;; -------------------------
;; code area
;; -------------------------
section .text
global asm_main
asm_main:
mov eax,msg ; pass address of the string msg in eax
call print_string ; call a function in asm_io library
; that will print the string msg
call read_int ; call a function that reads an
mov [x], eax ; integer from the keyboard and
; returns it in eax. Save returned
; value in variable x
mov eax,msg2 ; print the string msg2
call print_string ; ("you have entered")
mov eax,[x] ; get integer user entered
call print_int ; pass it via eax and call the
; function specialized in printing
; integer numbers
call print_nl ; call the function that prints
; a new blank line
;; return to C program
ret