Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NASM tutorial uses int 80h, but this isn't working on Windows

I'm starting NASM Assembler after finishing FASM. I'm coding this in a Windows Operating System. My code reads:

section.data ;Constant
            msg:    db "Hello World!"
            msg_L:   equ $-msg  ; Current - msg1

section.bss ;Varialble

section.text ; Code
        global _WinMain@16 

_WinMain@16:
        mov eax,4
        mov ebx,1; Where to wrte it out. Terminal
        mov ecx, msg
        mov edx, msg_L
        int 80h

        mov eax, 1 ; EXIT COMMAND
        mov ebx,0 ; No Eror
        int 80h

To compile it and execute I use:

nasm -f win32 test.asm -o test.o
ld test.o -o test.exe  

I am currently following this video on tutorials on NASM. I changed the start to WIN32, but when I execute it, it just gets stuck and won't run... Any problems with this?

like image 672
amanuel2 Avatar asked Jul 08 '16 14:07

amanuel2


People also ask

What is Int 80H in assembly language?

INT is the assembly mnemonic for "interrupt". The code after it specifies the interrupt code. (80h/0x80 or 128 in decimal is the Unix System Call interrupt) When running in Real Mode (16-bit on a 32-bit chip), interrupts are handled by the BIOS.


1 Answers

You are trying to make a Linux system call (int 80h) on the Windows operating system.

This will not work. You need to call Windows API functions. For example, MessageBox will display a message box on the screen.

section .rdata   ; read-only Constant data
            msg:    db "Hello World!"
            msg_L:   equ $-msg  ; Current - msg1

section .text ; Code
        global _WinMain@16
        extern _MessageBoxA@16

_WinMain@16:
        ; Display a message box
        push 40h   ; information icon
        push 0
        push msg
        push 0
        call _MessageBoxA@16

        ; End the program
        xor eax, eax
        ret

Make sure that the book/tutorial you're reading is about Windows programming with NASM, not Linux programming!

like image 107
Cody Gray Avatar answered Sep 19 '22 04:09

Cody Gray