Vous êtes sur la page 1sur 7

Extra credit triple x86 assembly projects

Note: You may do these projects to improve your grade, but it is not required.
Cannot lower your grade.

Project No.1:

What to turn in:

your assembly file: pr1-grep.asm

What to do:

Write a program which perform similarly to the basic function of the Linux
"grep" command with the "-n" option (line numbers), doing a simple word search.

A command line using your program should look like:

o ./Lab0x05-grep searchword

And should do the (almost) same thing as

o grep -n searchword

o except you do not need to do colors

o but you do need to do line numbers

Requirements:

For full credit, your program

o must get the string to search for from the first command line
argument

o must ignore any other command line arguments


o must correctly process text from standard input, regardless of
source

from the user

./Lab0x05-grep Waldo

from a redirected file

./Lab0x05-grep Waldo < somefile.txt

from a pipe:

ls -l | ./Lab0x05-grep Waldo

o must print the line number a colon a space and the entirety of
any line containing text that matches the string given as the first command
line argument

o must After each output matching line, the next line should put
carets "^^^^^^" underneath the first matching text in that line

o must stop on end-of-file

o for lines up to 255 characters long:

must work normally, printing entire matching lines

do not split, truncate, combine any lines up to 255


characters

o must, for lines longer than 255 characters (worry about this
requirement last)

discard 255 character chunks of the line until a match is


found, then

then print "**truncated**" before printing the rest


of the line, including the section that contains the first match

o must NOT allow buffer overflow

o should NOT print any prompt (just like grep)

For full credit, your program


o does not need to handle regular expressions like grep does

just treat first argument as a simple string to search for

o does not need to color the output text the way grep does
in Linux Mint or other terminal

though if you want to figure out the ascii or ncurses


tricks to color the output text to highlight the searchword in the output
lines, you may do that instead of putting carets under the search word in
the next line.

Tips:

The following standard C library functions (and symbols) are most likely
going to be useful:

o fgets()

fgets reads up to one whole line, but has a parameter to


limit the number of character's read in, so you can avoid overflowing your
buffer.

fgets needs a file pointer to standard input, which is also


defined in the C libraries -- stdin

so you will need...

extern stdin

...just as with the library function


names

o printf()

o strstr()

search for a string within another string ("find substring")

Note that if found, the return value is a pointer to the first


character of the found substring within the string you are searching...

...so the difference between that address and the


address of the searched string may help determine the number of
spaces to print before the carets (" ^^^^").

o strlen()
argc and argv go on the stack as parameters for _start (or main) to
use.

o Pay attention to the class video where we discuss this.

o Also google: nasm assembly 386 command line arguments

Project No.2:

What to turn in:

Your assembly language program file: pr2.asm

What to do:

Write an assembly program that prints its command line arguments


(strings) in lexically sorted order.

"Lexically sorted" (for this lab) means sorted in the order determined
by the standard C library function strcmp.

o The precedence of symbols in a pair of strings is determined by


their ascii code

...so uppercase & lowercase are not the same "letter" for
purposes of lexical sorting by strcmp:

A..Z all come before a..z

"aXe" before "annual"

o This behavior is all done for you by strcmp

--so there is nothing special you need to do, -- just


use strcmp to decide which string comes before another string

This boils down to doing a "bubble sort", "selection sort" or any other
simple sort you want to do.
o Hint: google "bubble sort", "selection sort" if you have any doubt
about what those algorithms look like.

o Here is just about the simplest way to sort N things:

(loop) Repeat N times (loop):

(loop within loop) For each item in the list, up to the


2nd to last item do:

If the next item comes before this item, then


swap them.

o Tips:

Swap the pointers to the strings, don't try to swap the


character data!

After a swap & move another step down the list, you end
up comparing the same item to the next next item, and so on.

Treat your "_start"

argc and argv are the first and second


parameters.

The elements of argv are pointers to strings

The argv array is right on the stack

Watch the Week 15 Monday video

Project No.3:

What to turn in:

Your assembly language program: pr3.asm


Read about 1-Dimensional "life"
here: http://jonmillen.com/1dlife/index.html

We will be using the "rules" from the above website.

Experiement with the 1D life simulator on that page to get a


better feel for how it works.

I highly encourage you to google "conway's game of life" and learn


more about the 2D version. It is very interesting. (but for this lab, we are sticking
to the 1D version).

Challenge: For additional extra credit, try making a 2D Game of


Life simulator

Google for methods of "clearing the screen" in C


programming and Linux

Redraw the screen each generation

You may want to look at the Assemblipede game for it's


method of clearing/redrawing, using ncurses

Similar to Assembliped it should take a file name as a


command line argument, then open&read that file to get the initial Life
population.

Instructions: Your program should take a single command line


argument which is a string representing the initial or "seed" population

Use hash marks '#' for "live" cells, and spaces ' ' for "dead" or
empty cells:

Note: in bash shell, you can use double-quotes around a


command line argument that needs to include spaces:

./Lab0x0B-1Dlife " ## # # # ## ## # "

if your program detects something other than a space ' ' or


hash mark '#' in the argument then it should...

...exit by telling a joke

The size of this initial string should also limit the size of the
population

i.e. do not let your output lines grow or shrink


your program prints out the command line arguement as the first line
of output...

...then it produces & prints each next generation on next line

pausing for user to press a [enter]

if user enters, Q then quit

Use these rules to determine the next line from the current line:

For each character:

count how many neighboring hash marks within 2


steps

(do not count itself)

A space ' ' becomes a hash '#' (new cell is


born) if...

...it has 2 or 3 "live" neighbors (2 or 3 hash


'#' neighbors)

Otherwise the space stays a space (empty


cell stays empty)

A hash '#' becomes a space ' ' (a live cell dies) if...

...it has 0, 3, or 5hash '#' neighbors (living


neighbors)

Otherwise it remains alive (stays as a hash


'#')

Again, you may do this lab to improve your grade, but it is not required.
Cannot lower your grade.

Good luck with end of semester and Finals ahead.

Vous aimerez peut-être aussi