This is Kevin P. Rice's Typepad Profile.
Join Typepad and start following Kevin P. Rice's activity
Join Now!
Already a member? Sign In
Kevin P. Rice
San Luis Obispo, California, USA
Recent Activity
Only 162 bytes assembled! ; ---------------------------------------------------------------------------- ; FizzBuzz.asm ; Win32 Console program ; ; A fun programming exercise: ; Counts from 1 to 100. Prints "Fizz" on every 3rd iteration, "Buzz" on ; every 5th iteration, "FizzBuzz" if both, else prints count. ; ; Copyright Kevin P. Rice (http://tek4.com/) ; 2007 December 15 ; ; Build instructions (ML.EXE Microsoft Macro Assember Version 7.00.9466): ; ml /coff fizzbuzz.asm /link /incremental:no /subsystem:console kernel32.lib ; ---------------------------------------------------------------------------- TITLE FizzBuzz .386 .MODEL flat, stdcall ; required to call Win32 .STACK 100h ; more than adequate ; ---------------------------------------------------------------------------- ; CONSTANTS ; ---------------------------------------------------------------------------- ; ----- Fizz/Buzz pattern bit flags (30-bit pattern) ; The Fizz/Buzz pattern (mod 3 and mod 5) repeats every 15 iterations. ; Therefore, the entire Fizz/Buzz pattern is coded in 30 bits--each two bits ; representing Fizz (bit 0) or Buzz (bit 1). The flags are rotated right ; twice for each iteration. Two Buzz flags in a row signals the end of the ; 30-bit pattern--and the flags are rotated an extra two bits to realign ; them within the 32-bit storage for the next cycle. FIZZBUZZ_PATTERN EQU 011110000010010010000011000010000b ITERATIONS EQU 100 ; number of iterations ; A pointer to the LSD (least significant digit) of the ASCII counter ASCII_COUNTER_LSD EQU OFFSET msg_count + SIZEOF msg_count - 2 ; ---------------------------------------------------------------------------- ; Microsoft Win32 external function prototypes (kernel32.lib) ; ---------------------------------------------------------------------------- ExitProcess PROTO, ; exit process function dwExitCode:DWORD ; return code ; ----- ; Used to retrieve a Win32 handle to the Console for printing STD_OUTPUT_HANDLE EQU -11 ; Win32 API constant for stdout handle GetStdHandle PROTO, ; get standard handle nStdHandle:DWORD ; type of console handle ; ----- ; Used to print to the Console WriteConsole EQU ; alias WriteConsole PROTO, ; write a buffer to the console handle:DWORD, ; output handle lpBuffer:PTR BYTE, ; pointer to buffer nNumberOfBytesToWrite:DWORD, ; size of buffer lpNumberOfBytesWritten:PTR DWORD, ; num bytes written lpReserved:DWORD ; (not used) ; ---------------------------------------------------------------------------- ; Global data ; ---------------------------------------------------------------------------- .data bytesWritten dd ? ; number of bytes written (used by WriteConsole) consoleOutHandle dd ? ; stores handle to standard output device msg_fizz db "Fizz" ; Fizz message msg_buzz db "Buzz" ; Buzz message msg_count db "000" ; 3-digit ASCII Counter (for printing count) msg_crlf db 0dh, 0ah ; carriage return/line feed message ; ---------------------------------------------------------------------------- ; Code ; ---------------------------------------------------------------------------- .code ; ---------------------------------------------------------------------------- main PROC ; ; Main procedure. ; ---------------------------------------------------------------------------- push STD_OUTPUT_HANDLE ; Win32 constant to request stdout handle call GetStdHandle ; get Win32 handle for console stdout mov [consoleOutHandle],eax ; store stdout handle for printing cld ; direction flag must be clear for Win32 WriteConsole function mov ebx,FIZZBUZZ_PATTERN ; load FizzBuzz pattern flags mov ecx,ITERATIONS ; loop counter - load number of iterations ; ----- pointer to first significant digit of ASCII counter (for printing) ; This register points to the ASCII counter used for printing the iteration ; count. The register is initialized to the LSD of the counter (one's digit), ; then is decremented as necessary (to the ten's digit, hundred's, etc.) so ; that leading zeros are not printed. mov edx,ASCII_COUNTER_LSD ; point to ASCII counter LSD loop_start: ; ----- increment ASCII counter and maintain pointer to first non-zero digit mov esi,ASCII_COUNTER_LSD ; get pointer to ASCII counter LSD inc_digit: inc byte ptr [esi] ; increment ASCII digit cmp byte ptr [esi],'9' ; did increment overflow past '9'? jle inc_done ; jump if no overflow (done) mov byte ptr [esi],'0' ; reset digit to zero dec esi ; point to next most significant digit cmp edx,esi ; test if printing pointer includes this digit jle inc_digit ; if yes, loop to increment next digit (carry) dec edx ; adjust printing pointer to include new digit jmp inc_digit ; loop to increment next digit (carry) inc_done: ; ----- any Fizz or Buzz on this iteration? mov al,011b ; bit mask to test this iteration only and al,bl ; test pattern flags for Fizz or Buzz jnz test_fizz ; jump if Fizz or Buzz ; ----- no Fizz or Buzz--print count instead mov eax,ASCII_COUNTER_LSD + 1 ; get pointer to one byte past ASCII counter sub eax,edx ; subtract pointer to start to get length mov edi,edx ; point to ASCII counter call writeString ; print ASCII counter jmp rotate_flags ; skip Fizz/Buzz tests, but rotate flags ; ----- test for Fizz (rotate pattern flags one bit) test_fizz: mov eax,4 ; # of chars to print in Fizz/Buzz messages ror ebx,1 ; rotate pattern flags to get fizz flag jnc test_buzz ; no fizz mov edi,OFFSET msg_fizz ; point to fizz message call writeString ; print message ; ----- test for Buzz (rotate pattern flags one bit) test_buzz: ror ebx,1 ; rotate pattern flags to get buzz flag jnc print_crlf ; no buzz mov edi,OFFSET msg_buzz ; point to buzz message call writeString ; print message ; ----- test for 2nd Buzz in a row (marks end of 30-bit Fizz/Buzz pattern) mov al,010b ; bit mask to test for next buzz flag and al,bl ; test next iteration's buzz flag jz print_crlf ; if no buzz, skip flag realignment ; ----- rotate Fizz/Buzz flags two bits for next iteration rotate_flags: ror ebx,2 ; rotate pattern flags print_crlf: mov eax,2 ; number of chars to print mov edi,OFFSET msg_crlf ; point to CR/LF message call writeString ; print CR/LF loop loop_start ; loop on ECX until done push 0 ; return code = 0 call ExitProcess ; Win32 exit process function main ENDP ; ---------------------------------------------------------------------------- writeString PROC ; ; Writes a null-terminated string to Console standard output device. ; ; IN: EAX - number of characters to write ; EDI - points to null-terminated string to write ; DF - direction flag must be clear ; ---------------------------------------------------------------------------- pushad ; push all push 0 ; unused parameter push offset bytesWritten ; buffer to receive number of bytes written push eax ; bytes to write (string length) push edi ; pointer to string push consoleOutHandle ; console stdout handle call WriteConsole ; write to console popad ; pop all ret writeString ENDP END main
Toggle Commented Aug 20, 2010 on Why Can't Programmers.. Program? at Coding Horror
Ah! And I've learned something, yet again! The meaning behind the name: Placer County, California -- Gold Country. Thanks!
Sharon Leavitt provides no basis or references to her "facts". It is provably false that "thousands of acre feet of sand are dispersed into the air" by offroading. The USGS estimates (http://pubs.usgs.gov/of/2006/1219/ -- p. 26) "that about 150,000 cu. m of sand are blown inland each year along the 55 km stretch of coastline from Pismo Beach to Point Arguello". Converted to Leavitt's odd use of acre-feet, this would be 122 acre-feet of sand. Also know that vehicle recreation only utilizes 10% or less of that same area (http://www.duneguide.com/images/OceanoDunesClosedAreas.jpg ). Thus, Leavitt asserts that "thousands of acre-feet of sand are dispersed" by vehicle use in 10% of the dune complex, when only 122 acre-feet of sand feed the entire 100% of the dune complex! Spread evenly, the sand supply in the vehicle recreation area would only be 12.2 acre-feet, yet Leavitt would have us believe that vehicles remove THOUSANDS of acre-feet annually? There would quickly be no dunes left, yet vehicles have recreated there for over 100 years (http://www.bob2000.com/pismo.htm ). Additionally, OHV traffic at Oceano Dunes has not increased--it has decreased. I'd like to see where the USGS spoke about a 400% increase--the USGS studies the earth, they do not measure park use. If they have, please provide references to your facts.
What a pleasurable opportunity to meet and greet such a kindly expert! As a resident of nearby San Luis Obispo ("SLO" to the locals), I jumped at the opportunity to learn more about sand at your enthralling lecture and presentation at the Long Beach Aquarium. It was my honor to "host" you and your lovely wife here in our local dunes. I learned even more about the wondrous sand formations we call 'dunes' and especially loved the micro-world "canyon" (pictured above) that eroded in front of our eyes to the vibrations of our voice. Your close-up photo could just as easily be an aerial photo of any mountain side. Thanks for teaching me about cross-bedding, sorting and other fascinations. I wish you book was on tape so I could listen on my way to work. The radio interview was a nice warm-up, though. Any sand enthusiasts are welcome to contact me. I'd love to be acquainted with anyone as congenial as Michael. Kevin P. Rice kriceslo@gmail.com http://SLORider.com/ http://YourDunes.org/