Author Topic: Assembler for windows?  (Read 7738 times)

nobody

  • Guest
Assembler for windows?
« on: January 20, 2009, 07:07:32 PM »
I found this code
Code: [Select]
; For Windows:
; nasm -f win32 --prefix _ -o prime.obj prime.asm
; gcc -o prime.exe prime.obj
;
; For Linux:
; nasm -f elf32 -o prime.o prime.asm
; gcc -o prime prime.o

section .data
msg: db 'Enter an integer: ', 0
chr: db '%d', 0
ispmsg: db 10, 'The integer %d is prime!', 10, 0
nopmsg: db 10, 'The integer %d is not prime.', 10, 0

section .text
global main
extern printf, scanf

main:

push ebp
mov ebp, esp
sub esp, $0c

mov dword [ebp-8], 1
push msg
call printf
add esp, 4

lea eax, [ebp-4]
push eax
push chr
call scanf
add esp, 8

cmp dword [ebp-4], 2
jge next
mov dword [ebp-8], 0
jmp continue

next:
jne nextt
jmp continue

nextt:
mov eax, [ebp-4]
cdq
mov ebx, 2
idiv ebx
cmp edx, 0
je nexttt

finit
fild dword [ebp-4]
fsqrt
fistp dword [ebp-$0c]

mov ecx, 3
jmp ccheck
floop:
mov eax, [ebp-4]
cdq
idiv ecx
cmp edx, 0
jne check
mov dword [ebp-8], 0
jmp continue
check:
add ecx, 2
ccheck:
cmp ecx, [ebp-$0c]
jle floop
jmp continue

nexttt:
mov dword [ebp-8], 0

continue:
xor eax, eax
cmp eax, [ebp-8]
jne isprime
mov eax, [ebp-4]
push eax
push nopmsg
call printf
add esp, 8
jmp endit

isprime:
mov eax, [ebp-4]
push eax
push ispmsg
call printf
add esp, 8

endit:
add esp, $0c
pop ebp
xor eax, eax
ret

using command prompt I did "nasm -f win32 --prefix _ -o prime.obj prime.asm" and I got a file prime.obj

what do i o now?

How do I convert the .obj file to a .exe file?
Does gcc work on windows? where do I get it?

nobody

  • Guest
Re: Assembler for windows?
« Reply #1 on: January 20, 2009, 09:35:41 PM »
help please?

nobody

  • Guest
Re: Assembler for windows?
« Reply #2 on: January 20, 2009, 10:19:01 PM »
No, you have to install Linux. :)

Just kidding. You can get gcc (etc.) for Windows here:

http://mingw.org/

Never used it. You can also get "Cygwin" - a more complete Unix(ish) environment for 'doze (ran slow as crap on my machine).

But... if you've got any C compiler installed, you "should" be able to use it with the "usual" command line. Note that there's no C to actually compile - the compiler's job in this case is "merely" to invoke the linker with the proper command line. I could tell you this for Linux, but not for Windows - better let gcc or other compiler do it!

If you try this and have trouble, post the error message(s)... maybe we can help you figure it out...

Best,
Frank

nobody

  • Guest
Re: Assembler for windows?
« Reply #3 on: January 20, 2009, 11:44:09 PM »
Thanks Frank,

I'll be installing cygwin (because i've heard a lot about it recently)

I'll soon inform you on the process.