Fibonacci Program in Assembly Language

Here’s how to write a Fibonacci sequence program in Assembly language from scratch for the x86-64 processor. Also includes instructions on how to install the Flat Assembler.


First, let’s install the Flat Assembler. You can download the program from here:

Doesn’t need Windows setup/installation. Simply download the zip file and extract it to your preferred location.

Personally I extracted mine here: C:\Users\sanjib\bin\fasmw17330

Location of the Flat Assembler program on my machine

Environment Variables

We need to set 2 environment variables:

  • Set the INCLUDE variable to the INCLUDE folder in your fasm folder (where you extracted the Flat Assembler program): this will allow you to include additional assembly files in your assembly program. Mine was: C:\Users\sanjib\bin\fasmw17330\INCLUDE
  • Add to the Path variable your fasm folder (where you extracted the Flat Assembler program): this will allow you to call the fasm.exe program from anywhere in your machine. I added C:\Users\sanjib\bin\fasmw17330
The INCLUDE environment variable on my machine
The Path environment variable on my machine

Download the file

Download the file from here:

We need to download this file at put it in the INCLUDES folder of your fasm directory.

We need this file as we are going to include it in our Fibonacci program. This program allows user input and output to the console.

How my INCLUDE folder looks like

Fibonacci Program in Assembly Language

This is how the Fibonacci program looks like in Assembly language. Please read the inline comments which explains all the lines of code. Also watch the video that shows from the beginning to end on how to install the Flat Assembler and write the program from scratch.

I mention x and y below as if they were variables. But these are just imaginary variables to explain Fibonacci algorithm.

We are using 4 registers as follows:

  • eax: to store the x value
  • ebx: to store the y value
  • ecx: as the counter
  • edx: as the tmp value during the swap
format PE console       ; tells the assembler that this is a console program
entry start             ; marks the start of the program, see the start: label below

include ''    ; includes the file necessary for Windows operating system
include ''  ; includes the file to call read_hex and _print_eax instructions

start:                  ; the entry-point of the program
    call    read_hex    ; reads user input and stores it in the eax register
    mov     ecx, eax    ; move content eax to ecx, will use ecx as the counter n

    mov     eax, 0      ; now set eax to 0 (initial value of let's say x)
    mov     ebx, 1      ; set ebx to 1 (initial value of let's say y)

    ; the 3 lines below are the fibonacci algorithm: sets x to y, and y to x+y
    mov     edx, eax    ; store value of eax in edx (used as a tmp area)
    mov     eax, ebx    ; move content of ebx to eax (sets x)
    add     ebx, edx    ; sum ebx with value of edx (what used to be eax, sets y to x+y)

    jc      fib_carry   ; register 32-bits, not big enough to calculate over 30 hex

    dec     ecx         ; decrease counter
    jz      exit        ; jump to exit: if ecx reaches 0

    jmp     fib         ; jump back to fib: label, creates the loop

    mov     eax, -1     ; carry over occurred, mark it with value ffffffff

    call    print_eax   ; print answer

    push    0           ; exit console program
    call    [ExitProcess]

Map CAPS Lock to Control Key in Windows

Windows version: 10

If you use the control keys a lot for keyboard shortcuts, it makes sense to have the control key where the caps lock key is. Why? Because while the fingers are resting in the home position (ASDF row), you have the pinky finger under the “A” key and right beside it will be the “Control” key. It’s easy on the pinky and ergonomic.

The early keyboards used to have the Control Key beside A:

Here are three ways I recommend (I prefer the registry edit):

Both Power Toys and Ctrl2Cap are fine in my opinion as both are officially listed on the Microsoft sites.

However I like the registry edit solution better as there is no software to install and it’s just a single line of edit. I used to be scared editing the Registry Editor but the procedure below is tested and safe. Just carefully type in the values (you won’t be able to copy/paste them).

1. Open the Registry Editor, you can hit the “Windows” key and start typing regedit and it will show you suggestions for opening the Registry Editor:

2. Navigate to the entry:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout

3. Right-click “Keyboard Layout” and add a new “Binary Value” with name: Scancode Map

4. Type in the following values:

00 00 00 00 00 00 00 00 02 00 00 00 1d 00 3a 00 00 00 00 00

You can’t copy / paste them, so type them in carefully 😊

5. Click OK, close the Registry Editor and restart your computer. Your CAPS Lock key should now be mapped to the Controls Key.

Download a File Using Go

Downloading a file from the Internet using Go is remarkably easy. Especially coupled with concurrency it makes downloading multiple files fast. The following code below shows how to download a single file using Go.

Goal: Download a test image file, the Google logo

  1. First get the file using http.Get
  2. Extract the filename from the URL by splitting it with “/”, then get the last part
  3. Create an empty file with the filename
  4. Dump the data into the file from the “res” object in step 1
package main

import (

func main() {
	// 1. Get the file
	url := ""
	res, err := http.Get(url)
	if err != nil {

	// 2. Extract filename
	parts := strings.Split(url, "/")
	filename := parts[len(parts)-1]

	// 3. Create an empty file
	file, err := os.Create(filename)
	if err != nil {

	// 4. Dump the data
	defer res.Body.Close()
	n, err := io.Copy(file, res.Body)
	if err != nil {

	fmt.Printf("wrote: %q, size: %.2f kb\n", filename, float64(n)/1024)

Send Email With Go and MailJet

The following steps show how to send mail with Go using the standard smtp package. To test I used MailJet as the mail server but you can also use Mandrill or SendGrid.

First let’s setup MailJet as the mail server. Then write the Go code and send a test email.

MailJet Setup

After creating your free MailJet account, you should make sure you complete the 2 steps below (under Account Settings):

  • Add a Sender Domain or Address
  • Setup SPF/DKIM Authentication

Personally, I found validating an entire domain very convenient. That way I can use the domain for all my projects mail sending requirements. For example:

But you don’t have to use a custom domain if you don’t want to. You can add a single sender email address from which the mail will be sent from.

Next, you need to setup an API key and Secret – these will be the username and password in Go code. You can set the API key and Secret under Account Settings:

Go Code

Please make sure you specify the following constants and variables with your own:

  • username, password: These are your API key and secret
  • host, port: the port should be 587, you can find your host under your account settings:
  • from: the email address from which mail will be sent from. I presume you have set this in the steps above under MailJet account settings: Add a Sender Domain or Address, Setup SPF/DKIM Authentication.
  • to: you can specify any address that you own for testing. The test email will be sent to this address. I specified my own personal email address which you should replace with your own.

Type the following code in your favorite editor, then run the code in a terminal: go run main.go

package main

import (

func main() {
	const (
		username = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" // your 32 digit API key
		password = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" // your 32 digit secret
		host     = ""                  // your MailJet host
		port     = "587"                              // recommended port for TLS
		from     = "FROM-EMAIL@YOUR-VALID-DOMAIN.COM" // your validated domain
		addr     = host + ":" + port

	to := []string{
	subject := "Test mail using Go with MailJet"
	message := fmt.Sprintf(`Subject:%s

This is a test message sent with Go and MailJet.


Sent on %v`, subject, time.Now())

	auth := smtp.PlainAuth("", username, password, host)
	err := smtp.SendMail(addr, auth, from, to, []byte(message))
	if err != nil {
		log.Println("send mail:", err)
	fmt.Println("mail sent successfully")

If you configured everything correctly and ran the code, you should receive an email like the one shown in the screenshot below. I received my test email at my personal Gmail address. My from address was: “”

Here is a video of the code in action where I configure the code, run it and receive a test mail.

Windows Firewall Rule for Go Web Development

If you do Go web development on Windows, then you are likely to come across the Windows Firewall – Security Alert whenever you build and run the Go app. For example, here I am trying to build and run a sample Go web server program “main1.exe” that wants to run on port 4000:

Windows Defender Firewall – Security Alert

This can be annoying when you create a lot of throw-away small apps for learning; you end up with hundreds of these “allow” rules in the Firewalls ruleset. Here’s a small glimpse of all the rules that got created running an experimental web program “multiple_handlers.exe”:

I am not sure if hundreds or even thousands of these junk rules slow up the system. To me they are junk for sure as I am not likely to run these again after the learning and testing is done. So my solution is to create a single inbound rule for port 4000 and always try to stick to the same port when developing web programs in Go. Here is how to do it in Windows:

1. Press the Windows key (start button) on your keyboard and start typing “firewall”, click the Windows Defender Firewall link as shown below:

2. Next click on “Advanced settings”

3. Then right-click on “Inbound Rules”, which will bring up a pop-up menu, then click “New Rule…”

4. Select “Port” then click Next

5. Type the port you want to allow. I choose 4000 for local development, so that’s what I specify and click Next.

6. Select “Allow the connection” and click Next

7. I work from home, so I choose “Private” only and click Next

8. Give the rule a friendly name, I gave it “4000 for local development” and click Finish

9. The rule should now be created and can be seen as below.

Now I can happily run my Go web programs on port 4000 and never receive a Windows firewall security alert ever again 😀

How to Run Simply Scheme on Windows

Goal: To be able to run Scheme on Windows, particularly the flavor “Simply Scheme”.

There is a great computer science book called Simply Scheme by Brian Harvey and Matthew Wright. Professor Brian Harvey also taught a great class CS61A at the University of California, Berkeley. Our goal is to be able to run Simply Scheme so that we can follow along the book and its exercises.

Illustrated by Polly Jordan, from page 4 of the book Simply Scheme

Simply Scheme uses custom Scheme commands to teach some important programming concepts. These commands are not available on regular Scheme but their value cannot be undermined in helping to learn more easily concepts taught in the book like recursion, higher order functions, composition, abstraction and more.

The best and easiest way to run scheme on Windows is via DrRacket from the Racket language site. Racket download provides a nice integrated learning environment DrRacket and it can be extended to run Simply Scheme via a package “Danny Yoo’s Simply Scheme”.

1. Download and install DrRacket from here

2. Start Racket, then click on File -> Package Manager

3. Click the tab “Available from Catalog”, then type “simply” in the filter. You should see “simply-scheme” listed. Select “simply-scheme” and click the Install button.

4. After installation, close the dialog box and restart the DrRacket

5. Choose Language -> New Language from the menu bar. Then select Simply Scheme as shown below.

6. You should be able to run Simply Scheme programs now. Here is an example program that implements “Pig Latin”.

7. Bonus: If you like Emacs Key bindings then enable it in Edit -> Preferences -> Editing. Make sure the option is “unchecked” for Enable keybindings in menus.

Enjoy Simply Scheme!

I remind myself: It can be easy to learn new languages and syntax. Then tedious to keep up to date with endless frameworks. But great programming concepts are timeless, so it’s a good idea to learn them well.

Install and Configure Apache and PHP on Windows

This post explains how to install and configure Apache and PHP on Windows. Sure, there are convenient options like: Bitnami WAMP Stack, WampServer or XAMPP. But over the years I found that installing each stack separately is more reliable and provides greater flexibility. You will probably also want MariaDB for a database which you can download and install from here: The database itself doesn’t have to be configured directly with either Apache or PHP so there are no steps provided here for the database. You only need to enable a line in PHP ini for PHP to provide the database functions.


  • Windows 10, 64-bit
  • PHP 7.4.x
  • Apache 2.4.x


Download PHP from the Windows download page. We will use PHP as an Apache module, so make sure to get the Thread Safe version.

After downloading the zip file, unzip it to a convenient location on your hard drive. I usually keep all my stand-alone programs that I use under ~/bin folder. So the location of my unzipped PHP folder is: C:\Users\sanji\bin\php-7.4.27-Win32-vc15-x64

Copy the file php.ini-development and rename it to php.ini, then edit it:

# The default input vars, upload and post sizes are small 
# so I make sure they are big enough
max_input_vars = 5000
post_max_size = 100M
upload_max_filesize = 100M
max_file_uploads = 50
# Only for local development machine, I set the max execution time at 120 seconds
# instead of the default 30 seconds, because some PHP application updates fail 
# locally without a high enough timeout threshold
max_execution_time = 120

# I usually set the full-path because sometimes just specify "ext" doesn't work
extension_dir = "C:\Users\sanji\bin\php-7.4.27-Win32-vc15-x64\ext"

# I have the following extensions enabled which 
# is also good for WordPress development
extension=exif      ; Must be after mbstring as it depends on it

I also added the location “C:\Users\sanji\bin\php-7.4.27-Win32-vc15-x64” to the Path in my Windows Environment Variables under System Properties.

Nothing more needs to be configured for PHP. Let’s get Apache installed and configured.


Apache binaries are not provided by the official Apache HTTPD project. You can can get either from ApacheHaus or Apache Lounge. Here is the download page screenshot of the binary for Apache 2.4.52 x64 on ApacheHaus:

After downloading the zip file, unzip it at a convenient location on your drive. The full path on my machine is: C:\Users\sanji\bin\Apache24. For convenience, I also added to the environment Path variable “C:\Users\sanji\bin\Apache24\bin” via Windows System Properties.

The file “Apache24\conf\httpd.conf” needs to be edited.

# Change the following to the location where you 
# unzipped the downloaded Apache zip file
Define SRVROOT "/Users/sanji/bin/Apache24"

# I use port 8080 instead of the default port 80
Listen 8080

# I use virtual hosts, so following needs to be enabled 
# and the httpd-vhosts.conf file included
LoadModule vhost_alias_module modules/
Include conf/extra/httpd-vhosts.conf

# The following modules are also enabled
LoadModule rewrite_module modules/

# The following settings enable PHP
LoadModule php7_module "/Users/sanji/bin/php-7.4.27-Win32-vc15-x64/php7apache2_4.dll"
<FilesMatch \.php$>
    SetHandler application/x-httpd-php
PHPIniDir "/Users/sanji/bin/php-7.4.27-Win32-vc15-x64"

# I also had to add the following line to get curl working with PHP 
# (aside from enabling curl in php.ini)
LoadFile "/Users/sanji/bin/php-7.4.27-Win32-vc15-x64/libssh2.dll"

ApacheHaus uses “extra/httpd-ahssl.conf” for SSL configuration. I use the port 4430. Here is my “Apache24\conf\extra\httpd-ahssl.conf” change:

# I changed the default port 443 to 4430
Listen 4430 https

Finally here is my vhosts configuration file (located in Apache24\conf\extra\httpd-vhosts.conf).

# I serve all my sites from the folder "C:\Users\sanji\pdn"
# So the following entry affects all my development sites
<Directory "/Users/sanji/pdn">
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
    DirectoryIndex index.html index.php

# I use port 4430 for SSL
# Here are settings for a site called viaye.san, you can create your own by 
# editing the C:\Windows\System32\drivers\etc\hosts file
# To generate and self-sign SSL certificates, please see 
# I like to keep my docroot under "www" and the 
# access and error logs under the "logs" folder
<VirtualHost *:4430>
    SSLEngine on
    ServerName viaye.san
    DocumentRoot "/Users/sanji/pdn/viaye/www"
    ErrorLog "/Users/sanji/pdn/viaye/logs/error.log"
    CustomLog "/Users/sanji/pdn/viaye/logs/access.log" common
    SSLCertificateFile "/Users/sanji/_pepper/_ssl_local/viaye.san/cert.pem"
    SSLCertificateKeyFile "/Users/sanji/_pepper/_ssl_local/viaye.san/server.key"

That’s it for configuration. The final step is to add httpd as a Windows service. Head over to C:\Users\sanji\bin\Apache24\bin and run:

httpd -k install

You can now start, restart the Apache HTTPD server from the Windows Services panel as seen below:

The following video shows how to install Apache, PHP and MariaDB on Windows using the steps above.

Create a Self-signed Certificate on Windows for Local Development

We need to a create self-signed certificate for local development so that the local development server behaves similar to a live production server. Additionally the certificate must not generate warnings in the browser (Chromium based browsers only) that the certificate is self-signed and can’t be trusted.

Developing locally with plain http is just fine. But sometimes we need to mimic development with production so that TLS encryption via https is available also on our development machines. We also don’t want to see ugly security warnings from browsers. The following article shows how to create self-signed certificates on Windows that doesn’t generate browser warnings on Chrome and other Chromium based browsers.

The article is a bit long but please grab a coffee and follow along. The result is worth the effort as you only need to generate the certificate once in a very long time. I set the expiry date 10 years in the future for the domains I create for local development.

Goal: Create an imaginary domain pdb.oak.san with a self-signed certificate that works on major browsers (except Firefox) without generating a warning. Works great on Chromium based browsers like Chrome, Canary, Microsoft Edge and Opera, IE.

Step 1: Setup hostname

  • Open Notepad in Administrator mode: Click Windows Start icon in task bar and start typing Notepad, right click the Notepad icon and click Run as administrator
  • Inside Notepad, open the file: C:\Windows\System32\drivers\etc\hosts
  • We want to create an imaginary domain: pdb.oak.san, add the following line to the hosts file:    pdb.oak.san
  • Save the file and close

Step 2: Create a client-side self-signed certificate

  • Open PowerShell in Administrator mode: Click Windows Start icon in task bar and start typing PowerShell, right click the PowerShell icon and click Run as administrator
  • Type the following to generate a self-signed certificate for domain pdb.oak.san with friendly name pdb.oak.san that expires after 10 years:
New-SelfSignedCertificate -CertStoreLocation Cert:\LocalMachine\My -DnsName "pdb.oak.san" -FriendlyName "pdb.oak.san" -NotAfter (Get-Date).AddYears(10)
  • You should get the following output

Step 3: Copy the certificate created in Step 2 to Trusted Root Certification Authorities, then export it

  • Open Management Console for Certificates: Click Windows Start icon and start typing certificates, click Manage computer certificates
  • On the left panel, click Personal -> Certificates, you should see the client-side certificate for pdb.oak.san created above in Step 2
  • On the left panel, open the tree for (but don’t left click the folder) Certification Authorities -> Certificates
  • With the right mouse button, drag and drop the certificate to the location opened in the previous step
  • Now export the certificate: right-click the certificate, All Tasks -> Export…
  • Welcome screen appears, click Next
  • Select Yes, export the private key, click Next
  • Keep the default values for .PFX, click Next
  • Type a password for the private key, click Next
  • Browse for a location and give the certificate a name (cert.pfx), click Next
  • Finally click Finish
  • You will get a notice that the export was successful

Step 4: Create the server-side certificate and key

  • Pre-requisite: you need to have OpenSSL installed. Since you are a developer and on Windows, it’s highly likely you already have installed, so you should also have OpenSSL installed. Otherwise we recommend installing Git for Windows with Git Bash support – this will automatically also install OpenSSL.
  • Open Command Prompt and change directory to the location where you exported the certificate with .PFX extension cert.pfx in Step 3 above.
  • Type the following commands in the Command Prompt one by one. When prompted for password, type the password you used in Step 3 above when exporting the .PFX certificate.
$ openssl pkcs12 -in cert.pfx -nocerts -out key.pem -nodes
$ openssl pkcs12 -in cert.pfx -nokeys -out cert.pem
$ openssl rsa -in key.pem -out server.key
  • You should now have the following files in the folder, we will be using the cert.pem and server.key files. You can delete the other files if you want to.
cert.pem    --> KEEP
server.key  --> KEEP

Step 5: Test

  • You can use Apache or Nginx to test the https connection for the pdb.oak.san domain. We will create a simple Go server as it can be created really fast with a few lines of code. Create a file called main.go and type the code below. Make sure cert.pem and server.key is in the same folder as the main.go file.
package main

import (

func handleHome(w http.ResponseWriter, r *http.Request) {
    _, _ = fmt.Fprintln(w, "Home page to test the TLS cert and secure https connection")

func main() {
    http.HandleFunc("/", handleHome)
    _ = s.ListenAndServeTLS("cert.pem", "server.key")
  • Build and run the Go server: go build main.go, then run the resulting executable program main.exe
  • Now if we visit https://pdb.oak.san/ in a browser, we can see the home page with the following content: “Home page to test the TLS cert and secure https connection”
  • We can also check the certificate by clicking on the lock icon in the browser address bar:

For Nginx Users

To test on Nginx instead of writing Go code, you can use the configuration below.

  • Make sure to copy your cert.pem and server.key to the locations for ssl_certificate and ssl_certificate_key.
  • Folder paths like C:\Users\sanji\pdn\pdb.oak.san\www should of course match the locations in your own computer.
server {
    listen          443 ssl;

    server_name     pdb.oak.san;
    root            C:\Users\sanji\pdn\pdb.oak.san\www;
    access_log      C:\Users\sanji\pdn\pdb.oak.san\logs\access.log;
    error_log       C:\Users\sanji\pdn\pdb.oak.san\logs\error.log;
    index           index.html;

    ssl_certificate     C:\Users\sanji\pdn\pdb.oak.san\ssl\cert.pem;
    ssl_certificate_key C:\Users\sanji\pdn\pdb.oak.san\ssl\server.key;

The video below shows the steps I took to setup SSL on an imaginary domain on my local machine. The video is 20 minutes; maybe I could have been done the video in 10 minutes or less. But here I am showing the actual problems I am running into and the steps I am taking to solve them.

Setting up domains, servers and certificates in real-life is not without problems. This is not a scripted video. It shows the problems I face and how I resolve them.

This a scenario where you have created personal certificates and digitally signed them on your own and now you want them available and trusted on another machine.

The Definitive 4-Step Short Guide to Implementing WordPress Language Files

WordPress: 5.5.1

The reason to call this post “definitive” is because it contains the exact information (without adding anything extra) for implementing WordPress language files (aka internationalization).

The 4-Steps

1. The plugin entry point “.php” file needs the following Text Domain WordPress directive, considering foo-bar as the plugin name:

* Text Domain: foo-bar

Where is the The Text Domain used? For example, in the 2nd argument of _e() and __() functions.

The Domain Path directive didn’t need to be specified even though the plugin wasn’t part of the official WordPress plugin directory as specified here:

2. Create a “lang” folder (to put all your .mo and .po translation files) under your plugin folder:


Folder name “lang” is preferred to “languages” because it’s shorter.

3. Create the .mo and .po language translation files via PoeEdit and make sure to prefix them with the plugin name:

  • foo-bar-en_US.po
  • foo-bar-fr_FR.po

PoeEdit is a bit awkward to use at first, but it gets the job done. Beginners need to refer to a quick-guide on how to generate the .mo and .po files.

4. Load the language translation files from the plugin entry point “.php” file like this (the folder pointing to the language files is a relative path):

add_action('plugin_loaded', function () { 
    load_plugin_textdomain('foo-bar', false, 'foo-bar/lang'); 

For better code organization a static function under a class is highly recommended, instead of the anonymous function above (the 2nd argument to add_action).

2 Common Mistakes to Avoid

  • Don’t forget to prefix the language files with the plugin name (see step 1 above).
  • Don’t forget to specify relative folder and not absolute folder (see step 4 above).

Getting Started with Phaser 3

A barebones Phaser 3 getting started demo.

5 Easy Steps

See the comments in index.html in the Github repo.

  1. Include the JS file phaser-arcade-physics.min.js
  2. Declare the config var
  3. Create a new Phaser.Game
  4. Preload the 4 game assets (images) in preloadFoo() function
  5. Create the game in createFoo() function
    • add background image
    • create a particles emitter
    • create the ball boss
    • attach the emitter to the boss

For more information see the official Getting Started page here: