CSC231 Homework 5 Fall 2017
--D. Thiebaut (talk) 09:27, 30 October 2017 (EDT)
Preparation
For this assignment you will need to downloaded an updated version of 231Lib.asm, which has been augmented with a new function for reading strings.
getcopy 231Lib.asm
An example program using the new function, _getString(), is shown below:
;;; ; hw5Prep.asm ;;; ; D. Thiebaut ;;; ; ;;; ; Gets a string from the user and prints it back ;;; ; ;;; ; to assemble and run: ;;; ; ;;; ; nasm -f elf hw5Prep.asm ;;; ; nasm -f elf 231Lib.asm ;;; ; ld -melf_i386 -o hw5Prep hw5Prep.o 231Lib.o ;;; ; ./hw5Prep ;;; ; ------------------------------------------------------------------- ;;; ------------------------------------------------------------ ;;; data areas ;;; ------------------------------------------------------------ section .data prompt db "> " ;;; ------------------------------------------------------------ ;;; code area ;;; ------------------------------------------------------------ section .text global _start extern _getString extern _printString extern _println _start: ;; prompt the user mov ecx, prompt mov edx, 2 call _printString ;; get a string from the user ;; _getString returns the address of the string read in ecx, ;; and the number of chars read in edx call _getString ;; since ecx and edx already contain the address and number ;; of chars, we can directly call _printString, which needs ;; the string and number of chars in the same registers call _printString ;; print a line-feed char. call _println ;;; exit() mov eax,1 mov ebx,0 int 0x80 ; final system call