|
|
New Articles:
Southern California Glider Landout Database Soaring 5-Inch Sky Robot FDM in Vacuum Gin Books Hacktastic e-bike Farnsworth Fusor Land Anchor Turchickentato Bowmaking Custom Discovery Roof Rack August, 2012 - Sierra Backpacking July 22nd, 2012 - Hiking in Santa Barbara July 15th, 2012 - Valley of Fire May 5th, 2012 - Afton Canyon April 28th, 2012 - Devils Playground Alpine Tripod Convict Creek Trail January 2012 - Mustangs January 3rd, 2012 - Heart Lake August 7th, 2011 - Kelso Dunes August 5th, 2011 - Lundy Canyon Hike August 2011, Mammoth Archery Birds in the garden June 4th, 2011 - San Gorgonio May 29th, 2011 - Sequoia National Forest April 23rd, 2011 - Living Desert April 2nd, 2011 - Death Valley March 8th, 2011 - Mountain Palm Springs February 13th, 2011 - Iron Smelt Blacksmithing November 13th, 2010 - Mojave October, 2010 - Mammoth Android September, 2010 - Mammoth September, 2010 - Duck Lake Trail Backpacking Red Iron bloom forging August 28th, 2010 - Mt. San Jacinto OSM Import: US Designated Wilderness July 25th, 2010 - Mojave Mustangs July 17th, 2010 - Mojave Exploration Bloomery furnace iron smelting Open Street Map: Mojave Project June 13th, 2010 - Mojave June 6th, 2010 - El Cajon Trails Wolf Mountain Sanctuary Carrizo Gorge March 28th, 2010 - Salton Sea March 21st, 2010 - South Main Divide March 13th, 2010 - Anza Borrego Wildflowers March 7th, 2010 - CSULB Japanese Garden February 2010 - Mammoth GeoRSS AISlib OpenStreetMap Dakota and Asha Celebrate Christmas, 2009 November 21st, 2009 - Mojave Road November 14th, 2009 - Anza Borrego Exploring The East Mojave: The Afton Canyon Area Broken flex plate Remote Image Serving Astro/night photography in Inyo National Forest Wild Mustang Sightings RSS September 26th, 2009 - Night Photography In Frazier Park Whiskey Brandy August 15th, 2009 - Catalina dive trip Astrophotography Sensornet January 24th, 2009 - Mojave Exploration July 2008 Mammoth Vacation AIS President Barack Obama! Rachel Maddow Big Geek Barack Obama April 12th, 2008 - Wildflowers and Landmarks My Grandfather's Alfa Romeo Spider March 8th, 2008 - Carrizo Plain Bridge To Nowhere High Availability October 20th, 2007 - Big Bear Camping October 22nd, 2007 - Fire Scottish Highlands, Aug 7th, 2006 Scottish Highlands, Aug 6th, 2006 August 5th, 2007 - Duck Lake Trail May 26th, 2007 - Kelso Dunes Culloden Battlefield, Aug 5th, 2006 May 20th, 2006 - Irwindale Renaissance Faire Edinburgh, Aug 4th, 2006 The Clifs of Moher, Aug 3rd, 2006 The Burren, Aug 2nd, 2006 Bunratty Castle, Aug 1st, 2006 May 5th, 2007 - Mojave Truck Audio/Data Network 2007 - Master Bath Remodel Centrum: Exit The Ring of Kerry, Jul 31st, 2006 Nikon D200 Victory in 2006! Blarney and Killarney, Jul 30th, 2006 Dublin and Cork, Jul 29th, 2006 Dublin, Jul 27th & 28th, 2006 Married! What Can I Do? April 30th, 2006 - Anza Borrego New desktop: Intel 805 D Macro Photography Jan 7th and 14th, 2006 - Hiking Whiting Ranch Hiking Engaged! Digital Photography with Linux September 5th, 2005 - Living Desert August 19th, 2005 - Mammoth Hiking and Photography July 30th, 2005 - Tucker Wildlife Sanctuary Nikon D70 Death, Fright and Photography Mmmmmm Eggs MythTV Inova T4 May 14th, 2005 - Red Rock April 2nd, 2005 - Death Valley Count Every Vote Act of 2005 Image Archiving Linear Logic ScanGuage Gentoo Linux November 6, 2004 - Mojave Super Tuesday, 2004 John Kerry Kayaking Irish Stew ImageServer Ireland, 2004 Canon A80 Camera Jul 25, 2004 - Death Valley Chronic Hiccups May 4th, 2004 Landscaping - My Front Slope Stump Pullin' Yeeee Haw! Feb 22nd, 2004 Feb 16th, 2004 PostgreSQL Logfile Analysis Spam Mountains? Desert? Jan 30th, 2004 Jan 28th, 2004 Encryption Ceiling Cargo Basket Front Bumper Version 2 Asha Exide Orbitals Land Rover Valve Jobs Spirits The Matrix: Revolutions Halloween 2003 Greg Davis CDL Linkage Ouzo Democracy Mom's Turkey Gravy Grandma's Guacamole Top Nodes Julian Pie Company DeCSS The KB1DIG 2-meter Halo Antenna Incomming searches Gardening is hard! Aug 13th, 2003 SQL and Perl Cancun 2003 Jul 9th, 2003 Aprs intelegence Jun 17th, 2003 Some People's Comments Dakota is a silly dog The Matrix: Reloaded Chris' Stage Bottle Harness April 23rd, 2003 Cracked Radiator! Black Wednesday DVD Burning Under Linux My Satellite Phone Wind! My Near-Death Experience Laser Cannon Revival Front Bumper, Version 2 SpamAssassin The Critters Dakota Milton KPC 3 Plus and HTX-252 My House Moving, moving moving... Mobile 1 Portola Hills New new house Suse Linux Database images In Truck Dr. Pepper My Favorite Toilet Kelso Dunes Desert Trips Ifulmuh Late Thoughts: Dr. Pepper Cooler 265/75-R16 Tires on a DII Linux George W. Bush Rants Driving Reservations Horses Sep 14 2002 Obsession August 17th Yukon Dives Less notifications My Custom Front Bumper Bracketless, Renamable Links Discreet Winch Welding Jul 28 2002 Day Trip My Firewall Jedi Group, my T1 and money A Bumperless Discovery! My Custom Rear Bumper Vanessa's 24th Birthday Jun 30th Dive to Long Beach Canyon PHP/PostgreSQL String Quoting Tonsillectomy, Uvulaectomy and Turbinite Reduction Searching functionality 240 Watt CO2 Laser Cannon My Workspace Dr. Pepper The Tulsa Rib Company The quality of hard disks these days Email notification of articles Email notification of comments erikburrows.com source code User Bios User Preferences Login feature Renisance Faire Jun 9, 2002 Computers hate me, and it is mutual. Star Wars Sucks! Horses, Jun 1, 2002 Land Rover Mileage Insomnia, Robin goes evil. 100 Watt Diode Laser Test Firing 1 Amateur Radio The Matrix 2001: A Space Odyssey TDI Deco Class Horses, Apr 30, 2002 APRS Movies Blackbird My Truck Batteries My Truck Vasquez Rocks The Zope Bible PSK31 Mojave Apr-12-2002 100 Watt Diode Laser The New www.erikburrows.com Hunter the Kitty Horses Geeks Yukon May-13-2001 Computers Matts Desert Pics Mojave Feb-10-2001 Mojave Apr-01-2001 Programming Languages Ironage Jul-4-2001 Mojave Jan-27-2001 Ironage Feb-03-2001 Mojave Jun-09-2001 SCUBA Jedi Group
|
|
|
|
Programming Languages -   2002/04/06 | Viewed 79 times this month, last update: 2004/12/01
|
|
I program in quite a few languages. Here is the master list, in psudo-cronological order:
- BASIC
- Assembly
- Perl
- HTML
- Shell scripting
- SQL
- PL/SQL
- Javascript
- PHP
- Java
- C
- C++
Programming is an Art. Yes, it is, don't argue. Some day, computers will evolve to the
point where programmers, writing this archane code are no longer neccisary to have
our machines do our bidding. When that day happens, some art will die. I hope I don't
live to see it. Some programming is ugly. See: Spagetti code. But some is beautifull,
and some can be compared to precious stones. The code below is not really pretty,
it's not ugly, certainly, but it is wonderfull. It is so concise and so perfect I would
call this code one of the very few "diamonds" of code I have ever written.
;The second working assembly language program written by Erik G. Burrows
;A prime number generator that is capable of finding all the prime numbers
;up to 4 billion, and uses only registers to do so, except when printing
;them, which it does in decimal.
.MODEL SMALL ;One Data and One Code Segment
.386 ;Enable 32 bit register usage
.STACK ;A 1k stack
.CODE ;Code segment
.STARTUP ;Entry point
MOV EAX, 1 ;The first number
JMP FoundPrime ;One is prime, print it
NewNum: ;Next Number
INC EAX ;Advance number
MOV EBX, 1
BeginTest: ;Start test loop
INC EBX ;Advance divisor
CMP EAX, EBX ;Check if number = divisor
JE FoundPrime ;If so, it's prime, loop finished
MOV ECX, EAX ;Save the number
XOR EDX, EDX ;Zero high DWord of divisor
DIV EBX ;Divide number by divisor
XCHG EDX, ECX ;Prep remainder for testing
MOV EAX, EDX ;Put number back
JCXZ NewNum ;If no renainder it's not prime
JMP BeginTest ;Next in test loop
FoundPrime: ;Print the prime number
MOV EBX, EAX ;Store current number
MOV ESI, 10 ;Load divisor with 10
XOR ECX, ECX ;Zero digit count
NON_ZERO: ;Calculate digits
XOR EDX, EDX ;Zero high DWord of divisor
DIV ESI ;Divide number by divisor
PUSH EDX ;Put the digit on the stack
INC ECX ;Add one more digit to count
OR EAX, EAX ;Check for end of loop
JNE NON_ZERO ;Next digit to print
MOV EAX, EBX ;Restore the current number
WRITE_DIGIT_LOOP: ;Print digits
POP EDX ;Get digit in reverse order
ADD DL,"0" ;Add ascii 0 to the value
MOV SI, AX ;Store ascii value
MOV AH,2 ;Function 2h
INT 21h ;Print it
MOV AX, SI ;Restore the ascii value
LOOP WRITE_DIGIT_LOOP ;Next digit to print
MOV DL, " " ;A space
MOV ECX, EAX ;Store the current number
MOV AH,2 ;Function 2h
INT 21h ;Print it
MOV EAX, ECX ;Restore the test number
JMP NewNum ;Go next number
.EXIT ;Exit (never gets executed)
END ;End address
|
Comments:
Cataboligne (2004-01-04): So few who understand this almost Zen truth.
I used to work with a few who didnt "get" this. To them code was just a way to make money, run a business, or satisfy a customer.
I simply couldnt explain the brilliance that went into a beautiful piece of code. I almost felt sad for the vision they lack.
My best code, has no flow chart, no map, no design stage, no project management, and no notes besides the thoughts in my mind in the dark.
Sure one day machines will be self programming...and I know they will never write code the likes of mine.
You dont mention which assembly besides x86.
I can claim familiarity with these: Z80, 6502, 808x, 68000, VAX Asm.
Of those Z80 and 6502 are my strongest.
Any good thoughts can be sent to cataboligne@kmfms.com, dont expect a quick reply. :-)
Erik (2004-01-05): Actually, x86 assembly is all I ever learned. I'd love to play with some alpha or powerpc assembly. It'd feel so freeing to be able to use those extra registers!
depala5@yahoo.com (2004-03-24): hi, this is something really excellent..I'm very new to this assembly language... but i sure do appreciate this work...if you have time enough.. can you send me a detail explanation of this program..... I'd love to understand it better ......
Erik (2004-03-24): Well thank you, but I don't think I can explain or comment the program any more than it is. Walk through the program, read the comments, you'll see, it's pretty straight-forward.
Please.... (2004-03-25): can you mail me an assembly program that shows first 100 prime numbers...
Erik (2004-03-25): It's right there. On this page, it outputs all the prime numbers up to four billion! Run it, and grab the first 100 lines.
Josephat (2004-07-12): This code is great...commendable !
Erik (2004-07-12): Thank you!
giqonyo@yahoo.com (2004-07-19): I've run this program and does ok.However I'd like to understand the algorithm it follows.Thank u
Erik (2004-07-19): There are two major parts of the program. The loop which tests numbers for primeness, and the loop which prints out numbers in decimal for humans to read.
The lines between the BeginTest and FoundPrime labels are the logic to test a number to see if it's prime, and then loop to the next number to test. The test is simply a loop from 2 to the number being tested, where each loop tests to see if the number being tested is evenly divisible by the divisor. It's prime if none of the numbers from 2 to the number being tested evenly divide it. If a prime number is found, a jump to the FoundPrime label is made. This is another loop, but this time the number is divided by 10 over and over until less than 10 remains. Each time the number is divided by 10, we have another digit to print.
lam (2004-11-10): how would you alter the program to fit n(a max number) instead of 4 bilion? thanks
Erik (2004-11-11): The program goes to 4 billion, because it uses 32 bit registers for counters. In order to increase the scanning range, you'd need to use larger variables. In assembly, this means using a larger width CPU (like the 64 bit Opteron) or faking larger registers by using two or more registers, or main system RAM.
lam (2004-11-11): what I meant to say was how would you change the code to find prime numbers up to n (a number entered by the user). Per se the user doesen't want all prime numbers up to 4 billion but just primes up to 1000 or 2000.
Erik (2004-11-11): Ah, I see. A very good question to which I'm sorry, but I have no answer. You could add a hard-coded conditional break to the code. A better way would be to get a maximum range from the command line, and to do that you would need to convert the number specified (as a string) into a binary number. Good luck!
Linel Ortiz (2004-11-29): Hi. I need a similar assembly program. My program needs to search the space from 002 to 999 and prints the numbers that are prime. Please send it to me, it is very important for me. Thank you so much.
Erik (2004-11-30): Linel, feel free to modify the above program for your use, but I won't do your homework for you.
LilLinda327 (2004-11-30): I dont even know where to start from
Erik (2004-12-01): Where to start what, Linda? Programming? I suggest a class in BASIC. That's where most of us started. Or, "Learning Perl" is one of the best language introduction books I have ever read, or ever heard of. Or, if it's assembly language you want to start with (the above program is written in x86 assembly for the MASM assembler), try your local book store. I picked up the fattest book I could, and read it cover to cover.
K (2004-12-01): I guess everybody is looking for this homework ahahah. :)
Montu (2005-04-15): You good its looks very nice and simple insense of coding and how you have used the code its very impressive,, i have not yet check by computer but i know that it will works out.
Erik (2005-04-17): Thank you Montu, I hope it can be of use to you.
surinder singh kundu (2005-11-23): it was realy nice ,it helps me alot
ian nillas (2006-02-22): Please explain to me how RAM reservations and constants were important? Why it is very important in Assembly language programming?
Erik (2006-03-01): Ian, I'm not sure what you mean by RAM reservations, but constants are used in assembly programming, similarly to how they are used in any language.
dave (2006-03-11): I'm far from a assembly type guy, but couldn't you get some cheap improvements by assuming 1 and 2 are prime and neither testing even numbers nor testing with even numbers. Also perhaps only test up to n/2 rather then up to n? nice code, been a while since I've looked at any assembly, much less well organized code. almost makes me want to try some of it out again.
Erik (2006-03-11): Dave, yes, all of those would improve performance, but would make the main loop so much less pretty. :-) Besides, on a modern processor it should get to 2^32 in just a few seconds anyway.
marcos (2006-08-29): its very beatiful code, tks very much. i try in the masm32 but i cant compile. but i take the book art of assembly and i´m studying the code to understande your art in deep. tks
Tyler (2007-01-31): Very clear and concise code, I'm taking a MASM class at OSU right now and this is perfect, it follows our next program guidelines almost exactly. I'm not going to steal it, but definitely use it as a reference. Thanks for the great work!
Erik (2007-02-01): Wow, I'm amazed any university actually still teaches assembly! Glad I could help!
ashish (2007-03-18): thanks,bcoz of u i m able to complete myassignment
Juri (2007-03-29): This site provides very easy code in Assembly Language to generate Prime numbers then any other sites till I have searched.
cornelius (2007-07-28): this code compiles and links fine but falls over when I try to run it.
illegal instruction
132
Erik (2007-07-31): cornelius, it's been years and years since I compiled this code, but it ran OK under DOS. I don't know if you're trying to run it under Windows, or what affect that would have. If you're not already, try running it from the 'cmd' program, so it has a text terminal.
amenda (2007-11-24): hi Erik! i am working on a project in assembly language that calculates the number of primes in the first 2^32-1 numbers! can u help me in this plz? the anser to this is 203, 280, 221 btw! thanks !
Erik (2007-11-25): Amenda, you can start with the above program, and replace the print routine with a counter. Good luck!
;Pe (2008-05-01): I have a similar problem with generating prime numbers but for the x86 assember and I was wondering if you could help me out
Erik (2008-05-01): Pe, what problem are you having?
permalink
|
|