News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Invalid instruction operans on mov-ing

Started by bluman, February 22, 2011, 03:53:10 PM

Previous topic - Next topic

bluman

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.

redskull

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
Strange women, lying in ponds, distributing swords, is no basis for a system of government

dedndave

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

bluman

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?

dedndave

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

bluman

Lol, a simple Mov Byte Ptr DS:[TextMem], 65 works. Didn't believe this would do.

Thank you very much for the help.

dedndave

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

clive

You could use a segment construct like this

video  segment use16 at 0B800h
screen  db 1000 dup (?)
video ends
It could be a random act of randomness. Those happen a lot as well.