0

alright, so I just tried to write a hello world program for windows. I took a course on 16 bit assembly on one of those old machines, but I've never written a piece of assembly code on a new machine.

this is my attempt taken directly from tutorials_point:

section .text
global _start     ;must be declared for linker (ld)

_start:             ;tells linker entry point
   mov  edx,len     ;message length
   mov  ecx,msg     ;message to write
   mov  ebx,1       ;file descriptor (stdout)
   mov  eax,4       ;system call number (sys_write)
   int  0x80        ;call kernel

   mov  eax,1       ;system call number (sys_exit)
   int  0x80        ;call kernel

section .data
msg db 'Hello, world!', 0xa  ;string to be printed
len equ $ - msg     ;length of the string

to my understanding this outputs hello world to stdout by invoking an interrupt. I used nasm on cmd:

nasm -f elf file.asm
ld -m i386pe -s -o file.exe file.o

I guess that I need to create an exe file differently, since this was originally meant to run on linux. if so, please correct my mistake.

blahh
  • 47
  • 12
  • 2
    You need to find a tutorial for Windows... the code you have is for 32-bit Linux and the code is entirely different. – Michael Petch Feb 19 '20 at 03:50
  • 1
    You're using specific Linux systems calls that don't exist on Windows (or old DOS) platforms. – Ken White Feb 19 '20 at 03:51
  • @KenWhite : The executable being generated is a PE file. THe intermediate objects they created were ELF but it appears the version of LD they are using supports combining ELF and COFF files and output to a Win PE executable format. I believe the MinGW LD supports using both. Of course I would have used `-f win32` instead of ELF myself. – Michael Petch Feb 19 '20 at 03:56
  • 1
    If you want to write a 32-bit Windows application then this question is probably more or less a duplicate of this question from what I can tell: https://stackoverflow.com/q/12574924/3857942 – Michael Petch Feb 19 '20 at 04:03
  • 1
    If you are attempting this in WSL, WSL doesn't support 32-bit assembly either. – David C. Rankin Feb 19 '20 at 04:12

0 Answers0