I noticed this simple x86 Intel Assembly program only compiles and runs on the NASM Assembler in Linux. I was curious regarding if I am able to compile a Windows Assembly program, using the MASM syntax, on Linux. (in NASM) If not, I would be curious about what limitations, or differences there are between the NASM and MASM syntax.
I am now aware of the differences between the two stated in the NASM documentation. (Available at http://www.nasm.us/doc/nasmdoc2.html#section-2.2) However, I am still confused in regards to the system interrupts on Windows. For example, Does Windows require the interrupts to be called in a different manner than Unix-based operating systems?
Finally, I need to know if there is a more efficient way to achieve the same result.
HelloWorld Assembly Program:
section .data ;Constant Data Section
userMsg db 'What is your name?' ;Request Name Input
lengthMsg equ $-userMsg ;Set length of request
returnMsg db 'Hello there, ' ;Return Message
lengthRet equ $-returnMsg ;Set length of returned message
section .bss
number resb 5
section .text
global _start
_start:
mov eax, 4 ;Print first message to screen
mov ebx, 1
mov ecx, userMsg
mov edx, lengthMsg
int 80h
mov eax, 3
mov ebx, 2
mov ecx, number
mov edx, 5
int 80h
mov eax, 4
mov ebx, 1
mov ecx, returnMsg
mov edx, lengthRet
int 80h
mov eax, 4
mov ebx, 1
mov ecx, number
mov edx, 5
int 80h
mov eax, 1
mov ebx, 0
int 80h
These are the errors displayed when assembling the file.
Microsoft (R) Macro Assembler Version 6.14.8444
Copyright (C) Microsoft Corp 1981-1997. All rights reserved.
Assembling: C:\Projects\theapp.asm
C:\Projects\theapp.asm(1) : error A2008: syntax error : section
C:\Projects\theapp.asm(2) : error A2034: must be in segment block
C:\Projects\theapp.asm(3) : error A2034: must be in segment block
C:\Projects\theapp.asm(5) : error A2034: must be in segment block
C:\Projects\theapp.asm(6) : error A2034: must be in segment block
C:\Projects\theapp.asm(8) : error A2008: syntax error : section
C:\Projects\theapp.asm(9) : error A2008: syntax error : number
C:\Projects\theapp.asm(11) : error A2008: syntax error : section
C:\Projects\theapp.asm(12) : error A2008: syntax error : global
C:\Projects\theapp.asm(15) : error A2034: must be in segment block
C:\Projects\theapp.asm(16) : error A2085: instruction or register not accepted in current CPU mode
C:\Projects\theapp.asm(17) : error A2085: instruction or register not accepted in current CPU mode
C:\Projects\theapp.asm(18) : error A2085: instruction or register not accepted in current CPU mode
C:\Projects\theapp.asm(19) : error A2085: instruction or register not accepted in current CPU mode
C:\Projects\theapp.asm(20) : error A2034: must be in segment block
C:\Projects\theapp.asm(22) : error A2085: instruction or register not accepted in current CPU mode
C:\Projects\theapp.asm(23) : error A2085: instruction or register not accepted in current CPU mode
C:\Projects\theapp.asm(24) : error A2085: instruction or register not accepted in current CPU mode
C:\Projects\theapp.asm(25) : error A2085: instruction or register not accepted in current CPU mode
C:\Projects\theapp.asm(26) : error A2034: must be in segment block
C:\Projects\theapp.asm(28) : error A2085: instruction or register not accepted in current CPU mode
C:\Projects\theapp.asm(29) : error A2085: instruction or register not accepted in current CPU mode
C:\Projects\theapp.asm(30) : error A2085: instruction or register not accepted in current CPU mode
C:\Projects\theapp.asm(31) : error A2085: instruction or register not accepted in current CPU mode
C:\Projects\theapp.asm(32) : error A2034: must be in segment block
C:\Projects\theapp.asm(34) : error A2085: instruction or register not accepted in current CPU mode
C:\Projects\theapp.asm(35) : error A2085: instruction or register not accepted in current CPU mode
C:\Projects\theapp.asm(36) : error A2085: instruction or register not accepted in current CPU mode
C:\Projects\theapp.asm(37) : error A2085: instruction or register not accepted in current CPU mode
C:\Projects\theapp.asm(38) : error A2034: must be in segment block
C:\Projects\theapp.asm(40) : error A2085: instruction or register not accepted in current CPU mode
C:\Projects\theapp.asm(41) : error A2085: instruction or register not accepted in current CPU mode
C:\Projects\theapp.asm(42) : error A2034: must be in segment block
C:\Projects\theapp.asm(45) : error A2088: END directive required at end of file
_
Assembly Error
Press any key to continue . . .
int 80h
system calls and numbers) and wouldn't work with Windows even if you had managed to assemble it. The online link you are using is also using NASM and is running on a Linux backend so that is why that works. – Michael Petch