The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: bluman on February 22, 2011, 03:53:10 PM

Title: Invalid instruction operans on mov-ing
Post by: bluman on February 22, 2011, 03:53:10 PM
Hello!
This is one of my first attempts to write asm code after a long time, but can't get rid of the error mentioned in the title from the following code: Error A2051 - Invalid instruction operands on lines 13 and 15.

.386
.Model Flat, StdCall

;Public
Public myProc

.Const
TextMem Equ 0B8000h

.Code
myProc Proc p1:DWord, p2:DWord
Mov Al, 65
Mov Byte Ptr [TextMem], Al
Mov Al, 07h
Mov Byte Ptr[TextMem+1], Al
myProc EndP

End


Thanks,
Paul Herman.
Title: Re: Invalid instruction operans on mov-ing
Post by: redskull on February 22, 2011, 04:13:37 PM
You need segment overrides, e.g.

Mov Byte Ptr DS:[TextMem], Al

Note, however, that this code won't work how you want it to, and that the B800 method of accessing video memory won't work unless you are in DOS.

-r
Title: Re: Invalid instruction operans on mov-ing
Post by: dedndave on February 22, 2011, 04:22:09 PM
i think it works in console mode, which isn't really DOS   :P

a few notes:
1) EQUates need not be in a section - they are assembler directives and do not create data or code
2) PROC's are public by default - to make it private, SomeProc PROC PRIVATE
3) use EXTERNDEF to make data public
4) as Red mentioned, you need a segment override - but you do not need BYTE PTR if using AL - it can only be a byte
5) you do not need to put the value in AL first, it can be immediate - then you do need BYTE PTR   :P
6) it could be a single MOV using WORD PTR
7) 0B800h is a segment - not an offset
Title: Re: Invalid instruction operans on mov-ing
Post by: bluman on February 22, 2011, 04:26:38 PM
I don't think I can define 0B8000 as a segment, as this is part of an OS. I'm actually using jwASM to assemble it in order not to create conflicts with MASM license. How do I make it work this way?
Title: Re: Invalid instruction operans on mov-ing
Post by: dedndave on February 22, 2011, 04:31:59 PM
well - in 16-bit mode, you can get 0B800h into ES and do it that way
in protected mode (32-bit) - not really sure how to do it - lol
i would probably go to OSDev.org and find out   :bg
i think you have to get the buffer segment into the GDT, somehow

http://forum.osdev.org/
http://wiki.osdev.org/Main_Page
Title: Re: Invalid instruction operans on mov-ing
Post by: bluman on February 22, 2011, 04:34:58 PM
Lol, a simple Mov Byte Ptr DS:[TextMem], 65 works. Didn't believe this would do.

Thank you very much for the help.
Title: Re: Invalid instruction operans on mov-ing
Post by: dedndave on February 22, 2011, 04:40:03 PM
if you go to that forum, they have little contests to see who can write the slickest boot sector
here is one of them
http://forum.osdev.org/viewtopic.php?f=2&t=21791&p=174475&hilit=boot+sector+contest#p174475
a great place to learn about getting in and out of protected mode and displaying stuff   :U
Title: Re: Invalid instruction operans on mov-ing
Post by: clive on February 22, 2011, 06:55:07 PM
You could use a segment construct like this

video  segment use16 at 0B800h
screen  db 1000 dup (?)
video ends