Kick off your book project in 3 hours! Live workshop on Zoom. You’ll leave with a real book project, progress on your first chapter, and a clear plan to keep going. Saturday, May 2, 2026. Learn more…

Leanpub Header

Skip to main content

Assembly Arithmetic Algorithms-DOS

16-bit DOS Edition

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

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 which many human struggle to do.

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.

Free With Membership

With Membership

Free!

$5.00

You pay

$5.00

Author earns

$3.50
$
You can also buy this book with 1 book credit. Get book credits with a Reader Membership or an Organization Membership for your team.
PDF
EPUB
WEB
About

About

About the Book

You might be surprised to find a book in the 21st century about programming in Assembly Language on DOS.

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 any text based console program in the form of a 16-bit DOS (Disk Operating System) ".com" file.

The ".com" file was a format used by all version of MS-DOS, and even supported on Windows up to XP. It has no header information and is limited to 64 kilobytes of memory. Rather than viewing the limitation as a weakness, I view it as a strength because it forces me to be a better programmer and squeeze the most out of every byte.

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 16).

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

Author

About the Author

Chastity White Rose

Chastity White Rose is an author of over twelve books and two WordPress blogs. She writes humorous and educational content about philosophical and religious topics. She also uses her writing and graphic design skills to teach people about the game of Chess. She is earning an associate’s degree in creative writing at Full Sail University. As a transgender Christian woman, she writes books and blog posts to help others like her process the seeming disconnect between religious faith and an LGBTQIA+ identity. She measures the success of her writing by its emotional impact rather than its sales. For this reason, most of her writing is available free of charge.

Contents

Table of Contents

Assembly Arithmetic Algorithms

Preface

Introduction

  1. Required Knowledge
  2. Low Level
  3. Why DOS?
  4. Online Example Programs

Chapter 1: The First Program

  1. Assemble with FASM
  2. Assemble with NASM
  3. Disassembling the Program
  4. The General Purpose Registers
  5. Interrupt Information

Chapter 2: The putstring Function

Chapter 3: The intstr and putint functions

Chapter 4: Chastity’s Intel Assembly Reference

  1. mov
  2. add
  3. sub
  4. mul
  5. div
  6. cmp
  7. jmp
  8. push/pop
  9. Take it slow

Chapter 5: Integer Sequences and Their Application in Learning

  1. Fibonacci numbers
  2. Powers of 2
  3. Prime Numbers
  4. How to use these examples

Chapter 6: The strint Function

  1. The Program
  2. The Function
  3. The Output

Chapter 7: Translating Assembly to Other Programming Languages

  1. main.asm
  2. chastelib16.asm
  3. Assembly Test Suite Output
  4. main.c (The C Test Suite)
  5. chastelib.h (The C chastelib library)
  6. Portable Assembly Language

Chapter 8: Going from DOS to Linux or Windows

  1. main.asm (32 bit)
  2. main.asm 64 bit
  3. main.s (GNU Assembler 64 bit)

Chapter 9: Bitwise Operations for Advanced Nerds

  1. The Bitwise Operations
  2. Example 0: Fake Add
  3. Example 1: Fake Sub

Chapter 10: chastehex: Not just a program, but a philosophy.

  1. chex.asm
  2. chex.com

Chapter Z: More Documentation

Appendix of System Calls for DOS

  1. (Table 01680) Values for DOS extended error code: —-DOS 2.0+ —- 00h (0) no error 01h (1) function number invalid 02h (2) file not found 03h (3) path not found 04h (4) too many open files (no handles available) 05h (5) access denied 06h (6) invalid handle 07h (7) memory control block destroyed 08h (8) insufficient memory 09h (9) memory block address invalid 0Ah (10) environment invalid (usually >32K in length) 0Bh (11) format invalid 0Ch (12) access code invalid 0Dh (13) data invalid 0Eh (14) reserved 0Eh (14) (PTS-DOS 6.51+, S/DOS 1.0+) fixup overflow 0Fh (15) invalid drive 10h (16) attempted to remove current directory 11h (17) not same device 12h (18) no more files —-DOS 3.0+ (INT 24 errors)—- 13h (19) disk write-protected 14h (20) unknown unit 15h (21) drive not ready 16h (22) unknown command 17h (23) data error (CRC) 18h (24) bad request structure length 19h (25) seek error 1Ah (26) unknown media type (non-DOS disk) 1Bh (27) sector not found 1Ch (28) printer out of paper 1Dh (29) write fault 1Eh (30) read fault 1Fh (31) general failure 20h (32) sharing violation 21h (33) lock violation 22h (34) disk change invalid (ES:DI -> media ID structure)(see #01681) 23h (35) FCB unavailable 23h (35) (PTS-DOS 6.51+, S/DOS 1.0+) bad FAT 24h (36) sharing buffer overflow 25h (37) (DOS 4.0+) code page mismatch 26h (38) (DOS 4.0+) cannot complete file operation (EOF / out of input) 27h (39) (DOS 4.0+) insufficient disk space 28h-31h reserved —-OEM network errors (INT 24)—- 32h (50) network request not supported 33h (51) remote computer not listening 34h (52) duplicate name on network 35h (53) network name not found 36h (54) network busy 37h (55) network device no longer exists 38h (56) network BIOS command limit exceeded 39h (57) network adapter hardware error 3Ah (58) incorrect response from network 3Bh (59) unexpected network error 3Ch (60) incompatible remote adapter 3Dh (61) print queue full 3Eh (62) queue not full 3Fh (63) not enough space to print file 40h (64) network name was deleted 41h (65) network: Access denied (DOS 3.0+ [maybe 3.3+???]) codepage switching not possible (see also INT 21/AX=6602h,INT 2F/AX=AD42h) 42h (66) network device type incorrect 43h (67) network name not found 44h (68) network name limit exceeded 45h (69) network BIOS session limit exceeded 46h (70) temporarily paused 47h (71) network request not accepted 48h (72) network print/disk redirection paused 49h (73) network software not installed (LANtastic) invalid network version 4Ah (74) unexpected adapter close (LANtastic) account expired 4Bh (75) (LANtastic) password expired 4Ch (76) (LANtastic) login attempt invalid at this time 4Dh (77) (LANtastic v3+) disk limit exceeded on network node 4Eh (78) (LANtastic v3+) not logged in to network node 4Fh (79) reserved —-end of errors reportable via INT 24—- 50h (80) file exists 51h (81) (undoc) duplicated FCB 52h (82) cannot make directory 53h (83) fail on INT 24h —-network-related errors (non-INT 24)—- 54h (84) (DOS 3.3+) too many redirections / out of structures 55h (85) (DOS 3.3+) duplicate redirection / already assigned 56h (86) (DOS 3.3+) invalid password 57h (87) (DOS 3.3+) invalid parameter 58h (88) (DOS 3.3+) network write fault 59h (89) (DOS 4.0+) function not supported on network / no process slots available 5Ah (90) (DOS 4.0+) required system component not installed / not frozen 5Bh (91) (DOS 4.0+,NetWare4) timer server table overflowed 5Ch (92) (DOS 4.0+,NetWare4) duplicate in timer service table 5Dh (93) (DOS 4.0+,NetWare4) no items to work on 5Fh (95) (DOS 4.0+,NetWare4) interrupted / invalid system call 64h (100) (MSCDEX) unknown error 64h (100) (DOS 4.0+,NetWare4) open semaphore limit exceeded 65h (101) (MSCDEX) not ready 65h (101) (DOS 4.0+,NetWare4) exclusive semaphore is already owned 66h (102) (MSCDEX) EMS memory no longer valid 66h (102) (DOS 4.0+,NetWare4) semaphore was set when close attempted 67h (103) (MSCDEX) not High Sierra or ISO-9660 format 67h (103) (DOS 4.0+,NetWare4) too many exclusive semaphore requests 68h (104) (MSCDEX) door open 68h (104) (DOS 4.0+,NetWare4) operation invalid from interrupt handler 69h (105) (DOS 4.0+,NetWare4) semaphore owner died 6Ah (106) (DOS 4.0+,NetWare4) semaphore limit exceeded 6Bh (107) (DOS 4.0+,NetWare4) insert drive B: disk into A: / disk changed 6Ch (108) (DOS 4.0+,NetWare4) drive locked by another process 6Dh (109) (DOS 4.0+,NetWare4) broken pipe 6Eh (110) (DOS 5.0+,NetWare4) pipe open/create failed 6Fh (111) (DOS 5.0+,NetWare4) pipe buffer overflowed 70h (112) (DOS 5.0+,NetWare4) disk full 71h (113) (DOS 5.0+,NetWare4) no more search handles 72h (114) (DOS 5.0+,NetWare4) invalid target handle for dup2 73h (115) (DOS 5.0+,NetWare4) bad user virtual address / protection violation 74h (116) (DOS 5.0+) VIOKBD request 74h (116) (NetWare4) error on console I/O 75h (117) (DOS 5.0+,NetWare4) unknown category code for IOCTL 76h (118) (DOS 5.0+,NetWare4) invalid value for verify flag 77h (119) (DOS 5.0+,NetWare4) level four driver not found by DOS IOCTL 78h (120) (DOS 5.0+,NetWare4) invalid / unimplemented function number 79h (121) (DOS 5.0+,NetWare4) semaphore timeout 7Ah (122) (DOS 5.0+,NetWare4) buffer too small to hold return data 7Bh (123) (DOS 5.0+,NetWare4) invalid character or bad file-system name 7Ch (124) (DOS 5.0+,NetWare4) unimplemented information level 7Dh (125) (DOS 5.0+,NetWare4) no volume label found 7Eh (126) (DOS 5.0+,NetWare4) module handle not found 7Fh (127) (DOS 5.0+,NetWare4) procedure address not found 80h (128) (DOS 5.0+,NetWare4) CWait found no children 81h (129) (DOS 5.0+,NetWare4) CWait children still running 82h (130) (DOS 5.0+,NetWare4) invalid operation for direct disk-access handle 83h (131) (DOS 5.0+,NetWare4) attempted seek to negative offset 84h (132) (DOS 5.0+,NetWare4) attempted to seek on device or pipe —-JOIN/SUBST errors—- 85h (133) (DOS 5.0+,NetWare4) drive already has JOINed drives 86h (134) (DOS 5.0+,NetWare4) drive is already JOINed 87h (135) (DOS 5.0+,NetWare4) drive is already SUBSTed 88h (136) (DOS 5.0+,NetWare4) can not delete drive which is not JOINed 89h (137) (DOS 5.0+,NetWare4) can not delete drive which is not SUBSTed 8Ah (138) (DOS 5.0+,NetWare4) can not JOIN to a JOINed drive 8Bh (139) (DOS 5.0+,NetWare4) can not SUBST to a SUBSTed drive 8Ch (140) (DOS 5.0+,NetWare4) can not JOIN to a SUBSTed drive 8Dh (141) (DOS 5.0+,NetWare4) can not SUBST to a JOINed drive 8Eh (142) (DOS 5.0+,NetWare4) drive is busy 8Fh (143) (DOS 5.0+,NetWare4) can not JOIN/SUBST to same drive 90h (144) (DOS 5.0+,NetWare4) directory must not be root directory 91h (145) (DOS 5.0+,NetWare4) can only JOIN to empty directory 92h (146) (DOS 5.0+,NetWare4) path is already in use for SUBST 93h (147) (DOS 5.0+,NetWare4) path is already in use for JOIN 94h (148) (DOS 5.0+,NetWare4) path is in use by another process 95h (149) (DOS 5.0+,NetWare4) directory previously SUBSTituted 96h (150) (DOS 5.0+,NetWare4) system trace error 97h (151) (DOS 5.0+,NetWare4) invalid event count for DosMuxSemWait 98h (152) (DOS 5.0+,NetWare4) too many waiting on mutex 99h (153) (DOS 5.0+,NetWare4) invalid list format 9Ah (154) (DOS 5.0+,NetWare4) volume label too large 9Bh (155) (DOS 5.0+,NetWare4) unable to create another TCB 9Ch (156) (DOS 5.0+,NetWare4) signal refused 9Dh (157) (DOS 5.0+,NetWare4) segment discarded 9Eh (158) (DOS 5.0+,NetWare4) segment not locked 9Fh (159) (DOS 5.0+,NetWare4) invalid thread-ID address

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

Now, this is technically risky for us, since you'll have the book or course files either way. But we're so confident in our products and services, and in our authors and readers, that we're happy to offer a full money back guarantee for everything we sell.

You can only find out how good something is by trying it, and because of our 100% money back guarantee there's literally no risk to do so!

So, there's no reason not to click the Add to Cart button, is there?

See full terms...

Earn $8 on a $10 Purchase, and $16 on a $20 Purchase

We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

In fact, authors have earned over $15 million writing, publishing and selling on Leanpub.

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub