0

I'm writing "Hello,World" to console with DOS in FASM. But it's not working with x64.

I've tried to write program for x64 but it's not working, too.

Where is my fault?

It's my code:

format PE64

org  100h       


mov ax, cs
mov ds, ax
mov dx, msg     
mov ah, 9h        
int  21h         

mov  ah, 4c00h     
int  21h       

msg  db 'Hello, World!$'
  • 2
    `format PE64` makes a 64-bit windows program, no DOS program. In a indos program you can't call DOS interrupts like `int 21h` - it will crash. If you want to create a DOS COM program remove the `format PE64` and replace it with `USE16`. This will generate a DOS COM program. However on 64-bit Windows o can't run 16-bit DOS programs (you will get an error). You need to run DOS programs under a DOS emulator like DOSBox. On 32-bit windows you can run DOS programs. – Michael Petch Mar 30 '19 at 13:40
  • 2
    I think you also meant to use `mov ax, 4c00h` rather than `mov ah, 4c00h` – Michael Petch Mar 30 '19 at 13:41
  • Thanks but how can I use it without DOS program? If I change by computer to 32-bit(it's x86 -> x64->x32) if it work? And if isn't work how can I change it – TheFnafException Mar 30 '19 at 14:08
  • 1
    You'd have to install a 32-bit version of Windows to run 16-bit DOS programs. You can't run 16-bit DOS programs directly on 64-bit Windows. You can write PE32 and PE64 programs that run on 64-bit Windows but there you can't use DOS interrupts. You'd have to call the Windows API to output characters to the console. – Michael Petch Mar 30 '19 at 14:12
  • How can I do it? And can you give me manual of it please – TheFnafException Mar 30 '19 at 14:22
  • And can I use BIOS interrupt? – TheFnafException Mar 30 '19 at 14:24
  • 1
    No you can't use DOS or BIOS interrupts in a PE64 or PE32 program.They are only available in DOS programs, and as I said you can't run DOS programs in 64-bit windows without a DOS emulator like DOSBox. 64-bit Windows does not support running 16-bit code anymore in a 64-bit OS because of a design change to the 64-bit CPUs. – Michael Petch Mar 30 '19 at 14:26
  • This SO answer shows how you can use the Windows API to write directly to the command console using FASM: https://stackoverflow.com/a/2568311/3857942 . It generates a Win32 console program that can be run on 64-bit Windows or 32-bit Windows – Michael Petch Mar 30 '19 at 14:30
  • CAN you GIVE ME MANUAL WINAPI AND GIVE ME AN EXAMPLE? – TheFnafException Mar 30 '19 at 14:51
  • I ALREADY DID. I gave you the LINK to a Stackoveflow Answer that USES FASM to create a WIN32 (NOT DOS) program that outputs "Hello World" to the console. Did you try it? https://stackoverflow.com/a/2568311/3857942 . – Michael Petch Mar 30 '19 at 14:51
  • You can use a 16 bit MSDOS emulator. It's also possible to use Windows Virtual PC with MSDOS 6.22 installed, but I'm not sure where you can get the stuff to do this (try a web search). If you do manage to find what you need to do this, I recommend using a USB stick to transfer files to / from the virtual PC. You could also use a cd-rom burner program to transfer files to the Virtual PC, or use existing cd-rom's that have what you need to install into the virtual PC. – rcgldr Mar 30 '19 at 16:09
  • Ok, but if I will write with WINAPI then have there any difference between fasm and c++? Is there speed difference between languages? – TheFnafException Mar 31 '19 at 06:28

0 Answers0