Author Topic: is it possible to setup the data segement in.386  (Read 10768 times)

hellfix

  • Guest
is it possible to setup the data segement in.386
« on: June 16, 2012, 04:09:16 AM »
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

  • Member
  • *****
  • Posts: 8828
  • Still using Abacus 2.0
    • DednDave
Re: is it possible to setup the data segement in.386
« Reply #1 on: June 16, 2012, 04:50:21 AM »
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

  • Guest
Re: is it possible to setup the data segement in.386
« Reply #2 on: June 16, 2012, 05:13:07 AM »
 :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

  • Regular Member
  • *
  • Posts: 27
  • Toolsmith and Assembler coder (x86,ARM,MIPS,68K)
Re: is it possible to setup the data segement in.386
« Reply #3 on: June 16, 2012, 06:29:31 AM »
Should probably decide if using dword (4 bytes) or word (2 bytes), on a 386 it's cheaper to do the former.

Code: [Select]
.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
Code: [Select]
  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

  • Member
  • *****
  • Posts: 13957
  • Assembly is fun ;-)
    • MasmBasic
Re: is it possible to setup the data segement in.386
« Reply #4 on: June 16, 2012, 06:36:03 AM »
The inc di will produce a crash under certain circumstances. Try getting rid of your 16-bit past...

clive

  • Regular Member
  • *
  • Posts: 27
  • Toolsmith and Assembler coder (x86,ARM,MIPS,68K)
Re: is it possible to setup the data segement in.386
« Reply #5 on: June 16, 2012, 06:38:29 AM »
Quote from: jj2007
The inc di will produce a crash under certain circumstances. Try getting rid of your 16-bit past...

Quote from: hellfix
im 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

  • Guest
Re: is it possible to setup the data segement in.386
« Reply #6 on: June 16, 2012, 07:55:05 AM »

NoCforMe

  • Guest
Re: is it possible to setup the data segement in.386
« Reply #7 on: June 16, 2012, 08:04:50 AM »
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

  • Guest
Re: is it possible to setup the data segement in.386
« Reply #8 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:

clive

  • Regular Member
  • *
  • Posts: 27
  • Toolsmith and Assembler coder (x86,ARM,MIPS,68K)
Re: is it possible to setup the data segement in.386
« Reply #9 on: June 16, 2012, 10:01:19 AM »
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

Code: [Select]
; 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

  • Guest
Re: is it possible to setup the data segement in.386
« Reply #10 on: June 16, 2012, 10:34:17 AM »
i downloaded it off the net :badgrin:

Mr Hippy

  • Guest
Re: is it possible to setup the data segement in.386
« Reply #11 on: June 16, 2012, 10:35:14 AM »

NoCforMe

  • Guest
Re: is it possible to setup the data segement in.386
« Reply #12 on: June 16, 2012, 11:20:31 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

  • Member
  • *****
  • Posts: 8828
  • Still using Abacus 2.0
    • DednDave
Re: is it possible to setup the data segement in.386
« Reply #13 on: June 16, 2012, 11:26:40 AM »
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