ftp
to get two files from ftp://phred.dcccd.edu/pub/ltaber.
The files ate sample.S and sbr.S.
In the file sample.S there are instructions on how to assemble the code using the FSF gcc compiler.
Follow the instructions.
/* Louis Taber 11/1/97 PCC */ /* */ /* Sample program for assembly language */ /* subroutines on Linux. These are compiled */ /* and linked as follows: */ /* */ /* If compiled/assembled together. */ /* gcc -nostdlib -o sample sbr.S sample.S */ /* */ /* If comples as seperate modules. */ /* gcc -nostdlib -o sample sbr.o sample.S */ /* */ /* To assemble the library to object */ /* gcc -c sbr.S */ /* this will create the object file for the library */ #define FILE_STDIN $0 /* file handle for stdin */ #define FILE_STDOUT $1 /* file handle for stdout */ #define FILE_ERROR $1 /* file handle for stderror */ #define LINUX_SYS $0x80 /* interrupt for system calls */ /* Values for system calls */ /* defined in unistd.h */ #define LINUX_EXIT $1 #define LINUX_READ $3 #define LINUX_WRITE $4 .file "sample.S" .version "01.01" .data head: .string "Sample gcc/linux assembly" " language program\n\n" request: .string "Please input a hexadecimal number: " eop: .string "\nThe program is done.\n" hex: .string " Hexadecimal: " dec: .string " Decimal: " .text .align 16 .globl _start .type _start,@function _start: xorl %ebp,%ebp /* clear bp */ andl $0xfffffff8,%esi /* align stack to */ /* 8 byte boundry */ movl $head,%esi call pstring movl $request,%esi /* print out program heading */ call pstring call getline /* get input string */ call char2num /* convert to number */ movl $dec,%esi call pstring call pnumd /* print in decimal */ call new_line /* keep output neat */ movl $hex,%esi call pstring call pnumnl /* print in hex */ call new_line /* keep output neat */ movl $12,%ecx /* load loop counter */ movl $1,%eax /* starting point */ movl $2,%ebx /* for multiply */ loopa: call pnumd /* print decimal number */ movb $' ',%dl /* get a space */ call putchar /* print the space */ call pnumnl /* print number in hex */ mull %ebx /* factorial series */ inc %ebx loopl loopa movl $eop,%esi call pstring movl LINUX_EXIT,%eax /* exit code */ int LINUX_SYS /* call OS */ hlt /* exit should not return */ .align 16 .comm d,1,1 .ident "GCC: (GNU) 2.7.2.1"
The subroutines can be found at: ftp://phred.dcccd.edu/pub/ltaber/sbr.S.
Run the program, it puts out a factorial series.
Redirect the programs output through thesample
tee
command so that you
can print it.
Label it withsample | tee temp lpr temp
Place the lab in the instructor hand-in box in BUS R6E, the "terminal room".Your-Name Lab 4.3: assembly TABER CSC135