News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

is it possible to setup the data segement in.386

Started by hellfix, June 16, 2012, 04:09:16 AM

Previous topic - Next topic

hellfix

im trying to use com functions in a 386 instruction set is it possible to set up the data segement using ax like this

mov ax,@data
mov ds,ax

or is this setup only for model small and not to work with

.386
.model flat,c
.stack

is there a way to use com functions on under .386 im trying to use create file
function under .386 instruction set

dedndave

by COM, i assume you are talking about objects and all that
not a .COM (tiny model) program
these are not the same thing

COM may not be used with 16-bit code, as far as i know

for a .COM program, CS, DS, ES, and SS are all the same segment

if you specify Flat, do not specify a stack
16-bit code and a Flat memory model do not go together   :P

hellfix

 :dazzled: im trying to  use an example i found in this new masm book i got off the internet it goes like this

.386
.model flat,c
.stack 100h

includelib msvcrt

.data
printf proto arg1:ptr byte, printlist:vararg
sum dword ?
data dword 3435h,2444h,2439h,2332h,0
.code
public main
main proc
     mov edi,offset data            ;setup pointer
     mov cx,4                             ;loop counter
     mov bx,0                           
     
add_up:mov bx,[edi]                 ;add contents
       inc di
       inc di
       dec cx   
       jnz add_up
       mov esi,offset sum
       mov [esi],bx
stoploop:nop
   
       ret
     
main endp
end main

i dont know why it used mov to add the contentes of the array but im trying to use
a printf function to check if the answer is right but printf cant print a dword how to i make it print any variable type

clive

Should probably decide if using dword (4 bytes) or word (2 bytes), on a 386 it's cheaper to do the former.

.386
.model flat,c
.stack 100h

includelib msvcrt

.data
printf proto arg1:ptr byte, printlist:vararg
sum dword ?
data dword 3435h,2444h,2439h,2332h,0
.code
public main
main proc
     mov edi,offset data            ;setup pointer
     mov ecx,4                             ;loop counter
     mov ebx,0                           
     
add_up:add ebx,[edi]                 ;add contents
       add edi,4
       dec ecx   
       jnz add_up
       mov esi,offset sum
       mov [esi],ebx
stoploop:nop
   
       ret
     
main endp
end main


The following C would be fine for printing 32-bit values
printf("%u\n", sum);

Something equivalent to
  push  ebx
  push  offset format
  call  printf
  add  esp,8
..
format db "%u",0Dh, 0Ah, 0

It's a pity the clowns in Washington DC don't understand the Constitution as well as Edward Snowden

jj2007

The inc di will produce a crash under certain circumstances. Try getting rid of your 16-bit past...

clive

Quote from: jj2007The inc di will produce a crash under certain circumstances. Try getting rid of your 16-bit past...

Quote from: hellfixim trying to  use an example i found in this new masm book i got off the internet it goes like this

This new book apparently sucks. Name and shame.

It's a pity the clowns in Washington DC don't understand the Constitution as well as Edward Snowden

hellfix

The 80x86 IBM PC and Compatible Computers

http://www.amazon.ca/80X86-IBM-Compatible-Computers-Interfacing/dp/013061775X

NoCforMe

Sorry to ask you this--don't mean to insult your intelligence--but are you sure you understand the differences between 16-bit (8086) and 32-bit ('3+86) programming? Because it sounds like you don't. They're quite different animals.

Almost everything you'll find here has to do with 32-bit programming, mostly for the Windows API (either GUI or console apps).

You can still create 16-bit programs that'll run under DOS (.exe or .com), but they're different from 32-bit programs aimed for the '386 and above processors.

hellfix

im a newbie at programming but i understand dos programs both com and exe are different and the 386 use an extended instruction set but along with that i dont know much about there total sum of differences but understand this you have to start somewhere and im trying to tackle assembly programming because i like programming in it. its just that i have alot of questions that the book cannot answer. :icon_rolleyes:

clive

I hope you got it for $20, not $200 retail. Looking at the reviews it looks like they've been warming this over since 1992

; ml -Fl -coff testapp.asm -link -SUBSYSTEM:CONSOLE

.386
.model flat,c
.stack 100h

includelib c:\masm32\lib\msvcrt.lib

printf proto arg1:ptr byte, printlist:vararg

.data
sum dword ?
data dword 3435h,2444h,2439h,2332h,0
format db "Answer in Hex 0x%08X", 0Dh, 0Ah, 0

.code
public main

main proc
      mov edi,offset data         ;setup pointer
      mov ecx,4 ;loop counter
      mov ebx,0

add_up: add ebx,[edi]               ;add contents
        add edi,4
        dec ecx
        jnz add_up

        mov esi,offset sum
        mov [esi],ebx

invoke printf, addr format, ebx

        ret

main endp

end main
It's a pity the clowns in Washington DC don't understand the Constitution as well as Edward Snowden

hellfix



NoCforMe

Quote from: hellfix on June 16, 2012, 08:14:33 AM
im a newbie at programming but i understand dos programs both com and exe are different and the 386 use an extended instruction set but along with that i dont know much about there total sum of differences but understand this you have to start somewhere and im trying to tackle assembly programming because i like programming in it. its just that i have alot of questions that the book cannot answer. :icon_rolleyes:

True, you have to start somewhere, and nobody here looks down on you because you're a beginner.

So now that you know the basic divide here, between DOS (16-bit) and Windows (32-bit) programs, you need to decide which you're going to learn.

I would suggest Windows, unless you have some specific reason to learn 16-bit programming. (You do have access to a computer running Windows, don't you?) Reason is, it's actually a lot easier programming using the "flat" model under Windows. Yes, you have to learn a few things about Windows-specific techniques (like event-driven programming, handling messages, etc.), but it's so much easier not having to screw around with segment registers. And 32-bit programming has other advantages, like being able to use any of the "general-purpose" registers (EAX, EBX, ECX, EDX, plus ESI and EDI) as index registers, instead of just BX, SI and DI in 16-bit real mode.

If you want to learn Win32 programming, download the MASM32 stuff, then look in the examples folder, take a program there and use it as a starting point. And, of course, ask questions here.

dedndave

well - i certainly would not say win32 is easier
there are a seemingly endless number of functions, messages, notifications, structures to learn about
however, it is a lot more rewarding and powerful
you have all those functions, etc, because it can do a lot more stuff   :P