Tag: technology

  • AAA DOS: Chapter 8: Going from DOS to Linux or Windows

    In the unlikely event that you have read the first 7 chapters of this book, I am going to assume you are a pretty hard core computer user. What I can say for sure is that you are the type of person who reads books or blog posts about technical details. DOS is an operating system that tends to only be used by nerds who love reading text and efficient operations at the command line.

    Sadly to say, our kind is dying out. At the time of writing this I am 38 years old and there are few people who remember the old way computers were used. DOS is mostly seen as a dead platform and it is not usually used except by programmers and hard core gamers who still run their favorite games in a DOS emulator. Though I cannot fail to mention that FreeDOS is available as a real DOS system.

    https://www.freedos.org/

    But most people know nothing about DOS because the popular operating systems available today are Windows, MacOS and Linux.

    If you have enjoyed programming in Assembly, I do have some helpful tips on how you can apply most of the same information to start Assembly in Linux.

    As far as Windows or MacOS go, I cannot help you much with that because I don’t use proprietary operating systems if I have a choice. These operating systems don’t allow you to simply load registers and call interrupts to print things on the screen.

    Linux, however, works very much like DOS does. If you know how to load the registers correctly and use a system call, you can print strings of text just like in DOS except MUCH faster because you will be running natively instead of in an emulator as in the DOS examples from the rest of this book.

    I cannot cover the details of installing a Linux operating system because there are many choices. However I recommend Debian because it has been my main distro for years. Therefore, the following two programs that I will show you in this chapter have both been tested to work on my 64 bit Intel PC running Debian 12 (bookworm).

    Remember, although DOS was a 16 bit system, modern Linux processors and distros usually support 32 or 64 bit code. Therefore, I will be showing you a small program using the FASM assembler that prints text using a Linux version of the putstring function. It behaves the same as the DOS version behaves in chapter 2.

    main.asm (32 bit)

    format ELF executable
    entry main
    
    main:
    
    mov eax,main_string
    call putstring
    
    mov eax, 1  ; invoke SYS_EXIT (kernel opcode 1)
    mov ebx, 0  ; return 0 status on exit - 'No Errors'
    int 80h
    
    ;A string to test if output works
    main_string db 'This program runs in Linux!',0Ah,0
    
    putstring:
    
    push eax
    push ebx
    push ecx
    push edx
    
    mov ebx,eax ; copy eax to ebx. ebx will be used as index to the string
    
    putstring_strlen_start: ; this loop finds the length of the string as part of the putstring function
    
    cmp [ebx],byte 0 ; compare byte at address ebx with 0
    jz putstring_strlen_end ; if comparison was zero, jump to loop end because we have found the length
    inc ebx
    jmp putstring_strlen_start
    
    putstring_strlen_end:
    sub ebx,eax ;By subtracting the start of the string with the current address, we have the length of the string.
    
    ; Write string using Linux Write system call. Reference for 32 bit x86 syscalls is below.
    ; https://www.chromium.org/chromium-os/developer-library/reference/linux-constants/syscalls/#x86-32-bit
    
    mov edx,ebx      ;number of bytes to write
    mov ecx,eax      ;pointer/address of string to write
    mov ebx,1        ;write to the STDOUT file
    mov eax,4        ;invoke SYS_WRITE (kernel opcode 4 on 32 bit systems)
    int 80h          ;system call to write the message
    
    pop edx
    pop ecx
    pop ebx
    pop eax
    
    ret ; this is the end of the putstring function return to calling location
    
    ; This Assembly source file has been formatted for the FASM assembler.
    ; The following 3 commands assemble, give executable permissions, and run the program
    ;
    ;	fasm main.asm
    ;	chmod +x main
    ;	./main
    

    The program above uses only two system calls. One is the call to exit the program. The other is the write call which is the same as the DOS function 0x40 of interrupt 0x21; However, the usage of the registers is not in the same order. However, these registers: eax,ebx,ecx,edx are the same registers except that they are extended to 32 bits. That is why they have an e in their name.

    But if you take the time to study it, you will see that it does the exact same process of finding the length of the string by the terminating zero and then loading the registers in such a way that the operating system knows what function we care calling, which handle we are writing to, how many bytes to write, and where the data is in memory which will be written.

    Next I will show you the 64-bit equivalent that works the same way but uses different numbers for the system calls.

    main.asm 64 bit

    format ELF64 executable
    entry main
    
    main: ; the main function of our assembly function, just as if I were writing C.
    
    mov rax,main_string ; move the address of main_string into rax register
    call putstring
    
    mov rax, 60 ; invoke SYS_EXIT (kernel opcode 60 on 64 bit systems)
    mov rdi,0   ; return 0 status on exit - 'No Errors'
    syscall
    
    ;A string to test if output works
    main_string db 'This program runs in Linux!',0Ah,0
    
    putstring:
    
    push rax
    push rbx
    push rcx
    push rdx
    
    mov rbx,rax ; copy rax to rbx as well. Now both registers have the address of the main_string
    
    putstring_strlen_start: ; this loop finds the lenge of the string as part of the putstring function
    
    cmp [rbx],byte 0 ; compare byte at address rdx with 0
    jz putstring_strlen_end ; if comparison was zero, jump to loop end because we have found the length
    inc rbx
    jmp putstring_strlen_start
    
    putstring_strlen_end:
    sub rbx,rax ;rbx will now have correct number of bytes
    
    ;write string using Linux Write system call
    ;https://www.chromium.org/chromium-os/developer-library/reference/linux-constants/syscalls/#x86_64-64-bit
    
    mov rdx,rbx      ;number of bytes to write
    mov rsi,rax      ;pointer/address of string to write
    mov rdi,1        ;write to the STDOUT file
    mov rax,1        ;invoke SYS_WRITE (kernel opcode 1 on 64 bit systems)
    syscall          ;system call to write the message
    
    pop rdx
    pop rcx
    pop rbx
    pop rax
    
    ret ; this is the end of the putstring function return to calling location
    
    
    ; This Assembly source file has been formatted for the FASM assembler.
    ; The following 3 commands assemble, give executable permissions, and run the program
    ;
    ;	fasm main.asm
    ;	chmod +x main
    ;	./main
    
    

    You may notice that the 64-bit program also uses the syscall instruction rather than interrupt 0x80. On my machine both programs behave identically because both calling conventions are valid. There are executables that run in 32 bit mode and others that run in 64 bit mode. They are not usually compatible and the FASM assembler has to be told which format is being assembled.

    FASM has been my preferred assembler for a long time because unlike NASM, it has everything it needs to create executables without depending on a linker.

    “What is a linker?” You might be asking. You see, the developers of Linux never really expected for people to be writing applications entirely in assembly. Usually they are written in C and then GCC compiles it to assembly that only the Gnu assembler (informally called Gas) can assemble and then link with the standard library. There is a linker program called “ld” that GCC automatically uses.

    However, through some research and experimentation, I have converted the previous 64 bit FASM program into the Gas syntax. As you read it, remember that the AT&T phone company made this weird alternative syntax. The source and destination have been flipped so you will see the register receiving data on the right side instead of the left.

    main.s (GNU Assembler 64 bit)

    # Using Linux System calls for 64-bit
    # Tested with GNU Assembler on Debian 12 (bookworm)
    # It uses Chastity's putstring function for output
    
    .global _start
    
    .text
    
    _start:
    
    mov $main_string,%rax # move address of string into rax register
    call   putstring      # call the putstring function Chastity wrote
    mov    $0x3c,%eax     # system call 60 is exit
    mov    $0x0,%edi      # we want to return code 0
    syscall               # end program with system call
    
    main_string:
    .string	"This program runs in Linux!\n"
    
    putstring:            # the start of the putstring function
    push   %rax
    push   %rbx
    push   %rcx
    push   %rdx
    mov    %rax,%rbx
    
    putstring_strlen_start:
    cmpb   $0x0,(%rbx)
    je     putstring_strlen_end
    inc    %rbx
    jmp    putstring_strlen_start
    
    putstring_strlen_end:
    sub    %rax,%rbx # subtract rax from rbx for number of bytes to write
    mov    %rbx,%rdx # copy number of bytes from rbx to rdx
    mov    %rax,%rsi # address of string to output
    mov    $0x1,%edi # file handler 1 is stdout
    mov    $0x1,%rax # system call 1 is write
    syscall
    pop    %rdx
    pop    %rcx
    pop    %rbx
    pop    %rax
    ret
    
    # This Assembly source file has been formatted for the GNU assembler.
    # The following makefile rule has commands to assemble, link, and run the program
    #
    #main-gas:
    #	gcc -nostdlib -nostartfiles -nodefaultlibs -static main.s -o main
    #	strip main
    #	./main
    

    Although I find the GNU Assembler syntax hard to read, the fact that this assembler exists as part of the GNU Compiler Collection means that it is usually available even on systems that don’t have FASM or NASM available.

    It is possible to use NASM also but it can’t create executables and requires linking with “ld” anyway. It is better to just write directly for the GNU Assembler or stick with FASM if you prefer intel syntax.

    However, the beauty is that the machine code bytes from both types of assembly are identical! In fact that is how I got the GAS version. I had to assemble the other version and then disassemble it with objdump to get the equivalent syntax.

    The programs you saw in this chapter only work on Linux, but Linux is Free both in terms of Software Freedom and Free in price too because anyone with an internet connection can download the ISO of a new operating system and install it on their computer as long as they take the time to read directions from the makers of that distribution. In fact Debian, Arch, Gentoo, and FreeBSD (not Linux but very similar) all have great instruction manuals. If you have managed to read this book, then you will have no problem following their stuff.

  • Age Verification Rant

    As a Free Software and Open Source advocate, I am always aware of the latest technology changes. In March of 2026, I found several articles and visuals detailing laws that people were trying to pass to force operating systems to have “age verification” built into them. I should not have to tell you my opinion on this because it should be obvious.

    The goal of these laws is to force people to prove that they are 18 years or older to be able to use their computers. As someone who grew up with old computers running DOS, Windows 3.1, Windows 98, and Ubuntu Linux, all before I was 18, I have to say that I oppose such laws because they prevent kids from learning how to use computers at an early age.

    People who are in favor of these laws claim that they are protecting children from harmful things. Don’t fall for this lie. No additional software changes are needed. Parents are ultimately in charge of the computers they buy for their kids and installing parental controls on them if they wish. Also, many websites require users to be 13 years or older to create things like a Facebook account. At some point, these children and especially their parents need to be responsible for following the rules.

    I am not against age verification in principle, but I have to consider the facts. In many cases, age verification will require users to provide photo IDs or Driver’s Licenses to access services we depend on. AI software for reading these already exists for many websites.

    If the government just decides that your state ID or driver’s license is nullified and invalid, this means you can no longer do what others do. See the situation in Kansas for why I, as a Transgender person, am concerned with the evil things governments can do on a whim.

    https://www.nbcnews.com/news/us-news/kansas-revoked-drivers-licenses-1700-transgender-residents-rcna262120

    But laws like the recent one in California go a step further and want to make age verification part of the operating system.

    https://leginfo.legislature.ca.gov/faces/billTextClient.xhtml?bill_id=202520260AB1043

    If you are on a PC or cell phone using software by Microsoft, Apple, or Google, you will not experience any change because these operating systems already lock people out if they don’t have money to buy things in the app stores or a cell phone that can receive text messages. In most cases, only adults have access to cell numbers and email addresses due to the fact that email providers now force people to verify with their phones.

    Side note: The two-step cell phone text verification is a crime against my own mother, who cannot operate a cell phone and has to have my help to get into her own email sometimes. I have also been kicked off my own email several times and had to use my phone. Digital ID is already here because nobody is allowed to do literally anything without a cell phone these days. People can’t even work at Walmart without a cell phone anymore because everything requires the MyWalmart app, which uses the same verification. If my cell phone is lost or stolen, I can’t clock in to work, can’t check my bank account, order an Uber ride, or even call my mom to tell her I am alive. Though at least I can walk since we are both in Lee’s Summit.

    I am a 38-year-old adult who used computers long before I even had internet access. My own response to these evil actions is to censor and restrict people from using their own computers. The biggest target that will be hurt is the Linux operating system because Linux is all about Freedom of software and privacy. The laws passing in some states can make it illegal to install or distribute an operating system without these age verification signals, constantly letting the government and all foreign enemies know who you are and how old you are, because they have your photo ID, which may or may not be valid depending on how transgender you are at the time.

    My cell phone controlling my life is something I can’t do anything about, but nobody touches my Linux PC, where I write my books and do my own programming for the pure love of math. These draconian laws basically make the past 30 years of my life using computers illegal.

    But you know what? It’s gonna be funny when I go to prison and am placed in a room full of rapists, murderers, and people who did nothing wrong but were accused of things because of their skin color. They will ask me: “What are you in for?”

    And I will tell them, “I used Linux and wrote several books and hundreds of fun programs.” Then they will ask me what Linux is. If you feel bad because you don’t know what Linux or the GNU project is, keep in mind that these lawmakers don’t have a clue either.

  • Chastelib Readme and Manifesto

    Chastelib is a library I have been developing since mid 2025, though some of the functions have existed in some form for 20 years and have been hacked together as I needed them for projects. Over the past 6 months, I have refined them and have extensively documented the source code, and have even begun writing a manual on how to use them. This project will take years, as I have fun improving things and explaining why my own methods of outputting numbers now surpass the capabilities of the C and C++ standard libraries when it comes to printing integers in other bases.

    To my knowledge, nobody other than me uses these functions, but they are extremely easy to use by including header files or just copy pasting the functions you like into your own C and C++ projects.

    Core Function List

    • intstr: Convert an integer to astring in bases 2 to 36
    • strint: Convert a string in bases 2 to 36 to an integer
    • putstring: Print a zero-terminated string to standard output
    • putint: Print an integer using intstr and then putstr

    To understand the context of this library and how it came about, you have to know that I have been a C programmer for 25 years. Most of my projects are just toy programs for printing sequences of integers. Even more strange is that I enjoy bases other than ten, referred to as decimal by humans.

    Math is a game to me, and I do computer programming for fun. I also think that the C programming language is the best programming language to ever exist. However, there are some limitations that come with it.

    The printf family of functions can output formatted text containing arbitrary strings of text with format specifiers and arguments to print integers and floating point numbers.

    For integers, there is the %d for decimal, %u for unsigned decimal, %X for hexadecimal, and %o for octal. Although these are the most common number bases used, I prefer the option to print binary. The %b format specifier does exist as a GNU extension, but because I like my code to conform to the 1989 standard, I decided I should write my own set to manage the conversion of integers to and from strings that I can always rely on.

    Of the core functions, only putstring uses a C standard library function. It uses the low-level fwrite function to write a string after finding its length by searching for the terminating zero.

    Although simple, the putstring allows me flexibility when I am translating chastelib to use a new C library, or when I want to translate all the functions to another programming language.

    For example, when using other languages, I can’t rely on printf being available. Moreover, printf is a complicated function to write, and I have no idea how it actually works. When I tried translating my functions to Rust, having putstring as my trusted output function helped a lot. That being said, Rust is a painful language, and I stopped because it hurt my head too much, which is saying something, given how good I am at Assembly language on Intel platforms.

    The putstring function also helped when I was using ncurses because I could just change putstring to call addstr, which does the same thing in the context of terminal programs written with ncurses.

    The other functions don’t read or write to any devices and rely on putstring to show results. However, this means they execute very fast. Not only is C fast because it is a compiled language, but I have incrementally improved my algorithm over months to do the work quickly, and also made the code look good at the same time.

    Of all the functions used, strint is used the least because most of the time I am the only one providing input to my programs. If other people were using my programs, they would of course provide strings from the keyboard that would be parsed as integers. I have tested the function to ensure that it works correctly. In fact, my program chastehex was why the function was originally written. I could have had a generic hexadecimal converting function, but I made one that was flexible and supported any base from 2 to 36.

    Technical note: Base 36 is the highest base because digits 0 to 9 are used for digits less than ten. Letters A through Z are used as 10 to 35, whether they are uppercase or lowercase. The ten digits plus 26 letters of the English Alphabet provide a standard that programmers have used before I was even born. It is a good standard, and so I stuck with it.

    Future Extensions

    • floating point conversions
    • ncurses utilities

    The Github repository with the latest source is here:

    https://github.com/chastitywhiterose/chastelib

  • C chastelib core 2-25-2026

    There comes a time every so often when I find a typo in my source code. I recently found one in the C version of chastelib. I used the opportunity to expand on my existing comments to better explain the purpose of these functions which are used in my chastehex and chastecmp programs.

    I am also working on extension libraries to add to chastelib to support future command line utilities I might write, even if I don’t know what tools I will write. I have dreams of making my own small programming language but what I imagine is more complex that I am prepared for at my skill level and lack of free time.

    I just finished my Programming 2 class about C++ and I have to say that I still prefer C, even though there are some features of C++ such as function overloading that I find extremely cool.

    Anyway, read below this years edition of the 4 functions that make up the core of chastelib, my own standard library I am building.

    /*
     This file is a library of functions written by Chastity White Rose. The functions are for converting strings into integers and integers into strings.
     I did it partly for future programming plans and also because it helped me learn a lot in the process about how pointers work
     as well as which features the standard library provides, and which things I need to write my own functions for.
    
     As it turns out, the integer output routines for C are too limited for my tastes. This library corrects this problem.
     Using the global variables and functions in this file, integers can be output in bases/radixes 2 to 36
    */
    
    /*
     These two lines define a static array with a size big enough to store the digits of an integer, including padding it with extra zeroes.
     The integer conversion function always references a pointer to this global string, and this allows other standard library functions
     such as printf to display the integers to standard output or even possibly to files.
    */
    
    #define usl 32 /*usl stands for Unsigned String Length*/
    char int_string[usl+1]; /*global string which will be used to store string of integers. Size is usl+1 for terminating zero*/
    
     /*radix or base for integer output. 2=binary, 8=octal, 10=decimal, 16=hexadecimal*/
    int radix=2;
    /*default minimum digits for printing integers*/
    int int_width=1;
    
    /*
    This function is one that I wrote because the standard library can display integers as decimal, octal, or hexadecimal, but not any other bases(including binary, which is my favorite).
    My function corrects this, and in my opinion, such a function should have been part of the standard library, but I'm not complaining because now I have my own, which I can use forever!
    More importantly, it can be adapted for any programming language in the world if I learn the basics of that language.
    */
    
    char *intstr(unsigned int i)
    {
     int width=0;
     char *s=int_string+usl;
     *s=0;
     while(i!=0 || width<int_width)
     {
      s--;
      *s=i%radix;
      i/=radix;
      if(*s<10){*s+='0';}
      else{*s=*s+'A'-10;}
      width++;
     }
     return s;
    }
    
    /*
     This function prints a string using fwrite.
     This algorithm is the best C representation of how my Assembly programs also work.
     Its true purpose is to be used in the putint function for conveniently printing integers, 
     but it can print any valid string.
    */
    
    void putstring(const char *s)
    {
     int c=0;
     const char *p=s;
     while(*p++){c++;} 
     fwrite(s,1,c,stdout);
    }
    
    /*
     This function uses both intstr and putstring to print an integer in the currently selected radix and width.
    */
    
    void putint(unsigned int i)
    {
     putstring(intstr(i));
    }
    
    /*
     This function is my own replacement for the strtol function from the C standard library.
     I didn't technically need to make this function because the functions from stdlib.h can already convert strings from bases 2 to 36 into integers.
     However, my function is simpler because it only requires 2 arguments instead of three, and it also does not handle negative numbers.
    I have never needed negative integers, but if I ever do, I can use the standard functions or write my own in the future.
    */
    
    int strint(const char *s)
    {
     int i=0;
     char c;
     if( radix<2 || radix>36 ){printf("Error: radix %i is out of range!\n",radix);}
     while( *s == ' ' || *s == '\n' || *s == '\t' ){s++;} /*skip whitespace at beginning*/
     while(*s!=0)
     {
      c=*s;
      if( c >= '0' && c <= '9' ){c-='0';}
      else if( c >= 'A' && c <= 'Z' ){c-='A';c+=10;}
      else if( c >= 'a' && c <= 'z' ){c-='a';c+=10;}
      else if( c == ' ' || c == '\n' || c == '\t' ){break;}
      else{printf("Error: %c is not an alphanumeric character!\n",c);break;}
      if(c>=radix){printf("Error: %c is not a valid character for radix %i\n",*s,radix);break;}
      i*=radix;
      i+=c;
      s++;
     }
     return i;
    }
    
    /*
     Those four functions above are the core of chastelib.
     While there may be extensions written for specific programs, these functions are essential for absolutely every program I write.
     
     The only reason you would not need them is if you only output numbers in decimal or hexadecimal, because printf in C can do all that just fine.
     However, the reason my core functions are superior to printf is that printf and its family of functions require the user to memorize all the arcane symbols for format specifiers.
     
     The core functions are primarily concerned with standard output and the conversion of strings and integers. They do not deal with input from the keyboard or files. A separate extension will be written for my programs that need these features.
    */
    
  • Advice to a new Programmer

    This month I started a Programming 1 class as part of Full Sail University’s ACE program. One of the other students asked me some questions and I ended up writing a larger response than I planned. I think my information will be helpful for other people who are new to programming.

    Hello chastity, I’m Ty. I appreciate you teaching others what you know. I do not know anything about programming, but I’m hoping I learn a lot from this college course and make friends like you. I would love any tips you have for me, as a programmer newbie. What language to start with? Fundamental apps, tools, services, etc.. anything I should to start. Thank you chastity.

    There are many tools I can recommend. Mostly, I stick with Free and Open Source software. I write most of my code in the C Programming Language, which came before C++. I use the GCC compiler, and I even use GNU Make to automate compiling and running my programs.

    I am looking forward to learning about how C++ is different than C. I always found C to be an easy language because it is smaller than C++, and I have most of the functions memorized.

    Also, you may find this helpful.

    https://chastitywhiterose.github.io/Chastity-Code-Cookbook/

    It is a book/website I have been writing to help teach programming, but also to share some of my impressive code examples and philosophy of why I promote Free Software.

    Everything on there is entirely free and released under the GPL3 license. I consider it my act of community service to give back to the open source community because it has benefitted me all my life. I have a blast compiling my C programs on Debian Linux with GCC on computers too old to run modern versions of Windows. I don’t even use an IDE. I only use a console and a text editor as if I were living in the 1980s. But at least this Programming 1 course teaches things as most humans would find convenient.

    I can also probably help you with specific programming questions. What operating system do you use, and how is your general math knowledge? I think you will find that no matter what programming language becomes your favorite, every data type really is numbers, even such things as colors or coordinates for shapes in video games.

    Most of the magic in the video game, Chaste Tris, that I published comes from my knowledge of numbers rather than it does being a good programmer. I consider myself more of a gamer and mathematician than I am a skilled programmer.

    https://store.steampowered.com/app/1986120/Chaste_Tris/

    I also wanted to mention some cool text editors that you might like. On Windows, Notepad++ is the most convenient text editor because it has syntax highlighting, but it loads up faster than Visual Studio if you are doing your own programming for fun, which isn’t required for the class.

    https://notepad-plus-plus.org/

    But I also recommend Geany because it runs on Windows, Mac, or Linux. I use it quite a bit when I need my code to be more readable for larger projects.

    https://www.geany.org/

    I think the most important feature of a text editor and/or IDE for a programmer is the ability to see the line numbers because when a compiler tells me an error I have on a specific line, being able to see which line that number is on helps out a lot. The second most important feature is to choose a highlighting syntax that is easy on your eyes. Each person is different, and their eyes perceive colors differently. A lot of these editors will let you choose a scheme that works for you, or even create your own. For example, you might like numbers to be in blue text and functions to be green. Or maybe you like a black background with bright colors like magenta or yellow for the text. I like my code to look beautiful as well as to compile and run successfully.