ASSEMBLY set up

Programming, for all ages and all languages.
Post Reply
hazique35
Posts: 6
Joined: Sun Mar 31, 2013 9:57 am

ASSEMBLY set up

Post by hazique35 »

Im having so much trouble trying to start using this. Im trying to use flat assembler. I know that DosBox can be used, but this is an emulator, and therfore I will not be working directly with the hardware. (correct me if i am wrong on this) So how the heck can I start coding with ASSEMBLY if I cant even run it? Im using Windows 7, on a 64 bit operating system. Ive looked this up all day but I cant find much. What do I have to do?

Thanks
User avatar
trinopoty
Member
Member
Posts: 87
Joined: Wed Feb 09, 2011 2:21 am
Location: Raipur, India

Re: ASSEMBLY

Post by trinopoty »

Assemble to a flat binary.
Copy it to the first sector of floppy.
Run it in Bochs/Virtualbox/VMware.
Always give a difficult task to a lazy person. He will find an easy way to do it.
hazique35
Posts: 6
Joined: Sun Mar 31, 2013 9:57 am

Re: ASSEMBLY set up

Post by hazique35 »

Thanks for the answer. I dont know how to assemble to a flat binary... Here is the code that I a trying to run:

Code: Select all

ORG 100h
USE16

mov ah, 09
mov dx, msg
int 21h

mov ah, 01
int 21h
mov ah, 4ch
int 21h

msg db 'Hello World', 0ah, '$'


Do I need to add any extra code? Sorry, Ive only started using ASSEMBLY now, Im more familiar with C++.
User avatar
bluemoon
Member
Member
Posts: 1761
Joined: Wed Dec 01, 2010 3:41 am
Location: Hong Kong

Re: ASSEMBLY set up

Post by bluemoon »

Look like you're call DOS services, and you mentioned DOSBOX, so I suppose you're learning assembly with DOS environment.
In that case, DOS only support loading .com or .exe (MZ) executable format file.

To generate an .com you may hand code an .ORG 100h to skip the PSP (as you already do), assemble as flat binary(you did it too) and rename it with .com extension.

You code looks well, so what's the problem, what do you expect to see and what's the observables?
User avatar
iansjack
Member
Member
Posts: 4706
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: ASSEMBLY set up

Post by iansjack »

As you are using 64-bit Windows you have no choice but to use an emulator. 16-bit programs are not supported under Windows 64-bit.
hazique35
Posts: 6
Joined: Sun Mar 31, 2013 9:57 am

Re: ASSEMBLY set up

Post by hazique35 »

So, sense I have to use the emulator, I wont actually be able to do anything with the hardware or can I still do some stuff?
Antti
Member
Member
Posts: 923
Joined: Thu Jul 05, 2012 5:12 am
Location: Finland

Re: ASSEMBLY set up

Post by Antti »

I just wrote you a sample code (NASM + LINK). This is a native 64-bit windows program. I am sure that this helps you to get started.

Code: Select all

Build instructions:

nasm.exe -o hello.obj -f win64 hello.asm
link.exe /OUT:hello.exe /ENTRY:start /SUBSYSTEM:WINDOWS hello.obj kernel32.lib user32.lib

Code: Select all

; Sample 64-bit Windows program

	global start
	extern MessageBoxW
	extern ExitProcess

	section .text

start:
	sub rsp, 32+8                    ; Alignment + shadow parameters

	mov rcx, 0                       ; hwnd = NULL
	lea rdx, [rel helloMessage]      ; lpText = helloMessage
	lea r8, [rel helloCaption]       ; lpCaption = helloCaption
	mov r9, 0                        ; uType = MB_OK
	call MessageBoxW

	mov rcx, 0                       ; uExitCode = 0
	call ExitProcess

.end:	jmp .end


	section .data

helloCaption: dw __utf16__ 'http://forum.osdev.org', 0x0000
helloMessage: dw __utf16__ 'Hello 64-bit Windows world!', 0x0000
Last edited by Antti on Sun Mar 31, 2013 12:23 pm, edited 1 time in total.
hazique35
Posts: 6
Joined: Sun Mar 31, 2013 9:57 am

Re: ASSEMBLY set up

Post by hazique35 »

thanks!
Post Reply