Page 1 of 1

the compatibility between bochs and masm

Posted: Mon Jun 01, 2009 7:04 am
by david
I don't think bochs could run 32-bit masm routiue(compiled by masm). but 16-bit masm program is ok.

32-bit masm code:

Code: Select all

	.386P
TEXT segment para use32 public 'CODE'
	assume cs:TEXT, ds:nothing, es:nothing, ss:nothing
Start:
	xor ax, ax
	xor bx, bx
	
	push 07C0h
	push @F
	retf
@@:
	mov ax, cs
	mov ds, ax
	mov es, ax
TEXT ends
	End Start
then, compile and link it by masm.

but use bochs to debug it, the disassembling code is :

Code: Select all

<bochs:3> u /10
00007c00: (                    ): xor eax, eax              ; 6633c0
00007c03: (                    ): xor ebx, ebx              ; 6633db
00007c06: (                    ): push 0x07c0               ; 68c007
00007c09: (                    ): add byte ptr ds:[bx+si], al ; 0000
00007c0b: (                    ): push 0x0011               ; 681100
00007c0e: (                    ): add byte ptr ds:[bx+si], al ; 0000
00007c10: (                    ): retf                      ; cb
00007c11: (                    ): mov ax, cs                ; 668cc8
00007c14: (                    ): mov ds, ax                ; 668ed8
00007c17: (                    ): mov es, ax                ; 668ec0
they are wrong, why?

bochs can't support 32-bit masm routine?

I change use32 to use16, it will be ok.

Re: the compatibility between bochs and masm

Posted: Mon Jun 01, 2009 7:14 am
by NickJohnson
Are you in protected mode? 32-bit code won't work very well in real mode...

Re: the compatibility between bochs and masm

Posted: Mon Jun 01, 2009 7:16 am
by neon
masm and bochs have nothing to do with each other. I am suspecting something else is at fault.

Re: the compatibility between bochs and masm

Posted: Mon Jun 01, 2009 7:24 am
by david
My code is in real-address mode.

but bochs also has the same problem in protected-mode.

I tested it before.

Re: the compatibility between bochs and masm

Posted: Mon Jun 01, 2009 7:33 am
by Brendan
Hi,

You show some initial boot loader code (which suggests to me that you haven't gone much further than initial boot loader code); and make the mistake of thinking that 32-bit code will run in real mode (and assume it's Boch's fault that the disassembly is messed up when it's disassembling 32-bit code as 16-bit code because of your mistake); and then you expect us to believe that 2 different products (MASM and Bochs) that have been used successfully by lots of people for many years don't work?
david wrote:but bochs also has the same problem in protected-mode.

I tested it before.
Not likely...


Cheers,

Brendan

Re: the compatibility between bochs and masm

Posted: Mon Jun 01, 2009 8:04 am
by ru2aqare
david wrote: they are wrong, why?
Because you told masm to emit code that assumes the processor uses 32-bit operands by default. Changing 'use32' to 'use16' emits code that assumes the processor uses 16-bit operands by default.

However if you load the aforementioned code into Bochs, the Bochs CPU is still in real mode, hence it will assume 16-bit operands, and disassemble/interpret your code the wrong way. If you change Bochs into protected mode, it will disassemble your code correctly.

This means that there is no incompatibility or such between the two software. The expected CPU modes were different, and you were using the programs the wrong way.

Re: the compatibility between bochs and masm

Posted: Mon Jun 01, 2009 8:41 am
by david
hey, guys

Thank you for answer my question, In fact I met this problem when i debug some code in protected-mode written by MASM and VC. But i don't want to show you all my code. Because I think you will understand it hardly.(reason: less comments, more functions, etc). I met this question two or three months ago, but I have to resolve it now. Luckly, I found the same problem in real-address mode(the code I show you), so I show you the boot code to look for help. The code is so easy.

Perhaps you are right, I will debug my code seriously tomorrow.

Good night.

Re: the compatibility between bochs and masm

Posted: Mon Jun 01, 2009 10:37 am
by neon
It may also help posting the version of MASM and Bochs that you are using.

Re: the compatibility between bochs and masm

Posted: Mon Jun 01, 2009 9:10 pm
by david
MASM: Microsoft (R) Macro Assembler Version 6.15.8803

Bochs: Bochs 2.3.5

Re: the compatibility between bochs and masm

Posted: Mon Jun 01, 2009 9:44 pm
by neon
Try using the newest bochs version (relivant thread)

Re: the compatibility between bochs and masm

Posted: Mon Jun 01, 2009 10:07 pm
by david
It is OK now! :D
I set D/B=1(D/B in segment descriptor) in my code, data and stack segment descriptor.Then, OK.
D/B=0 before i change it.