News:

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

Main Menu

File manipulation in good 'ole 16-bit DOS 6.22

Started by jejump, January 21, 2022, 01:27:08 PM

Previous topic - Next topic

Gunther

Quote from: jj2007 on January 22, 2022, 12:00:52 PM
Can you occasionally make a post without insulting those who don't agree with you?

Uhh, touched a nerve?

But please, allow me the following question: Was it your buggy code or mine that caused the assembly problems?
This just shows you're quarrelsome, opinionated, and incapable of self-criticism. That's not a personal attack, but a fact.

You have to know the facts before you can distort them.

jj2007

Quote from: Gunther on January 22, 2022, 04:38:56 PMWas it your buggy code or mine that caused the assembly problems?
This just shows you're quarrelsome, opinionated, and incapable of self-criticism. That's not a personal attack, but a fact.

An absolute n00b would have understood immediately that the file wasn't where the source expected it. Strange that an experienced programmer like you isn't able to either change the include line, or copy the *.inc to the folder where the assembler expects it :cool:

stack1~1.asm(1) : Error A2106: Cannot open file: "\masm32\MasmBasic\DosBasic.inc" [ENOENT]
stack1~1.asm(2) : Error A2209: Syntax error: Init
stack1~1.asm(3) : Error A2209: Syntax error: Print

Gunther

Quote from: jj2007 on January 22, 2022, 11:25:42 PM
An absolute n00b would have understood immediately that the file wasn't where the source expected it. Strange that an experienced programmer like you isn't able to either change the include line, or copy the *.inc to the folder where the assembler expects it :cool:

Tell it to the marines! Only you are responsible for your sloppy sources. 
You have to know the facts before you can distort them.

jejump


So, the code below produces an .exe file that produces this image:

https://drive.google.com/file/d/1Owctyj0LxRtwGguA9WeZkVaMNZ-rX-nU/view

on my Windows 7 computer by double-clicking the executable.  I wanted to see if in fact, DEBUG.exe was "hogging" most of the available memory.  Turns out, the real hog (I suppose) is Windows.  I get the same results in the working registers with or without working inside of DEBUG.  Segment registers will obviously differ.  I then opened FCOPY.exe inside of DEBUG and saw the same thing.  That program creates MYFILE.BAK literally at 70h bytes per data transfer.  I guess these are the limits. 

The challenge for me is that I want to open a file of max size 65535 bytes.  I want to then scan that data for an opening byte sequence that might be about 10 bytes long (actually, it's user defined) and then identify a closing byte sequence as well.  How to code that seems obvious if I could have the entire file available to me all at once.  At 112 bytes of file at once, I know there will surely be times when my available memory will cut off right in the middle of that signature byte sequence, so I'm gonna have to get clever about how to identify it when I have only 112 bytes of playground (or sometimes, maybe less).  Anyway, thought I'd share my findings.

Jj




    .386

xfrsize equ 0fff0h              ; # bytes per I/O access
                                ; (always multiple of 16)

bufsize equ 80                  ; length local buffer on stack

DGROUP group _DATA, STAK        ; automatic data group

_TEXT  segment word public use16 'CODE'
       assume  cs:_TEXT, ds:DGROUP, ss:STAK

Start:

    mov      ax, DGROUP         ; make data segment addressable
    mov      ds, ax


push CS
pop DS
push SS
pop ES
mov AX, 4800h
mov BX, 0FFFFh ; Not possible mem segment reserve
int 21h
push DX
push CX
push AX
lea AX, CS:[Reg_AX_Val]
pop DX
call Convert_DX_To_Ascii
lea AX, CS:[Reg_BX_Val]
mov DX, BX
call Convert_DX_To_Ascii
lea AX, CS:[Reg_CX_Val]
pop DX
call Convert_DX_To_Ascii
lea AX, CS:[Reg_DX_Val]
pop DX
call Convert_DX_To_Ascii

mov DX, CS
lea AX, CS:[Reg_CS_Val]
call Convert_DX_To_Ascii
mov DX, DS
lea AX, CS:[Reg_DS_Val]
call Convert_DX_To_Ascii
mov DX, ES
lea AX, CS:[Reg_ES_Val]
call Convert_DX_To_Ascii
mov DX, SS
lea AX, CS:[Reg_SS_Val]
call Convert_DX_To_Ascii

call Write_Reg_Status
mov AH, 0
call Wait_Esc
mov AX, 4C00h
int 21h


Wait_Esc:
int 16h
cmp AH, 1
jne Wait_Esc
ret


Convert_DX_To_Ascii:
push AX ; AX = address to store ASCII representation of DX
pop BP
push BX
mov SI, 3
mov AX, DX ; DX = 16-bit value to convert to ASCII
and AX, 0Fh
or AX, 30h
mov BX, AX
sub AX, 3Ah ; ASCII "9"+1
mov AX, BX
jc Zero_To_Nine_3
add AX, 7 ; Add 7 if > 9 (A to F)
Zero_To_Nine_3:
mov AH, 0
mov BX, AX
mov BYTE PTR CS:[BP+SI], BL
mov AX, DX
mov CL, 4
shr AX, CL
dec SI
and AX, 0Fh
or AX, 30h
mov BX, AX
sub AX, 3Ah ; ASCII "9"+1
mov AX, BX
jc Zero_To_Nine_2
add AX, 7 ; Add 7 if > 9 (A to F)
Zero_To_Nine_2:
mov AH, 0
mov BX, AX
mov BYTE PTR CS:[BP+SI], BL
mov AX, DX
mov CL, 8
shr AX, CL
dec SI
and AX, 0Fh
or AX, 30h
mov BX, AX
sub AX, 3Ah ; ASCII "9"+1
mov AX, BX
jc Zero_To_Nine_1
add AX, 7 ; Add 7 if > 9 (A to F)
Zero_To_Nine_1:
mov AH, 0
mov BX, AX
mov BYTE PTR CS:[BP+SI], BL
mov AX, DX
mov CL, 12
shr AX, CL
dec SI
and AX, 0Fh
or AX, 30h
mov BX, AX
sub AX, 3Ah ; ASCII "9"+1
mov AX, BX
jc Zero_To_Nine_0
add AX, 7 ; Add 7 if > 9 (A to F)
Zero_To_Nine_0:
mov AH, 0
mov BX, AX
mov BYTE PTR CS:[BP+SI], BL
pop BX
ret


Write_Reg_Status:
lea DX, CS:[Intro]
mov AH, 9
mov AL, 0
int 21h
ret




Intro db      0Dh,0Ah, "Int 21h call",0Dh
db 0Ah,0Ah,"Input AH = 48h"
db 0Dh,0Ah,"      BX = FFFFh (Impossible Paragraph Memory Request)"
db 0Dh,0Ah,0Ah
db "After call:  ",0Dh,0Ah,0Ah

Reg_AX_Def db "    AX = "
Reg_AX_Val db 4 DUP ("?")
db 0Dh,0Ah
Reg_BX_Def db "    BX = "
Reg_BX_Val db 4 DUP ("?")
db 0Dh,0Ah
Reg_CX_Def db "    CX = "
Reg_CX_Val db 4 DUP ("?")
db 0Dh,0Ah
Reg_DX_Def db "    DX = "
Reg_DX_Val db 4 DUP ("?")
db 0Dh,0Ah
Reg_CS_Def db "    CS = "
Reg_CS_Val db 4 DUP ("?")
db 0Dh,0Ah
Reg_DS_Def db "    DS = "
Reg_DS_Val db 4 DUP ("?")
db 0Dh,0Ah
Reg_ES_Def db "    ES = "
Reg_ES_Val db 4 DUP ("?")
db 0Dh,0Ah
Reg_SS_Def db "    SS = "
Reg_SS_Val db 4 DUP ("?")
db 0Dh,0Ah
db 0Dh,0Ah
db "Press 'Esc' to Exit!"
db 0Dh,0Ah,"$"

_TEXT  ends

_DATA segment word public use16 'DATA'


_DATA ends

STAK segment para stack use16 'STAK'

    db 2048 dup (?)             ; 2 KB stack

STAK ends

     end Start





_japheth


Haven't actually tried your program, but a quick look at your code


    mov      ax, DGROUP         ; make data segment addressable
    mov      ds, ax
push CS
pop DS


shows that you carefully set up the DS register ( mov ds,ax), but then destroy its content just 2 instructions later (pop ds). That probably won't work as expected.
Dummheit, gepaart mit Dreistigkeit - eine furchtbare Macht.

jejump


Oh.. Sorry, that's actually leftover junk.  I originally had this as a TINY code-segment-only model.  I was trying different approaches and wasn't really trying to setup DS as anything other than a copy of CS.