{"id":28146848,"url":"https://github.com/susam/hello","last_synced_at":"2025-05-14T23:15:51.910Z","repository":{"id":62334635,"uuid":"559588371","full_name":"susam/hello","owner":"susam","description":"A 23-byte “hello, world” program assembled with DEBUG.EXE in MS-DOS","archived":false,"fork":false,"pushed_at":"2022-11-16T22:28:14.000Z","size":25,"stargazers_count":139,"open_issues_count":0,"forks_count":4,"subscribers_count":5,"default_branch":"main","last_synced_at":"2023-11-07T19:46:25.492Z","etag":null,"topics":["asm","dos","hello-world","ms-dos","x86"],"latest_commit_sha":null,"homepage":"","language":"Assembly","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/susam.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGES.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-10-30T15:28:02.000Z","updated_at":"2023-10-23T11:11:49.000Z","dependencies_parsed_at":"2022-10-31T00:45:47.309Z","dependency_job_id":null,"html_url":"https://github.com/susam/hello","commit_stats":null,"previous_names":[],"tags_count":0,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/susam%2Fhello","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/susam%2Fhello/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/susam%2Fhello/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/susam%2Fhello/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/susam","download_url":"https://codeload.github.com/susam/hello/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254243313,"owners_count":22038048,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["asm","dos","hello-world","ms-dos","x86"],"created_at":"2025-05-14T23:14:44.909Z","updated_at":"2025-05-14T23:15:51.901Z","avatar_url":"https://github.com/susam.png","language":"Assembly","funding_links":[],"categories":[],"sub_categories":[],"readme":"Programming \"Hello, World\" in MS-DOS\n====================================\n\nThe program `HELLO.COM` was developed on MS-DOS Version 6.22 using the\nDOS program named `DEBUG.EXE`. It is exactly 23 bytes in length. It\ncan be used to print the string \"hello, world\" followed by newline to\nstandard output.\n\n\nAssemble\n--------\n\nHere is the complete `DEBUG.EXE` session that creates a \"hello, world\"\nprogram:\n\n```\nC:\\\u003edebug\n-A\n1165:0100 MOV AH, 9\n1165:0102 MOV DX, 108\n1165:0105 INT 21\n1165:0107 RET\n1165:0108 DB 'hello, world', D, A, '$'\n1165:0117\n-G\nhello, world\n\nProgram terminated normally\n-N HELLO.COM\n-R CX\nCX 0000\n:17\n-W\nWriting 00017 bytes\n-Q\n\nC:\\\u003eHELLO\nhello, world\n\nC:\\\u003e\n```\n\nNote that the `N` (name) command specifies the name of the file where\nwe write the binary machine code to. Also, note that the `W` (write)\ncommand expects the registers BX and CX to contain the number of bytes\nto be written to the file. When `DEBUG.EXE` starts, BX is already\ninitialized to 0, so we only set the register CX to 17 (decimal 23)\nwith the `R CX` command above.\n\nThe debugger session inputs are archived in the file named\n`HELLO.TXT`, so the binary file named `HELLO.COM` can also be created\nby running the following DOS command:\n\n```\nDEBUG \u003c HELLO.TXT\n```\n\nThe binary executable file can be created on a Unix or Linux system\nusing the `printf` command as follows:\n\n```\necho B4 09 BA 08 01 CD 21 C3 68 65 6C 6C 6F 2C 20 77 6F 72 6C 64 0D 0A 24 | xxd -r -p \u003e HELLO.COM\n```\n\n\nUnassemble\n----------\n\nHere is a disassembly of `HELLO.COM` to confirm that it has been\nwritten correctly:\n\n```\nC:\\\u003eDEBUG\n-N HELLO.COM\n-L\n-U 100 116\n117C:0100 B409          MOV     AH,09\n117C:0102 BA0801        MOV     DX,0108\n117C:0105 CD21          INT     21\n117C:0107 C3            RET\n117C:0108 68            DB      68\n117C:0109 65            DB      65\n117C:010A 6C            DB      6C\n117C:010B 6C            DB      6C\n117C:010C 6F            DB      6F\n117C:010D 2C20          SUB     AL,20\n117C:010F 776F          JA      0180\n117C:0111 726C          JB      017F\n117C:0113 64            DB      64\n117C:0114 0D0A24        OR      AX,240A\n-D 100 116\n117C:0100  B4 09 BA 08 01 CD 21 C3-68 65 6C 6C 6F 2C 20 77   ......!.hello, w\n117C:0110  6F 72 6C 64 0D 0A 24                              orld..$\n```\n\n\nRun\n---\n\nTo run this program on MS-DOS, simply enter the following command at\nthe command prompt:\n\n```\nHELLO\n```\n\n\nINT 20 vs. RET\n--------------\n\nAnother way to terminate a .COM program is to simply use the\ninstruction `INT 20`. This consumes two bytes in the machine code: `CD\n20`.\n\nWhile producing the smallest possible executable is not the goal of\nthis project, this project indulges in a little bit of size reduction\nby using the `RET` instruction to terminate the program. This consumes\nonly one byte: `C3`. This works because when a .COM file starts, the\nregister SP contains FFFE. The stack memory locations at offset FFFE\nand FFFF contain 00 and 00, respectively. Further, the memory address\noffset 0000 contains the instruction `INT 20`.\n\n```\nC:\\\u003eDEBUG HELLO.COM\n-R SP\nSP FFFE\n:\n-D FFFE\n117C:FFF0                                            00 00\n-U 0 1\n117C:0000 CD20          INT     20\n```\n\nAs a result, executing the `RET` instruction pops 0000 off the stack\nat FFFE and loads it into IP. This results in the intstruction `INT\n20` at offset 0000 getting executed which leads to program\ntermination.\n\nWhile both `INT 20` and `RET` lead to successful program termination\nboth in DOS as well as while debugging with `DEBUG.EXE`, there is some\ndifference between them which affects the debugging experience.\nTerminating the program with `INT 20` allows us to run the program\nrepeatedly within the debugger by repeated applications of the `G`\ndebugger command. But when we terminate the program with `RET`, we\ncannot run the program repeatedly in this manner. The program runs and\nterminates successfully the first time we run it in the debugger but\nthe stack does not get reinitialized with zeros to prepare it for\nanother execution of the program within the debugger. Therefore when\nwe try to run the program the second time using the `G` command, the\nprogram does not terminate successfully. It hangs instead. It is\npossible to work around this by reinitializing the stack with the\ndebugger command `E FFFE 0 0` before running `G` again.\n\n\nLicense\n-------\n\nThis is free and open source software. You can use, copy, modify,\nmerge, publish, distribute, sublicense, and/or sell copies of it,\nunder the terms of the MIT License. See [LICENSE.md][L] for details.\n\nThis software is provided \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\nexpress or implied. See [LICENSE.md][L] for details.\n\n[L]: LICENSE.md\n\n\nMore\n----\n\nThe example presented in this document relies on `INT 21` which is a\nDOS service. See the [ALT](ALT) subdirectory for example programs that\ndo not rely on DOS services. These additional examples also show how\nto create boot sector programs that print \"hello, world\" on booting\nthe computer.\n\nThere is also a 5-byte reboot program available at\n[github.com/susam/reboot](https://github.com/susam/reboot).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsusam%2Fhello","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsusam%2Fhello","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsusam%2Fhello/lists"}