Skip to content
Elchanan Heller edited this page Nov 1, 2021 · 2 revisions

Using Habit ASM

Launching Habit ASM

⚠️ Note: Be sure to assemble, link, and compile the program before launch. See Installing Dependencies and Program Compilation for details.

To launch Habit ASM, navigate into the directory where the program was compiled, type ./habit, and hit enter. In the example below, Habit ASM was compiled in the habit directory located within a directory called final:

elchanan.heller@dev:~/final$ cd habit
elchanan.heller@dev:~/final/habit$ ./habit

The Main Menu

Using the program is intuitive and straightforward. At the first launch, the user is presented with the Main Menu, shown below, which provides access to the program's main features.

Habit ASM > Main Menu
===================================
Enter 1 ... to set up a new habit
Enter 2 ... to record a daily entry
Enter 3 ... to print a report
Enter 0 ... to exit
===================================
Option: 

Choose a number that corresponds to the desired choice and hit enter to submit your selection. For example, hit 3 and enter to display a summary report.

⚠️ Note: Entering an invalid menu value results in an error message and Habit ASM exits.

Error: The value entered was invalid.
The program will now exit.

Creating a Goal

To create a new goal, hit 2 and enter from the main menu. You will then be prompted to provide a name for your habit and the duration of setting up your daily goal in minutes.

⚠️ Note: The program is designed to store a goal name up to 20 characters in length.

Once provided, a confirmation message is displayed, and the user is returned to the main menu.

In the example below, the user set up a goal to walk 30 minutes each day.

Main Menu > New Habit Setup
-----------------------------------

Enter a name for your new habit: walking
For how many minutes: 30

New habit:     walking
Daily minutes: 30

⚠️ Note: Setting up a new goal will purge all previously stored data.


Recording a Daily Entry

Once a new goal has been set up, hit 3 and enter to record a daily entry. Habit ASM displays a two-column table with a summary of any previous entries. The data in the table can be used to determine the appropriate day to record the next entry.

⚠️ Note: Entering an invalid date value results in an error message and the user is returned to the main menu.

Error: The value entered was invalid.
Returning to main menu.

In the example below, the user recorded 30 minutes of walking for day 1. The program displays a confirmation message confirming a successful entry.

Main Menu > Record Entry
-----------------------------------

Goal:    walking
Minutes: 30

+------+------+
| Day: | Min: |
+------+------+
|    1 |      |
+------+------+
|    2 |      |
+------+------+
|    3 |      |
+------+------+
|    4 |      |
+------+------+
|    5 |      |
+------+------+
|    6 |      |
+------+------+
|    7 |      |
+------+------+

Enter a day to record a habit: 1
Enter the amount of minutes: 30

Success: 30 minutes on day 1 has been recorded.

Printing a Summary

To show a summary report, hit 3 and enter from the main menu. The report displays all data recorded to date. This table is similar to the table presented when recording an entry with the addition of a Met column. This column displays an asterisk for any day where the goal duration has been met.

The progress bar provides a visual indicator of a user's progress towards goal achievement. The bar is dynamically updated as the user records daily entries.

For simplicity, the progress bar considers any recorded data for a particular day as progress towards the goal regardless if the targeted goal value has been met for the day.

Below the progress bar, the following user statistics are displayed:

  • The total amount of days for which an entry has been recorded.
  • The total amount of days where a user's goal has been met.
  • The total time the user has recorded.

Here is a sample report generated after one day of data entry:

Main Menu > Show Report
-----------------------------------

Goal:    walking
Minutes: 30

+------+------+-------+
| Day: | Min: |  Met: |
+------+------+-------+
|    1 |   30 |   *   |
+------+------+-------+
|    2 |      |       |
+------+------+-------+
|    3 |      |       |
+------+------+-------+
|    4 |      |       |
+------+------+-------+
|    5 |      |       |
+------+------+-------+
|    6 |      |       |
+------+------+-------+
|    7 |      |       |
+------+------+-------+

-----------------------------------
Progress:

β–‡β–‡
______________| 100%

-----------------------------------
Total days recorded: 1 / 7
Total goal met:      1 / 7
Total minutes:       30

Here is a sample report generated after seven days:

Main Menu > Show Report
-----------------------------------

Goal:    walking
Minutes: 30

+------+------+-------+
| Day: | Min: |  Met: |
+------+------+-------+
|    1 |   30 |   *   |
+------+------+-------+
|    2 |   20 |       |
+------+------+-------+
|    3 |   35 |   *   |
+------+------+-------+
|    4 |   10 |       |
+------+------+-------+
|    5 |   30 |   *   |
+------+------+-------+
|    6 |   15 |       |
+------+------+-------+
|    7 |   30 |   *   |
+------+------+-------+

-----------------------------------
Progress:

β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡
______________| 100%

-----------------------------------
Total days recorded: 7 / 7
Total goal met:      4 / 7
Total time:          2:50

Closing the Program

To close the program, hit 0 and enter. All user data is written to disk for persistent storage and is available upon program relaunch.

Modifying Goal Duration

HabitASM can be modified for users who desire a goal duration other than the default seven days. In habit.asm, change the value of %DAYS, which appears on line 4, to the desired amount of days. The program will adjust accordingly.

%define DAYS 7

Save and exit from the habit.asm file. Recompile and run the program with the following commands from within the habit directory:

nasm -f elf habit.asm
gcc -m32 -o habit habit.o driver.c asm_io.o

Finally, reset any previously recoded data by entering 1 from the main menu to configure a new goal.

Assembly I/O Routines

Habit ASM utilizes assembly I/O routines developed by Paul Carter.

The author describes these routines in Chapter 1, Section 3 of PC Assembly Language:

Table 1.4 describes the routines provided. All of the routines preserve the value of all registers, except for the read routines. These routines do modify the value of the EAX register. To use these routines, one must include a file with information that the assembler needs to use them. To include a file in NASM, use the %include preprocessor directive. The following line includes the file needed by the author’s I/O routines:

%include "asm_io.inc"

To use one of the print routines, one loads EAX with the correct value and uses a CALL instruction to invoke it. The CALL instruction is equivalent to a function call in a high level language. It jumps execution to another section of code, but returns back to its origin after the routine is over.

Table 1.4: Assembly I/O Routines

  • print int prints out to the screen the value of the integer stored in EAX
  • print char prints out to the screen the character whose ASCII value stored in AL
  • print string prints out to the screen the contents of the string at the address stored in EAX. The string must be a C- type string - (i.e. null terminated).
  • print nl prints out to the screen a new line character.
  • read int reads an integer from the keyboard and stores it into the EAX register.
  • read char reads a single character from the keyboard and stores its ASCII code into the EAX register.

PC Assembly Language by Paul Carter is available on the author's website under CC BY-NC-SA 4.0.