CSC231 Homework 2 2014
--D. Thiebaut (talk) 09:48, 21 September 2014 (EDT)
This homework is due on Tuesday, Sept. 30th, at 11:55 p.m.
Problem 1
- Create a program called IOskel.asm using your 231a-xx account, on a Linux machine (beowulf2, grendel, or any of the Linux Mint PCs in FH342 or FH345, and copy this code in it:
;;; -----------------------------------------------------
;;; IOskel.asm
;;; D. Thiebaut
;;; Simple skeleton program illustrating how to get an
;;; integer from the command line and displaying it back
;;;
;;; To assemble, link and run:
;;; nasm -f elf 231Lib.asm
;;; nasm -f elf IOskel.asm
;;; ld -melf_i386 IOskel.o 231Lib.o
;;; ./IOskel
;;; -----------------------------------------------------
;;; extern functions that will be linked to this program
;;; contained in 231Lib.asm
extern _printDec
extern _printString
extern _println
extern _getInput
;;; -----------------------------------------------------
;;; data section
;;; -----------------------------------------------------
section .data
x dd 0 ; the integer used for IO
msgX db "x = "
prompt db "> "
;;; -----------------------------------------------------
;;; code section
;;; -----------------------------------------------------
section .text
global _start
_start:
;;; get number from user
mov ecx, prompt
mov edx, 2
call _printString
call _getInput
mov dword[x], eax
;;; print "x = dddd" where dddd is the contents of x
;;; in decimal
mov ecx, msgX
mov edx, 4
call _printString
mov eax, dword[x]
call _printDec
call _println
;;; ; exit
mov ebx, 0
mov eax, 1
int 0x80
</source>