News:

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

help! with code

Started by rickszyr, June 23, 2009, 03:28:46 AM

Previous topic - Next topic

rickszyr

i'm trying to compile this code in masm32 version 10:

.386
.model flat, stdcall

.data
.code
start:
    mov ax,0900h
    mov dx, offset msg   <<<<<<
    int 21h

    mov ax,4c00h
    int 21h
    msg db "hiho",0

end start

but i get the following error referring to the marked line:

instruction operands must be the same size.

Any ideas?? thnx!!

also... i need a code to go through the file system. anyone got any code samples??

for example, how to go through a folder and print the name of the files there.

thanx

Farabi

Quote from: rickszyr on June 23, 2009, 03:28:46 AM
i'm trying to compile this code in masm32 version 10:

.386
.model flat, stdcall

.data
.code
start:
    mov ax,0900h
    mov dx, offset msg   <<<<<<
    int 21h

    mov ax,4c00h
    int 21h
    msg db "hiho",0

end start

but i get the following error referring to the marked line:

instruction operands must be the same size.

Any ideas?? thnx!!

also... i need a code to go through the file system. anyone got any code samples??

for example, how to go through a folder and print the name of the files there.

thanx

It was because you are coding a 16-bit on a 32-bit environtment.
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

rickszyr

so.. the solution? how would you write this the correct way?

Thnx.

dedndave



        include \masm32\include\masm32rt.inc

        .data

        .code

start:
        print   chr$("hiho"),13,10
        exit

        end start

Damos

.model flat, stdcall
is the problem, you are basically telling the assembler you are working in 32bit flat environment not 16bit.
so when you:
mov dx,offset msg
your asking to put a 32 bit value(the address of msg) into a 16 bit register (dx).
if you changed your registers to 32bit you would still have problems running this in windows because it is dos code.
I strongly recommend you forget about 16 bit dos and go straight to 32 bit windows.
Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius -- and a lot of courage -- to move in the opposite direction. - Albert Einstien

Slugsnack

Quote from: dedndave on June 23, 2009, 04:53:57 AM


        include \masm32\include\masm32rt.inc

        .data

        .code

start:
        print   chr$("hiho"),13,10
        exit

        end start

Fortunately 'print' supports quoted text  :bdg

print "hiho", 13, 10

dedndave

well - i didn't want to tell him the GetStdHandle and WriteFile method
wouldn't want to discourage a newcomer - lol
Damos is right - 32-bit is the way to go
16-bit is quickly becoming a dinosaur

Slugsnack

Quote from: dedndave on June 23, 2009, 11:29:18 AM
well - i didn't want to tell him the GetStdHandle and WriteFile method
wouldn't want to discourage a newcomer - lol
Damos is right - 32-bit is the way to go
16-bit is quickly becoming a dinosaur
becoming.. ?  BECOMING ?!?!?!?  :dazzled:

dedndave

it isn't officially a dinosaur until i forget how it works
i spent too many hours going "int 21h"
btw - i still have a functional XT

hutch--

rickszyr,

Farabi is correct here, you have taken a fragment of 16 bit DOS code that uses interrupts and tried to plug it into a 32 bit framework which simply will not work as they are different systems and memory addressing schemes. To do what you are after you need to learn some win32 then some assembler to write it. You have been given some simple examples on how to display text at the console but no-one is going to keep writing code for you.

If you are willing to learn win32 assembler, many people here will help you but if you just want some code, Rent A Coder is the way to go.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

SteveCurtis

Quote from: rickszyr on June 23, 2009, 03:28:46 AM
i'm trying to compile this code in masm32 version 10:

.386
.model flat, stdcall

.data
.code
start:
    mov ax,0900h
    mov dx, offset msg   <<<<<<
    int 21h

    mov ax,4c00h
    int 21h
    msg db "hiho",0

end start

but i get the following error referring to the marked line:

instruction operands must be the same size.

Any ideas?? thnx!!

also... i need a code to go through the file system. anyone got any code samples??

for example, how to go through a folder and print the name of the files there.

thanx

Hi rickszyr,

Before you go another step, you probably need to get a clear understanding of the difference between 'real mode' and 'protected mode'. 
For example:
With Protected Mode (PM) the machine uses 'descriptor tables' to manage many operational functions. (A descriptor is simply an area in memory that is like a structure, or record, and that contains necessary information to use a resource, such as memory). The processor then uses that information to know how to behave when generating addresses. In the case of memory access, what was a segment register now points to the descriptor table. Now, instead of being used to form the segment+offset address, the address is now formed from information within the decriptor table, plus a now 32 bit version of the offset register.

Descriptor tables do much more than this of course, so you can't take antything here and solve your problem directly and there is much more to PM 32bit than desciptor tables  :P.

Such items as descriptor tables (and there a few different types), need to be set up before use, so any PM (read 32 bit) operating sytem will always boot in 16 bit realmode for a few bytes of program (in the bootloader) to do the first initialisations and then jump to 32 bits to run. I think you should have a handle on these ideas purely as background to understanding PM as it differentiates from real mode.

The MASM32 installation has heaps of examples of code that does much useful stuff. You should take a walk in the Macros.ASM and also run the examples in the samples folder.  Also you need to buy a few books on protected mode assembler programming (one never seems to do). Also there are plenty of introductory sites and assembler courses. Here are few I found that will provide either extensive detail, or interesting tidbits about PM.

http://courses.ece.illinois.edu/ece390/books/labmanual/pmode.html
http://linuxgazette.net/issue82/raghu.html
http://www.osdever.net/tutorials/descriptors.php#start_gdt
http://www.duntemann.com/assembly.htm
(These are only a start)

Please take others from those here posted, such as Goasm, HLA, and Donkey's web pages on assembler as just a begginning.

Regards,
Steve