how to fill file with 0
how to fill file with 0
using MASM,
The size of complied file is 3K, I want to extend file to 32K, and fill file with 0.
how to do ?
The size of complied file is 3K, I want to extend file to 32K, and fill file with 0.
how to do ?
Just For Fun
I have no idea about doing it in a low language like that, but i know in C# you can read the bytes of the file, then increase the size of bytes, and re-make a replica file but with the extension.
Website: https://joscor.com
Re: how to fill file with 0
Simple as it gets, add this to the end:david wrote:using MASM,
The size of complied file is 3K, I want to extend file to 32K, and fill file with 0.
how to do ?
Code: Select all
times 32768-($-$$) db 0
You're wrong, it can be DOS too.JamesM wrote:MASM - can only be windows.
My web site: http://inflater.wz.cz (Slovak)
Derrick operating system: http://derrick.xf.cz (Slovak and English )
Derrick operating system: http://derrick.xf.cz (Slovak and English )
maybe
The DUP Operator
You can also declare an array with the DUP operator. This operator works with any of the data allocation directives described in "Allocating Memory for Integer Variables" in Chapter 4. In the syntax
count DUP (initialvalue [[, initialvalue]]...)
the count value sets the number of times to repeat all values within the parentheses. The initialvalue can be an integer, character constant, or another DUP operator, and must always appear within parentheses. For example, the statement
barray BYTE 5 DUP (1)
allocates the integer 1 five times for a total of 5 bytes.
The following examples show various ways to allocate data elements with the DUP operator:
array DWORD 10 DUP (1) ; 10 doublewords
; initialized to 1
buffer BYTE 256 DUP (?) ; 256-byte buffer
masks BYTE 20 DUP (040h, 020h, 04h, 02h) ; 80-byte buffer
; with bit masks
three_d DWORD 5 DUP (5 DUP (5 DUP (0))) ; 125 doublewords
; initialized to 0
Code: Select all
ORG 510 ; Make the file 512 bytes long
thank you, I know .
The exe file is 0.5K more than bin file.
But i find a problem.
It is impossible to create file which size is 64K.
if the file name is test.asm
the compile message is :
The size of test.exe is 64.5K.
exe2bin can't change test.exe to test.bin.
I need the file's size is 64K.
so, I think it is impossilbe to create bin file which size is 64k using MASM.
who know other good idea.
I know it maybe done using NASM.
But i must using MASM in my company .
Thanks.
Code: Select all
org 32767 ; 32 * 1024 - 1
db 0
But i find a problem.
It is impossible to create file which size is 64K.
Code: Select all
.model tiny
.code
.386
start:
xor ax, ax
org 65535 ; 64 * 1024 -1
db 0
end start
Code: Select all
masm test.asm
link test.obj
exe2bin test.exe test.bin
Code: Select all
F:\EzNet>masm test.asm
Microsoft (R) MASM Compatibility Driver
Copyright (C) Microsoft Corp 1993. All rights reserved.
Invoking: ML.EXE /I. /Zm /c /Ta test.asm
Microsoft (R) Macro Assembler Version 6.11c
Copyright (C) Microsoft Corp 1981-1994. All rights reserved.
Assembling: test.asm
F:\EzNet>link test.obj
Microsoft (R) Segmented Executable Linker Version 5.31.009 Jul 13 1992
Copyright (C) Microsoft Corp 1984-1992. All rights reserved.
Run File [test.exe]:
List File [nul.map]:
Libraries [.lib]:
Definitions File [nul.def]:
test.obj(test.asm) : warning L4020: _TEXT : code-segment size exceeds 64K-36
LINK : warning L4021: no stack segment
F:\EzNet>exe2bin test.exe test.bin
Insufficient memory
exe2bin can't change test.exe to test.bin.
I need the file's size is 64K.
so, I think it is impossilbe to create bin file which size is 64k using MASM.
who know other good idea.
I know it maybe done using NASM.
But i must using MASM in my company .
Thanks.
Last edited by david on Tue May 06, 2008 8:34 am, edited 1 time in total.
Just For Fun
- Combuster
- Member
- Posts: 9301
- Joined: Wed Oct 18, 2006 3:45 am
- Libera.chat IRC: [com]buster
- Location: On the balcony, where I can actually keep 1½m distance
- Contact:
For what company are you working that enforces this assembler, and assembly in general. Especially with this kind of dated software.david wrote:But i must using MASM in my company.
If there's a good reason for using these tools, then you should be able to ask your fellow colleagues during a coffee break how they would solve such a problem.
Code: Select all
#include <stdio.h>
#define FILE_SIZE 64*1024 // 64KB
int main (char argc, char **argv)
{
FILE *in = fopen(argv[1], "rb");
FILE *out = fopen(argv[2], "wb");
if (!in || !out)
{
fprintf(stderr, "File open error!\n");
exit(1);
}
unsigned long i;
char buffer;
for (i = 0; i < FILE_SIZE; i++)
{
if (!fread(&buffer, 1, 1, in))
buffer = '\0';
fwrite(&buffer, 1, 1, out);
}
exit(0);
}
Code: Select all
$ gcc -o test test.c
test.c: In function ‘main’:
test.c:18: warning: incompatible implicit declaration of built-in function ‘exit’
test.c:38: warning: incompatible implicit declaration of built-in function ‘exit’
$ echo "Howay the lads" >test.in
$ ./test test.in test.out
$ cat test.out
Howay the lads
$ ls -l test.out
-rw-r--r-- 1 james james 65536 2008-05-05 10:48 test.out
[quote]
org 65535 ; 64 * 1024 -1
db 0
[quote]
Wouldn't this place a zeroed byte after the 64k file? That would make the on-disk size 64.5k, whereas:
Should create a 64k file (disclaimer: I don't know MASM).
Cheers,
Adam
org 65535 ; 64 * 1024 -1
db 0
[quote]
Wouldn't this place a zeroed byte after the 64k file? That would make the on-disk size 64.5k, whereas:
Code: Select all
org 65534
db 0
Cheers,
Adam
What does this assemble too ?
If it will allow it.
Code: Select all
.model tiny
.code
.386
start:
xor ax, ax
org 1024
org 64511
db 0
org 64511Dex wrote:What does this assemble too ?If it will allow it.Code: Select all
.model tiny .code .386 start: xor ax, ax org 1024 org 64511 db 0
db 0
The byte's offset is 64511, not (64511 + 1024).
Just For Fun
to JamesM
I have made a tool to extend a file to 64K if the file's size is not 64K.
But I don't want to use it after I make the binary file everytime.
I want to make the binary file like this:
1 program
2 compile
3 link
then, the binary file's size is 64K.
Perhaps I am lazy,
Thanks!
I have made a tool to extend a file to 64K if the file's size is not 64K.
But I don't want to use it after I make the binary file everytime.
I want to make the binary file like this:
1 program
2 compile
3 link
then, the binary file's size is 64K.
Perhaps I am lazy,
Thanks!
Last edited by david on Tue May 06, 2008 8:32 am, edited 1 time in total.
Just For Fun