x86 assembly language for MS-DOS: Hello, world
Вставка
- Опубліковано 4 бер 2022
- I do a demonstration on how to get started programming in x86 assembly language for the MS-DOS operating system using NASM and DOSBox-X. We write a "hello, world" program, assemble and run it, and then disassemble and analyze the executable COM file.
NASM: nasm.us/
DOSBox: www.dosbox.com/
DOSBox-X: dosbox-x.com/
Intel 8086 CPU user manual: edge.edx.org/c4x/BITSPilani/E... - Наука та технологія
You made all that sound quite straight forward and approachable which is saying something when you're introducing assembly!
3:55 DOSBox-X does make a better job at emulating the machine and DOS environment than DOSBox without the x will do. The development scope of the latter is mainly for running games, thus its goal is not 100 % compatibility. DOSBox-X's goal is to try and achieve 100 % compatibility, thus more exotic DOS software will run on DOSBox-X than on DOSbox. And this is important for assembly programming.
Just found your channel and I'm really enjoying these!
Hint: We can also terminate a DOS based COM-programm with a "ret" instruction, if we do not corrupt the stack and the code segment. Because DOS place the instruction of an "int 20h" at the top of the PSP and it pushes a zero word to the stack just before it let the programm execute. If we execute at last the "ret" instruction, then the cpu return to the address of zero and continue executing the instruction of the "int 20h" inside of the PSP for terminating our programm.
But the default practice for terminating a DOS programm is to use the DOS function: AH=4Ch, AL=(DOS "ERRORLEVEL") of the int 21h.
Wouldn't there still be a RET after the 4C dos call?
@@SolarLantern424 I don`t know.
@@SolarLantern424 Why would there be? If DOS never returns control to the COM program after 4Ch, then nothing after that would ever get executed anyway. (Which is why the literal string at 010c doesn't get interpreted as code.)
@@nickwallette6201 So will the address for a RET stay on the stack in that situation?
@@SolarLantern424 The executing environment would get torn down by DOS, and all of that memory reused for something else (another executed program, e.g.)
That was great, thank you!
It's been a few decades since I last worked with COM files. This was a nice refresher. I was not aware of DOSBox-X, so it was to be able to recreate a real mode DOS environment.
BTW Since you're already using NASM, why not use the built in disassembler ndisasm in favor of hexdump?
I think hexdump is nice for demonstrating to newcomers that the assembled file is merely instructions in the form of binary data.
You're right, though. ndisasm is a more convenient tool. I actually didn't know about it at the time I made this video. I use NASM extensively in my current project, a real mode operating system: ua-cam.com/video/BX-DA1AY5tQ/v-deo.html&pp=gAQBiAQB
I do use ndisasm to support that work.
If i remember correctly one can generate COM files with the DOS debugger, too. No need for an assembler 😊
Nice vid
好懷念的 mov ah, 4ch; int 21h
Hi bro, I have a question that I would like you to answer if it’s possible
Look, I have like a test in a course where I’m using assembly, my professor ask to make that throw assembly receive the data in a serial port y show what’s sent in the console. Do you know if it’s possible to do it using dosbox and the same logic that you used in this video?
PD: English is not my main language, sorry if I have some grammar mistakes, but hope it’s understandable.
DOSBox has support for emulating serial ports. If it's complete enough, you should be able to use it.
Enabling it: www.dosbox.com/DOSBoxManual.html
Programming it (C code. You have to translate to assembly): wiki.osdev.org/Serial_Ports#Programming_the_Serial_Communications_Port
But if you have the option to write assembly on an x86 GNU/Linux computer, I'd recommend doing that instead. If you want to emulate, you could use Linux in the QEMU emulator, which emulates a serial port and can bind to a device or file on the host machine.
(search for serial) www.qemu.org/docs/master/system/invocation.html#hxtool-6
If you have any other questions, I'll try to help you.
I want to write an OS that sits atop MS-DOS that runs on ELF, similar to how Windows 3 uses NE.
Lol.
We have the well known example of the "Hello World!" program. This was first run over 40 years ago on real IBM PC hardware and also run on many PC compatible computers. This was practically the simplest program that could be written for MS-DOS. Now unless we have a historic restored IBM PC or PC compatible computer we have to run it on a DOS emulator.
Well, who _doesn't_ have a 5150 hanging around? :-D
No need to go that far back. A few days ago I booted Intel 6th generation machine to DOS from 3,5" floppy.
@@jussiala-konni288 It is amazing that after all these years that there are some Intel PCs that can still boot up the MS-DOS operating system.
excelent video, i have a question, is there a form to read and write file through with AH=3F and AH=40??? is possible a video with this information? and the function to seek a specified position in a file "seek" wich is the AH=42? all interrupt 21. thank very much.
Thanks for watching! I'm planning a future video for I/O, but I'm not sure when. In the meantime, here are my favorite DOS interrupt references. I think they both have very good sections on the 3Fh,40h,42h file functions.
www.techhelpmanual.com/5-dos_function_index___quick_reference_subset.html
flint.cs.yale.edu/cs422/doc/art-of-asm/pdf/CH13.PDF
@@chillruns6221 is very interesting. thank very much, already reading it
I am on an Android tablet with the Magic Dosbox Free app installed from the play store.
I tryied to post a new comment, but it is deleted in seconds.