News:

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

Main Menu

Building 16 bit Exe

Started by tda0626, May 14, 2024, 08:52:06 AM

Previous topic - Next topic

_japheth

QuoteI dump memory of the DS through debug and my string is in the original DS location before it is changed. Someone explain that to me because I don't get it.

This part of your program introduces hazardous behavior:

    mov bl,  ds:[si]            ; check to see if we are at the end of alpha
    .if bl>'Z'                 
        mov si, offset alpha        ; if so, reset the offset
    .endif

because there's nowhere in your string a character that's ">'Z'".


@NoCForMe: suggesting optimizations while a bug is to be fixed is not very "professional".
Dummheit, gepaart mit Dreistigkeit - eine furchtbare Macht.

NoCforMe

Quote from: _japheth on May 15, 2024, 02:29:23 PM@NoCForMe: suggesting optimizations while a bug is to be fixed is not very "professional".
Point taken. However, since my optimizations ended up fixing the problem I consider myself absolved here.
Assembly language programming should be fun. That's why I do it.

sinsi

Quote from: NoCforMe on May 15, 2024, 02:55:08 PMPoint taken. However, since my optimizations ended up fixing the problem I consider myself absolved here.
Until we hear from the OP, it's not fixed yet.

tda0626

Quote from: _japheth on May 15, 2024, 02:29:23 PM
QuoteI dump memory of the DS through debug and my string is in the original DS location before it is changed. Someone explain that to me because I don't get it.

This part of your program introduces hazardous behavior:

    mov bl,  ds:[si]            ; check to see if we are at the end of alpha
    .if bl>'Z'                 
        mov si, offset alpha        ; if so, reset the offset
    .endif

because there's nowhere in your string a character that's ">'Z'".


@NoCForMe: suggesting optimizations while a bug is to be fixed is not very "professional".


Yep that was it. Thanks for pointing that out. I added a zero to the end of the string and changed the check to check for that instead. It appears to work ok now.


In my code, I use the

mov ax, @data

How would I do the same thing without using the @data?



I don't mind being given optimizations but would rather get my code working first before doing anything else to it but do appreciate the tips. Also, I wanted to keep it somewhat simple to read because I can send this to my brother to look over and he should be able to follow it.

Tim

_japheth

Quote from: tda0626 on May 15, 2024, 09:12:55 PMIn my code, I use the

mov ax, @data

How would I do the same thing without using the @data?


Hm, that's actually not a trivial question. So the answer may also be a bit complicated:

@data is an alias for DGROUP and this is a segment reference, meaning the OS loader has to adjust this location when the program is loaded ( there are "segment fixups" in the MZ header for exactly this reason ).

To avoid segment fixups, the easiest way is to change the memory model from .small to .tiny ( but without adding "ORG 100h" at the program start, the program is still supposed to become an .EXE program ).

In model .tiny, @data isn't necessary anymore, because CS holds that value already. So instead of "mov ax, @data", you can now code "mov ax,cs".

Btw, it's a good idea to add the ".dosseg" directive just behind the ".model" directive. That tells the linker to organize segments is a somewhat smart way. Without that, your program will still run, but the stack may be located in the middle of the binary, wasting 512 bytes.
Dummheit, gepaart mit Dreistigkeit - eine furchtbare Macht.

NoCforMe

Quote from: _japheth on May 15, 2024, 09:59:21 PMTo avoid segment fixups, the easiest way is to change the memory model from .small to .tiny ( but without adding "ORG 100h" at the program start, the program is still supposed to become an .EXE program ).
So .tiny creates a .COM-like program except that it's actually an .EXE, right? (With the MZ header and all.) Otherwise it's like a .COM in that everything (code, data, stack) is in a single segment, correct?

Then to set DS, I always used
    PUSH  CS
    POP   DS
Assembly language programming should be fun. That's why I do it.

sinsi

If you use simplified code, have a look at .startup and .exit, they do a lot of the work for you
.model tiny
.code
        .startup
            ;your code
        .exit
end

NoCforMe

Hmm; never used those, never even heard of them.
.startup:
@Startup:
mov dx, DGROUP
mov ds, dx
mov bx, ss
sub bx, dx
shl bx, 1 ; If .286 or higher, this is
shl bx, 1 ; shortened to shl bx, 4
shl bx, 1
shl bx, 1
cli ; Not necessary in .286 or higher
mov ss, dx
add sp, bx
sti ; Not necessary in .286 or higher
(from the MASM 6.1 manual)
Assembly language programming should be fun. That's why I do it.

daydreamer

Quote from: tda0626 on May 14, 2024, 12:23:23 PMI got it to do a com file.

ml /c videowrite.asm

link16 videowrite.obj

It gives me a "No stack segment defined". Now I know why thanks to NoCforMe's template. :biggrin: But it still works.

I ran it in DOSBox-X. I am using this example to show my brother how to directly write to video memory instead of using the BIOS video services.
Is dosbox-x the version which support MMX opcodes ?
Optimisations with dosbox should be done with old CPUs cycle count data
@nocforme
.com files might be dinosaurs because of age,but size is like that mosquito in Jurassic park :)
my none asm creations
https://masm32.com/board/index.php?topic=6937.msg74303#msg74303
I am an Invoker
"An Invoker is a mage who specializes in the manipulation of raw and elemental energies."
Like SIMD coding

sinsi

Quote from: NoCforMe on May 16, 2024, 12:09:59 PMSo .tiny creates a .COM-like program except that it's actually an .EXE, right? (With the MZ header and all.) Otherwise it's like a .COM in that everything (code, data, stack) is in a single segment, correct?
/tiny (or the linker option /AT) creates a .com file, no header, just a binary image.
The only thing that makes it a .com file is using ORG 100h (or .startup will do that for you).

If you use ORG 100h in a .exe, there would be 256 null bytes before your code/data (if I'm remembering right).

_japheth

Quote from: NoCforMe on May 16, 2024, 12:09:59 PMSo .tiny creates a .COM-like program except that it's actually an .EXE, right? (With the MZ header and all.) Otherwise it's like a .COM in that everything (code, data, stack) is in a single segment, correct?

Yes. Technically, all that ".model tiny" does is to add segment _TEXT to DGROUP. You can stay with ".model small" and do that "manually":
.model small
.stack 256
DGROUP group _TEXT

.data

text db "hello",13,10,'$'

.code
start:
push cs
pop ds
mov dx, offset text
mov ah, 9
int 21h
mov ah, 4ch
int 21h

END start
Dummheit, gepaart mit Dreistigkeit - eine furchtbare Macht.

NoCforMe

Quote from: sinsi on May 16, 2024, 02:24:06 PMIf you use ORG 100h in a .exe, there would be 256 null bytes before your code/data (if I'm remembering right).
Yes, the ORG 100h puts the program entry point just past the PSP (program segment prefix), which is 256 bytes long. (Contains the file-control blocks (FCBs) and other stuff, including a pre-coded INT 20H for program exit.)

Although, nevermind, since you were describing an .exe and I was talking about a .com.
No need to further confuse the poor OP ...
Assembly language programming should be fun. That's why I do it.

NoCforMe

Quote from: tda0626 on May 15, 2024, 09:12:55 PMI added a zero to the end of the string and changed the check to check for that instead. It appears to work ok now.
No need to do that. See my code in the post above. Sure it's nonstandard string formatting, but who cares? It's your program, you can do what you want, and it works. (And remember that old DOS programs used '$' as a delimiter way back when.)
Assembly language programming should be fun. That's why I do it.

tda0626

Quote from: daydreamer on May 16, 2024, 02:09:05 PMIs dosbox-x the version which support MMX opcodes ?
Optimisations with dosbox should be done with old CPUs cycle count data



It has the option of emulating the Pentium MMX in the CPU type menu.