0

I decided to learn assembly today, because it seemed like it's a pretty powerfull tool, but I didn't know where to start learning it, so I googled it and found this: https://www.tutorialspoint.com/assembly_programming

It told me to install NASM and MinGW for compiling and linking, so I downloaded and installed it and made sure that both of them are working properly.

I copied the given code

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

and pasted it into an empty document called "hello.asm" and compiled it by writing

nasm -f elf hello.asm
(later nasm -f win32 hello.asm)

and afterwards

ld hello.o -o hello.exe
(later ld hello.obj -o hello.exe)

and it successfully created a .exe file both times , but when I tried to execute it, it only opened the windows command prompt and a new window opened that said "hello.exe doesn't work anymore".

I know this won't output anything, but shouldn't it at least run ?

What did I do wrong ?

Using:

  • Windows 7 professional 64bit
  • AMD FX 4350
  • nasm-2.12.02
  • MinGW
Hans Wuast
  • 55
  • 6

1 Answers1

0

You're going to need a different tutorial, as user tkausl pointed out this tutorial is for Linux x86_64 bit.

For windows, you can still use the NASM assembler and MinGW if you wish, but your code is going to look different because of the different calls and will also require you to use external libraries.

I recommend using the MASM for Windows however, as it is designed by Microsoft, and also included in the MASM32v8 package which has other tools. You can get MASM from here: http://www.masm32.com/

There is also a tutorial for Windows Assembly: https://www-s.acm.illinois.edu/sigwin/old/workshops/winasmtut.pdf

However, if you are intent on using the NASM assembler, then you can refer to the answer posted by caffiend here: How to write hello world in assembler under Windows?

Community
  • 1
  • 1