Luke Gorrie (lukego) wrote,
Luke Gorrie
lukego

Code snippet of the day

A Forth assembler word that happened to cross my path today:
code expand-rect  ( src dst w h --- )
   dx  pop              \ Height of source image in pixels
   4 [sp] edi xchg
   8 [sp] esi xchg
   begin
      0 [sp]  cx mov   \ Width of source image in pixels
      begin
         op: ax lods                \ Get a pixel
         op: ax d# 2400 [edi] mov   \ Write to next line
         op: ax stos                \ Write to this line + increment
         op: ax d# 2400 [edi] mov   \ Write to next line
         op: ax stos                \ Write to this line + increment
      loopa
      d# 2400 # edi add             \ Skip the next output line - already written
      edx dec
   0= until
   eax pop   \ Discard source width
   edi pop   \ Restore EDI
   esi pop   \ Restore ESI
c;

Posted just 'cause it's nice to have a little asm in life.
Tags: forth
Subscribe

  • Update: ZSLUG #1 on Tuesday

    Come and enjoy the Zurich Lisp & Stuff User Group on monday! Hans Hübner will tell you about building computers from scratch using FPGAs and I'll…

  • ZSLUG #1: Zurich's new Lisp & Stuff User Group

    Title: Zurich Lisp & Stuff User Group (ZSLUG) rebirth! Date: Monday February 7th, 2011 Time: 7pm onwards Venue: Office of Teclo…

  • Teclo Networks, and, Happy new year

    What a year. I'm finishing 2010 the same way I started it: living in my favourite place in the world, Zurich. (Here's a hint why.) True to form I…

  • Post a new comment

    Error

    default userpic
    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.
  • 2 comments