16-bit error "there was an error in creating"

Started by crazyhorse, December 15, 2011, 06:17:56 AM

Previous topic - Next topic

crazyhorse

Hello everyone. Nice to meet all of you.
I wrote this code to encode a text file but I get the error

"there was an error in creating" when i run the .exe file that the code generated

first off i used
1. \masm32\bin\ml /c buddies.asm
2. \masm32\bin\link16 buddies.obj
3. ENTER, ENTER, ENTER, ENTER for the four fields it asks afterward
4. and then it created the exe file.

I did this for both files seperately...Maybe i should put them together?


Could you guys/gals look at my code and see what I'm doing wrong ...I'm scratching my head right now, lol.





TITLE    Decoding using Base-85 algorithm.
              ; This program Decodes a file into its original form that was encoded by base-85 algorithm.


.model small
.386
.stack
.data

InputFileName DB 128  dup (?)
OutputFileName DB 128  dup (?)
InputBuffer DB 5000 dup (?)
OutputBuffer DB 4000 dup (?)

CreatingError DB "There was an Error in Creating."
OpeningError DB "There was an Error in Opening."
ReadingError DB "There was an Error in Reading."
WritingError DB "There was an Error in Writing."

Multiplier_1 DD 00000001h
Multiplier_2 DD 00000055h
Multiplier_3 DD 00001c39h
Multiplier_4 DD 00095eedh
Multiplier_5 DD 031c84b1h

InputHandle DW ?
OutputHandle DW ?
HoldBytes DW ?

.code

        main PROC

mov ax, @data
mov ds, ax

call InputOutputCommand ; For the input and output file name on command prompt

;;;;;;;;;;;;;;;;;;Create Output file;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
mov ah, 3Ch ; 3C to create a file
sub  cx, cx
mov dx, OFFSET OutputFileName

int 21h
jc CreateError
mov OutputHandle, ax

;;;;;;;;;;;;;;;;;;;;Open input file;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
mov ah,3Dh ; 3D to open a file   
sub al,al   
mov dx,OFFSET InputFileName

int 21h
jc OpenError
mov InputHandle, ax

;;;;;;;;;;;;;;Read Input File ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Read:
mov ah, 3Fh ; 3F to read a file
mov bx, InputHandle
mov cx, 5000 ; Input Buffer Size
mov dx, OFFSET InputBuffer

int 21h
jc ReadError

mov HoldBytes, ax
cmp ax, 0
jz CloseFiles


;;;;;;;;;;;;;;;;; Decode 5 bytes into 4 bytes;;;;;;;;;;;;;;;;;;;;;;;;;;;
mov dx,0
mov di,0
mov si, 0

mov ax, HoldBytes
mov bx, 5
div bx
mov cx, ax

Decode:
call Multiplication

cmp dl, 1
jz TwoBytesLeft

cmp dl, 2
jz ThreeBytesLeft

cmp dl, 3
jz FourBytesLeft

mov OutputBuffer[di + 3], bl
mov OutputBuffer[di + 2], bh
shr ebx, 16
mov OutputBuffer[di + 1], bl
mov OutputBuffer[di], bh

add di, 4
add si, 5

loop Decode
jmp WriteIntoFile

;;;;;;;;;;;;;;;;;;For less than 5 bytes left;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
FourBytesLeft:
add bh, 1
mov OutputBuffer[di + 2], bh
shr ebx, 16
mov OutputBuffer[di + 1], bl
mov OutputBuffer[di], bh

add di, 3
jmp WriteIntoFile


ThreeBytesLeft:
shr ebx, 16
mov OutputBuffer[di], bh
add bl, 1
mov OutputBuffer[di + 1], bl

add di, 2
jmp WriteIntoFile


TwoBytesLeft:
shr ebx, 16
add bh, 1
mov OutputBuffer[di], bh

add di, 1
jmp WriteIntoFile


;;;;;;;;;;;;;;;;;;;Write into Output File;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
WriteIntoFile:
mov ah, 40h ; 40h is to write
mov bx, OutputHandle
mov dx, offset OutputBuffer
mov cx, di
int 21h

jc WriteError

cmp ax, cx
jnz WriteError

jmp Read

;;;;;;;;;;;;;;;;;;;;;;;; To close Input and Output Files;;;;;;;;;;;;;;;;;;;;;;;;;
CloseFiles:
mov ah, 3Eh ; 3E is to close
mov bx, InputHandle
int 21h

mov ah, 3Eh
mov bx, OutputHandle
int 21h
jmp Exit


;;;;;;;;;;;;;;;;;;;;; Error for Creating a File ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
CreateError:
mov dx, OFFSET CreatingError
mov ah, 40h
mov bx, 1
mov cx, 31 ; length of the message CreatingError is 31.
int 21h

mov ah,1
int 21h
jmp Exit

;;;;;;;;;;;;;;;;;;;;; Error for Opening a File ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
OpenError:
mov dx, OFFSET OpeningError
mov ah, 40h
mov bx, 1
mov cx, 30 ; length of the message OpeningError is 30.
int 21h

mov ah,1
int 21h
jmp Exit

;;;;;;;;;;;;;;;;;;;;; Error for Reading a File ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ReadError:
mov dx, OFFSET ReadingError
mov ah, 40h
mov bx, 1
mov cx, 30 ; length of the message ReadingError is 30.
int 21h

mov ah,1
int 21h
jmp Exit

;;;;;;;;;;;;;;;;;;;;; Error for Writing into File ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
WriteError:
mov dx, OFFSET WritingError
mov ah, 40h
mov bx, 1
mov cx, 30 ; length of the message WritingError is 30.
int 21h

mov ah,1
int 21h
jmp Exit

;;;;;;;;;;;;;;;;;;;;;To Exit from the program;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Exit:
mov ax, 4c00h
int 21h

        main ENDP

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; This procedure is to do multliplication.
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Multiplication PROC
mov eax, 0
mov ebx, 0

mov al, InputBuffer[si]
sub al, 33
mul Multiplier_5
mov ebx, eax

mov eax, 0
mov al, InputBuffer[si + 1]
sub al, 33
mul Multiplier_4
add ebx, eax

mov eax, 0
mov al, InputBuffer[si + 2]

cmp al, 125
jz End4
sub al, 33
mul Multiplier_3
add ebx, eax

mov eax, 0
mov al, InputBuffer[si + 3]

cmp al, 125
jz End3
sub al, 33
mul Multiplier_2
add ebx, eax

mov eax, 0
mov al, InputBuffer[si + 4]

cmp al, 125
jz End2
sub al, 33
mul Multiplier_1
add ebx, eax
jmp End1

End4: mov dl, 1
jmp End1

End3: mov dl, 2
jmp End1

End2: mov dl, 3

End1:

ret
Multiplication ENDP

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; This procdeure is to put command on command-prompt 
; for Input File Name and Output File Name.
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
InputOutputCommand PROC
;;;;;;;;;;;;;;;;;;;;;;;;For the Input File Name;;;;;;;;;;;;;;;;;;;;
mov di, 81h
mov si, OFFSET InputFileName

mov al, 20h
repz scasb
jz FileMissing
dec di

GetInputFileName:
mov al, es:[di]
inc di
mov [si], al
inc si

mov al, es:[di]
cmp al, 20h ; If space (20h for space)
jz EndInputFileName
jmp GetInputFileName

EndInputFileName: mov byte ptr [si], 0

;;;;;;;;;;;;;;;;;;;;For the Output File Name;;;;;;;;;;;;;;;;;;;;;;;
mov si, OFFSET OutputFileName

mov al, 20h
repz scasb
jz  FileMissing
dec di

GetOutputFileName:
mov al, es:[di]
inc di
mov [si], al
inc si

mov al, es:[di]
cmp al, 0Dh ; 0Dh is for carriage return
jz EndOutputFileName
jmp GetOutputFileName

EndOutputFileName: mov byte ptr [si], 0
FileMissing: stc

ret
InputOutputCommand ENDP

END main




and





TITLE    Encoding using Base-85 algorithm.
              ; This program Encodes a file (text or image) into text file using Base-85 algorithm.


.model small
.386
.stack
.data

InputFileName DB 128 dup (?)
OutputFileName DB 128 dup (?)
InputBuffer DB 4000 dup (?)
OutputBuffer DB 5200 dup (?)

CreatingError DB "There was an Error in Creating."
OpeningError DB "There was an Error in Opening."
ReadingError DB "There was an Error in Reading."
WritingError DB "There was an Error in Writing."

InputHandle DW ?
OutputHandle DW ?
HoldBytes DW ?
Remainder DW ?
Divisor DD 85


.code

        main PROC

mov ax, @data
mov ds, ax

call InputOutputCommand

;;;;;;;;;;;;;;;;;;Create Output file;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
mov ah, 3Ch ; 3C to create a file
sub  cx, cx
mov dx, OFFSET OutputFileName

int 21h
jc CreateError
mov OutputHandle, ax

;;;;;;;;;;;;;;;;;;;;Open input file;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
mov ah,3Dh ; 3D to open a file   
sub al,al   
mov dx,OFFSET InputFileName

int 21h
jc OpenError
mov InputHandle, ax

;;;;;;;;;;;;;;Read Input File ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Read:
mov ah, 3Fh ; 3F to read a file
mov bx, InputHandle
mov cx, 4000 ; Input Buffer Size
mov dx, OFFSET InputBuffer

int 21h
jc ReadError

mov HoldBytes, ax
cmp ax, 0
jz CloseFiles

;;;;;;;;;;;;;;; Encode 4 bytes to 5 bytes;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
mov dx, 0
mov di, 0
mov si, 0

mov ax, HoldBytes
mov bx, 4
div bx

mov Remainder, dx ; Since, dx keeps remainder after ax divided by bx.
cmp ax, 0
jz BytesLeft
mov cx, ax

Encode:
mov edx, 0
mov ah, InputBuffer[si]
mov al, InputBuffer[si + 1]
shl eax, 16
mov ah, InputBuffer[si + 2]
mov al, InputBuffer[si + 3]

div Divisor
add dl, 33
mov OutputBuffer[di + 4], dl ; LSB of the encoded bytes

mov edx, 0
div Divisor
add dl, 21h
mov OutputBuffer[di + 3], dl

mov edx, 0
div Divisor
add dl, 21h
mov OutputBuffer[di + 2], dl

mov edx, 0
div Divisor
add dl, 21h
mov OutputBuffer[di + 1], dl

mov edx, 0
div Divisor
add dl, 21h
mov OutputBuffer[di], dl ; MSB of the encoded bytes

add di, 5
add si, 4

loop Encode

;;;;;;;;;;;;;;;;;;;;;;;;;;For Less than 4 bytes;;;;;;;;;;;;;;;;;;;;;;
BytesLeft:
cmp Remainder, 0 ; If no remaining byte occurs
jz WriteIntoFile

cmp Remainder, 1 ; If one byte occurs
jz OneByteLeft

cmp Remainder, 2 ; If two byte occurs
jz TwoBytesLeft

cmp Remainder, 3 ; If three byte occurs
jz ThreeBytesLeft

ThreeBytesLeft:
mov edx, 0
mov ah, InputBuffer[si]
mov al, InputBuffer[si + 1]
shl eax, 16
mov ah, InputBuffer[si + 2]
mov al, 0
div Divisor

mov edx, 0
div Divisor
add dl, 33
mov OutputBuffer[di + 3], dl

mov edx, 0
div Divisor
add dl, 33
mov OutputBuffer[di + 2], dl

mov edx, 0
div Divisor
add dl, 33
mov OutputBuffer[di + 1], dl

mov edx, 0
div Divisor
add dl, 33
mov OutputBuffer[di], dl

mov OutputBuffer[di + 4], 125 ; Here, 125 is for '}'
add di, 5
jmp WriteIntoFile


TwoBytesLeft:
mov edx, 0
mov ah, InputBuffer[si]
mov al, InputBuffer[si + 1]
shl eax, 16
mov ax, 0
div Divisor
mov edx, 0
div Divisor

mov edx, 0
div Divisor
add dl, 33
mov OutputBuffer[di + 2], dl

mov edx, 0
div Divisor
add dl, 33
mov OutputBuffer[di + 1], dl

mov edx, 0
div Divisor
add dl, 33
mov OutputBuffer[di], dl

mov OutputBuffer[di + 3], 125
mov OutputBuffer[di + 4], 125
add di, 5
jmp WriteIntoFile


OneByteLeft:
mov edx, 0
mov ah, InputBuffer[si]
mov al, 0
shl eax, 16
mov ax, 0
div Divisor

mov edx, 0
div Divisor

mov edx, 0
div Divisor

mov edx, 0
div Divisor
add dl, 33
mov OutputBuffer[di + 1], dl

mov edx, 0
div Divisor
add dl, 33
mov OutputBuffer[di], dl

mov OutputBuffer[di + 2], 125
mov OutputBuffer[di + 3], 125
mov OutputBuffer[di + 4], 125
add di, 5
jmp WriteIntoFile


;;;;;;;;;;;;;;;;;;;Write into Output File;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
WriteIntoFile:
mov ah, 40h ; 40h is to write
mov bx, OutputHandle
mov dx, offset OutputBuffer
mov cx, di
int 21h

jc WriteError

cmp ax, cx
jnz WriteError

jmp Read

;;;;;;;;;;;;;;;;;;;;;;;; To close Input and Output Files;;;;;;;;;;;;;;;;;;;;;;;;;
CloseFiles:
mov ah, 3Eh ; 3E is to close
mov bx, InputHandle
int 21h

mov ah, 3Eh
mov bx, OutputHandle
int 21h
jmp Exit


;;;;;;;;;;;;;;;;;;;;; Error for Creating a File ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
CreateError:
mov dx, OFFSET CreatingError
mov ah, 40h
mov bx, 1
mov cx, 31 ; length of the message CreatingError is 31.
int 21h

mov ah,1
int 21h
jmp Exit

;;;;;;;;;;;;;;;;;;;;; Error for Opening a File ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
OpenError:
mov dx, OFFSET OpeningError
mov ah, 40h
mov bx, 1
mov cx, 30 ; length of the message OpeningError is 30.
int 21h

mov ah,1
int 21h
jmp Exit

;;;;;;;;;;;;;;;;;;;;; Error for Reading a File ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ReadError:
mov dx, OFFSET ReadingError
mov ah, 40h
mov bx, 1
mov cx, 30 ; length of the message ReadingError is 30.
int 21h

mov ah,1
int 21h
jmp Exit

;;;;;;;;;;;;;;;;;;;;; Error for Writing into File ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
WriteError:
mov dx, OFFSET WritingError
mov ah, 40h
mov bx, 1
mov cx, 30 ; length of the message WritingError is 30.
int 21h

mov ah,1
int 21h
jmp Exit

;;;;;;;;;;;;;;;;;;;;;To Exit from the program;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Exit:
mov ax, 4c00h
int 21h

        main ENDP

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; This procdeure is to put command on command-prompt 
; for Input File Name and Output File Name.
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
InputOutputCommand PROC
;;;;;;;;;;;;;;;;;;;;;;;;For the Input File Name;;;;;;;;;;;;;;;;;;;;
mov di, 81h
mov si, OFFSET InputFileName

mov al, 20h
repz scasb
jz FileMissing
dec di

GetInputFileName:
mov al, es:[di]
inc di
mov [si], al
inc si

mov al, es:[di]
cmp al, 20h ; If space (20h for space)
jz EndInputFileName
jmp GetInputFileName

EndInputFileName: mov byte ptr [si], 0

;;;;;;;;;;;;;;;;;;;;For the Output File Name;;;;;;;;;;;;;;;;;;;;;;;
mov si, OFFSET OutputFileName

mov al, 20h
repz scasb
jz  FileMissing
dec di

GetOutputFileName:
mov al, es:[di]
inc di
mov [si], al
inc si

mov al, es:[di]
cmp al, 0Dh ; 0Dh is for carriage return
jz EndOutputFileName
jmp GetOutputFileName

EndOutputFileName: mov byte ptr [si], 0
FileMissing: stc

ret
InputOutputCommand ENDP

END main


dedndave

that's a lot of code for us to read through - lol
however....

generally, when there is an error creating a file, it is because you (or i - lol) do not have a proper file name
check the string
just before the create function, display the filename with INT 21h, AH=9

to make that easy, i sometimes terminate my filename strings with 0, 24h
the 0 is for the filename termination - the 24h is the DOS string display termination ("$")
so - you can display it - the 0 will appear as a space character   :U

jj2007


crazyhorse

okay i think i'm getting a hang of things kinda,

now my error is

'Cannot load VDM IPX/SPX support
There was an Error in Creating.

any ideas?

dedndave