![]() | ![]() | ![]() | 4.3 Run an assembly program |
cp command. Remember that you need to specify a destination.
A "." specifies the current directory. You can also use wild cards.
An "*" matches any number of any characters. So if you do:
cp ~CIS135/*.S .gortwill copy the two assembly language files from the class area to your current directory.
Use ftp
to get two files from ftp://lt.tucson.az.us/pub/.
The files are 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 complies as separate 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://lt.tucson.az.us/pub/sbr.S.
Run the program, it puts out a factorial series.
sampleRedirect the programs output through the
tee command so that you
can print it.
sample | tee temp lpr tempLabel it with
Your-Name Lab 4.3: assembly TABER CIS135Place the lab in the instructor hand-in box in BUS R6E, the "terminal room".
![]() | ![]() | ![]() | 4.3 Run an assembly program |