Tag: writing

  • Assembly Arithmetic Algorithms RISC-V

    Assembly Arithmetic Algorithms

    RISC-V Edition

    Preface

    This book is the RISC-V edition of Assembly Arithmetic Algorithms. This is the third book in the series but it is a completely acceptable way to learn programming, even for beginners.

    The first book was for 16-bit DOS programming using Assembly. The second book was for 32-bit Linux programming using the same assembly language for Intel machines.

    But the book you are reading now, is fundamentally different in nature. It uses simulators that run in any operating system to teach a new type of Assembly language for the RISC-V (Reduced Instruction Set Computing-Generation 5) processor.

    RISC-V is important because it is a royalty free open standard. This means that as it catches on, more companies will be able to make cheaper computers because they will not have to pay royalties to the Intel or ARM companies. I guess you could say that it is Open Source Hardware, which in my opinion is the final piece we need to match the Open Source Software people like me already have been enjoying with GNU and Linux.

    Introduction

    First, let me introduce this book by telling you what I will teach you. By the end of this book, you will have enough information to write small programs that will run on your machine but also allow you to bypass complicated languages like C++, Java, or even the Bash Linux shell. Arguably, the beautiful thing about Assembly is its simplicity.

    RISC-V is great because it is a Reduced Instruction Set Computing device. It has fewer instructions to learn and remember, especially when compared to Intel. It also has more registers available for use. Each of them have special purposes and conventions for how they are used. However, as the programmer, you are allowed to break these conventions because right now, your focus should be on learning it for fun!

    Required Knowledge

    To get the most out of this book, some background on the Binary and Hexadecimal numeral systems is going to be helpful, but this is not strictly required because I will be providing functions you can use in your code that will convert between decimal (base ten), binary (base two), and hexadecimal (base sixteen).

    However, I would say that experience in at least one programming language is necessary for an understanding of terminology like “arrays”, “pointers”, “addresses”, “integers”, etc. I recommend the C Programming Language as a start. C++ is also a good starting language, but it tends to abstract details away that directly apply to Assembly Language, which is the lowest level a human can go for understanding a computer.

    But I think it is perfectly okay for this Assembly language to be your introductory language for the world of computer programming. The language is simple, beautiful, and in my opinion, was designed better than Intel x86. The makers of the RISC-V architecture saw what other processors were doing and in some ways tried to avoid making the same mistakes as previous generations did.

    RISC-V is a new processor type and philosophy that was created in 2010 at University of California, Berkeley. The V in its name is actually the Roman number 5. That means there were apparently those named I,II,III,VI in the past.

    Many people have high hopes about this new computer architecture that is also old enough to trust. Because it is 16 years old at this time and has been standardized, there are many simulators available. This book will present two of these simulators and perhaps a passing mention of others as I learn about them myself and can provide more links.

    But because RISC-V is still relatively young compared to Intel 8086 (year 1978) and ARM (year 1983), I expect that the timing of this book will be of use to people who have heard about RISC-V and wonder what it is about.

    Low Level

    Low level is a term that confuses people. People think something high-level is better than low-level. In simple terms, humans consider themselves superior to machines and therefore think themselves higher or more important because of their abstract thought.

    A computer thinks only in terms of numbers. A computer may not understand “high-level” abstractions such as love, religion, philosophy, etc, but that is not its job. A computer must add, subtract, multiply, and divide. These are the four arithmetic functions that many humans struggle with.

    Therefore, I ask you, between a human and a computer, who is really low level or high level? In the age of Artificial Intelligence taking over human jobs and beating humans at Chess, we would all do well to take this question seriously.

    I wrote this book because I think like a machine, and I hope to help others think this way because it is the best way to learn programming and control your computer by writing Assembly Language programs, or to go back to your favorite programming language with a greater understanding of why things work as they do.

    Why RISC-V

    After writing 3 programming books, I decided I wanted to learn a language that offered the things I love about C and Assembly but was also new and exciting at the time.

    I first learned RISC-V from Robert Winker’s book.

    https://leanpub.com/riscvassemblyprogramming

    It was also available on Leanpub and I thought his teaching style is a standard that I hope to live up to. Obviously he is more experienced and his book is probably better than mine. Even so, I wanted to do my own part to promote education about RISC-V because I want to see a world where programming is easier and computers are cheaper. As much as I love Intel machines because I grew up with them, RISC-V provided me a new learning experience that I hope others discover and enjoy as much as I have!

    Chapter 1: The First Program

    For this chapter, I will explain give the source code of an example program that works in both RARS and riscemu simulators. Take a good look at it and the comments I included. I will be explaining this in detail. I also recommend you type or copy and paste this code into a text editor and save the file as “main.s” in a place on your computer that you prefer.

    Hello World

    .data
    
    string0: .asciz "Hello World!\n"
    
    .text
    
    li a0, 1       # STDOUT file number
    la a1, string0 # address of string 
    li a2, 13      # length of string
    li a7, 64      # write call number
    ecall          # environment call
    
    li a0, 0       # status
    li a7, 93      # exit
    ecall          # environment call
    

    There are two sections named “.data” and “.text”. All variables used in the program should be defined in the .data section. The .text section is where your code starts executing. This organization scheme is required for most simulators and assemblers.

    This program prints “Hello World” followed by a newline. It uses only 3 kinds of instruction and is fairly easy to follow.

    • li = load integer (or immediate value)
    • la = load address (a special kind of integer)
    • ecall = enviroment call (or syscalls)

    The reason that sometimes li is used to load a register and other times la is used is because technically, there is a limit on the size of integers that can be part of an instruction. Instructions like “la” are technically macros for multiple instructions that load upper and lower bits of a register.

    But besides that, having la for memory addresses and li for regular numbers makes the code more readable in my opinion.

    ecall is the how you would call the system calls of your operating system. It is the same idea as “int 0x80” was in my Linux Intel Assembly book. However, in RISC-V, there are different registers and different system call numbers than you would expect on Intel CPUs.

    But more importantly, this program was written for simulators and not a real operating system. The call numbers, which are loaded into the a7 register, are specific to the RARS and riscemu simulators. In the next chapter, I will explain the differences between these two simulators and how to run the program.

    Chapter 2: Simulator Choices

    There are two simulators I personally use and test my code against. Both of them are Free Software and available to download from their Github repositories. I will offer some information about them so you can choose which to use when following along with this book.

    RARS

    RARS is a port of the MARS simulator for MIPS processors. It is written in Java and is downloadable as a

    https://github.com/rarsm/rars

    This book favors RARS because it is easy to use and is reliable enough to use from any operating system. It also supports a lot of system calls and is the simulator I learned to use first. Because it runs using Java, you must have the Java Runtime installed. However, since Java can be installed and run on any operating system, you can be sure that it will work no matter whether your host operating system is Windows, Linux, or Mac.

    On my system, I usually have the file named “rars.jar” in my home directory. This allows me to run my source file like this:

    java -jar ~/rars.jar main.s
    

    Because ~ is a shortcut for the home directory, this allows me to run it from whichever directory I happen to be in that contains my source file, which in this case is named “main.s”.

    riscemu

    Riscemu is a simulator written in Python. It does not have as many system calls built in but it is a good option for people who have Python installed but cannot, or don’t want to install Java.

    https://github.com/AntonLydike/riscemu

    Running a source file with riscemu is even easier that with RARS.

    riscemu main.s
    

    In my experience, riscemu also launches faster than RARS does, mostly just because RARS requires Java to load the whole virtual machine before it starts. Because riscemu is written in Python, and Python is written in C, it is only natural that it might be faster.

    However, riscemu is really picky about having a space after commas in your instructions. It will fail with cryptic error messages if you don’t have proper spacing between your arguments to an instruction. This is probably a bug but it allows for consistency in formatting if you just remember to add a space after each comma. If you don’t like to do this, just forget riscemu and stick with RARS.

    Why use a simulator?

    You might be wondering why I am recommending using these simulators rather than a real assembler for a real machine with an operating system. There are 3 reasons.

    • I don’t have a computer with a RISC-V processor.
    • Simulators can be used by more people because they don’t require buying new hardware.
    • No “risk” in trying out this new RISC based machine.

    In short, I use these simulators or emulators for the same reason I used DOSBox in the DOS version of Assembly Arithmetic Algorithms.

    An emulator allows people to learn the language a Central Processing Unit uses before they have invested time or money into learning it. This means no investment or sacrifice from you.

    In fact, you might decide to forget learning RISC-V Assembly and learn Java or Python instead. Even so, I wrote this book so that I can share what a beautiful language the RISC-V Assembly language is and why I enjoy coding in it.

    Chapter 3: System Calls

    There are many more system calls for RARS than I will be teaching in this book. riscemu has less than RARS but the table below shows the calls that these two simulators both have in common. The 3 calls are enough for most programs.

    System Calls for RARS and riscemu

    Name a7 a0 a1 a2
    exit 93 status
    read 63 fd buf count
    write 64 fd buf count

    For more advanced programs that open and close files, you will need to use different call numbers and also different mode numbers. Unlike Linux and the POSIX system calls, the simulators are meant for teaching the language but you can’t count on them being compatible with each other in the same way. It is pure luck that the system calls for the 3 calls above matched. It is precisely this reason that I chose RARS and riscemu as the simulators for this book.

    Registers on RISC-V

    There are a LOT more registers than there were on Intel machines. This makes using RISC-V very easy because you don’t have to use memory locations as often.

    Name meaning/usage
    zero always = zero
    ra return address
    a0->a7 arguments
    s0->s11 saved values
    t0->t6 temporary

    The zero register is just a register that always equals zero. It may seem weird but remember than RISC-V does not allow comparing a register directly with a number. Normally you need to load a number into another register. But because comparing with zero is a common operation, this zero register is available to be compared or copied any time!

    The ra register is important for function calls. It is the register that keeps where you will return to when the function is done. Because of this, you will run into trouble if you try to do something else with it.

    The other registers can technically be used any way you want except that those starting with ‘a’ are used for arguments to environment calls. For this reason, they are used more than others.

    The registers that begin with ‘s’ or ‘t’ are technically the same but it is a convention or tradition that t0 to t6 are used for temporary cases where you need to add, subtract, multiply, or divide numbers. After you are done with them, you use them for something else and forget what you did with them last time.

    The s0 to s11 registers are the most abundant and you are expected to keep things that endure most or all of the program in them. For example, you might keep a file descriptor in one of them so that you could copy it to the correct ‘a’ register when you need to.

    Because of the fact that you cannot compare or otherwise perform math on memory addresses directly, you have to always load everything into registers. However, because RISC-V has more registers, you can also write programs that run faster because you access memory less often.

    However, you will be loading and saving memory for variables stored in the data section. Usually these will be strings you are printing.

    In the next chapter I will be introducing a function that can print any string by automatically calculating its length. I will also be using the calling convention of the recommended register usage.

    To be continued

  • new program: chastearg

    I wrote a small program for both Linux and DOS assembly. It is very easy to explain what it does with some pictures. The first picture is what it looks like when I use the Linux version on my Debian system. The second is the DOS version running under the DOSBOX emulator.

    As you can see, the words surrounded by quotes are displayed on the same line because they count as one argument. Linux handles this by default but DOS needed some help. I had to rewrite my entire argument filter for the DOS version.

    The reason I wrote this project and worked to make it consistent for both DOS and Linux is because I wanted to do an upgrade to the DOS version of chastext. As you can see from the picture below, I have succeeded!

    When I first posted about my chastext project, some people said it was useless because we can already use sed for Linux or other tools for find and replace. However, my assembly versions are simpler and faster than sed when you don’t need regular expressions. They also don’t depend on anything other than interrupt calls of the operating system.

    But more importantly, their argument is stupid. Writing similar programs to existing programs is a great programming exercise and is especially important for tiny projects where I don’t want to implement all the features of a program or its dependencies. I can also bring the program to platforms that the original program does not support, such as DOS.

    This attitude some people have is one that I don’t like. Should I not sing just because Taylor Swift can sing better than me? Should I not play the piano just because other people can do it better than me? Or should I not play Chess just because I can’t do it as well as Magnus Carlsen or a chess engine?

    I started programming for the joy of learning and writing me own things. I often reinvent the wheel such as how I wrote my own strlen and strcmp functions for my chastext project. I don’t have access to the C standard library with the way I am doing it. I can’t imagine criticizing someone else’s programming project just because it has features to a similar tool that may exist. Otherwise, I would be saying Linus Torvalds should not have created Linux just because Unix and Minix existed which had similar file systems.

  • Podcast and Programming Update 4-26-2026

    A lot of important things are going on in my life right now. Yesterday, I did episode 30 of the podcast series that my mom and I do together. It is the start of a mini series on Pride Month and the LGBTQIA+ community. It means a lot to have my mom as my ally in the fight for equality at this time, when transgender people are a punching bag of politicians and organizations like the Heritage Foundation lobbying them to discriminate against us.

    On a completely unrelated note, I often do computer programming to help me relax because it brings order to the chaos of life, and I am getting good at it. I have been working on creating a small set of utilities. My first two tools: chastehex and chastecmp, have been optimized to the extreme both in C and Assembly language. I recently made some changes to the C version so that the output of the programs matches the Intel assembly language versions for consistency.

    For each of these tools, I have created a separate repository for them, which includes not only the C source (which can run on any platform), but also the assembly versions for DOS, Linux, and even Windows.

    https://github.com/chastitywhiterose/chastehex
    https://github.com/chastitywhiterose/chastecmp

    Perhaps the reason these tools were so much fun to work on is that they do one job and do it well. I have still been thinking about what other tools like this I might create. The fun is that I optimize them for maximum speed, but readability of code at the same time.

    I have also made some attempts at making another game, but nothing has quite inspired me in that direction as much as doing simple text utilities. I will be studying common Linux commands in order to see if there are any gaps in functionality that I can fill by writing a tool for. I want to make something new that doesn’t exist. Chastehex certainly meets that criteria, but I wonder what else I can do?

  • Chastity’s List of Completed Full Sail University Classes

    This list contains all the classes I completed as part of 3 different programs. My original enrollment was in Game Business and Esports Science, but then I switched to creative writing. After graduation, I took some computer programming classes as part of the ACE (Alumni Continuing Education) program.

    These varied interests I have all have a generic theme. Storytelling as it relates to video games includes two parts. There are the words of the story and how the games are communicated in English to humans. The other side of it is the math that computers understand as well as autistic math nerds like me.

    Joseph Sheckels
    Systems Programming – Online
    SDV3111-O • Term C202603 • Section 02

    Garrett Girod
    Programming II – Online
    COP2334-O • Term C202602 • Section 04

    Davide Bisso
    Career Readiness – Online
    CRR4000-O • Term C202601 • Section 17ACE

    Douglas Arley
    Programming I – Online
    COP1334-O • Term C202601 • Section 08

    Joshua Collier
    Project and Portfolio III: Creative Writing – Online
    CWB338-O • Term C202506 • Section 02

    Matthew Peters
    Publishing and Distribution – Online
    ECW2953-O • Term C202505 • Section 02

    Convert Instructor
    Graduation Launch
    GRAD4000-O • Term C202506 • Section 05

    Joshua Begley
    Literary Genre I: Comedy and Tragedy – Online
    ECW3111-O • Term C202504 • Section 03

    John King
    Project and Portfolio II: Creative Writing – Online
    CWB228-O • Term C202503 • Section 02

    Cory Helms
    Television Writing – Online
    ECW3702-O • Term C202502 • Section 02

    Elise McKenna
    Developing New Worlds: Environment and Historical Research – Online
    ECW2841-O • Term C202501 • Section 02

    Genevieve Tyrrell
    Project and Portfolio I: Creative Writing – Online
    CWB119-O • Term C202412 • Section 01

    Cory Helms
    Writing Workshop I: Film – Online
    ECW4101-O • Term C202411 • Section 02

    Beth Strudgeon
    Introduction to Media Communications and Technologies – Online
    MCM1002-O • Term C202410 • Section 03

    Christopher Ramsey
    Multimedia Storytelling – Online
    ECW1409-O • Term C202410 • Section 01

    Brett Pribble
    Creative Skills Development – Online
    ECW1225-O • Term C202409 • Section 03

    Cory Helms
    Literary Techniques and Story Development – Online
    ECW2123-O • Term C202408 • Section 04

    Becca Godsey
    Professional Development Seminar II: Game Business and Esports – Online
    GBE3222-O • Term C202407 • Section 02

    Aaron Conner
    Project and Portfolio II: Game Business and Esports – Online
    GBE229-O • Term C202407 • Section 01

    Ren Vickers
    Game Business Models – Online
    GBE2501-O • Term C202406 • Section 01

    Shane Marcus
    Physical Science – Online
    PHY3020-O • Term C202405 • Section 05

    Ashley Jones
    Professional Development Seminar I: Game Business and Esports – Online
    GBE1111-O • Term C202404 • Section 01

    Becca Godsey
    Project and Portfolio I: Game Business and Esports – Online
    GBE119-O • Term C202404 • Section 01

    Terry Clark
    College Mathematics – Online
    MGF1213-O • Term C202403 • Section 04

    Otavio Moulin Lessa
    Gaming Culture and Engagement – Online
    GBE2001-O • Term C202402 • Section 01

    Philip Lacinak
    Digital Video and Audio Production – Online
    MCM2416-O • Term C202401 • Section 02

    David Sussman
    English Composition I – Online
    ENC1101-O • Term C202312 • Section 37

    Mike Dunn
    New Media Tools – Online
    MCM1203-O • Term C202311 • Section 09

    Ricky Sellers
    Video-Sharing Platforms – Online
    VID1555-O • Term C202310 • Section 01

    Katherine Coulthart
    Storytelling for Marketing – Online
    MKT163-O • Term C202309 • Section 02

    Alexia Brehm
    Introduction to Marketing – Online
    MKT210-O • Term C202308 • Section 01

    Brandon Morris
    Introduction to Esports Production – Online
    GBE1021-O • Term C202307 • Section 02

    Charles Cardwell
    Introduction to the Gaming Industry – Online
    GBE1001-O • Term C202306 • Section 02

    Jennifer Salzberg
    Psychology of Play – Online
    DEP1013-O • Term C202305 • Section 17

    Eddie Tapia
    Creative Presentation – Online
    GEN1011-O • Term C202304 • Section 26

    Orientation Team
    Full Sail Online Orientation (FSLE) – Online
    GEN2000-O • Term C202304 • Section 06

  • 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.