flat assembler
Message board for the users of flat assembler.
Index
> Main > Program too large for memory Goto page 1, 2 Next |
Author |
|
Picnic 11 Oct 2012, 15:06
Hi,
Try with a null-terminated string. Code: File_CH16 db 'C:/fasm/hello.txt',0 |
|||
11 Oct 2012, 15:06 |
|
sbeng 12 Oct 2012, 17:57
Ok now i'm writing an exe program that need to read a simple txt file, open it and print OK or ERROR message.
When i execute it (on a Windows Vista dos window) it does appears below message: "example.COM The NTVDM CPU has encountered an illegal istrction". My code is correct? Best regards. Code: format MZ READ_ROM: ;read file and save content in memory array mov AH,3Dh mov AL,0; readfile mov DX,File_CH16 int 21h mov [HANDLE16],AX jc PRINT_STATUS_KO jmp PRINT_STATUS_OK jmp CLOSE_ROM JMP END_PROCESS CLOSE_ROM: mov AH,3EH mov BX,HANDLE16 int 21H PRINT_STATUS_OK: mov dx,OK mov ah,09h int 21h PRINT_STATUS_KO: mov dx,Error_String mov ah,09h int 21h END_PROCESS: HANDLE16 DW 0 File_CH16 db 'C:\download\test\ciao.txt',0 Error_String db 'Errore=$',0 OK db 'OK$',0 |
|||
12 Oct 2012, 17:57 |
|
Picnic 12 Oct 2012, 21:19
Some quick observations,
END_PROCESS needs some exit code, usually it's Code: mov ax, 004Ch int 21h jump to PRINT_STATUS_OK will display also PRINT_STATUS_KO -it probably will crash since it's missing the exit routine- 'jmp CLOSE_ROM' and 'JMP END_PROCESS' never be executed. [HANDLE16] needs brackets at CLOSE_ROM subroutine. It may be easier if you split code into small routines. Here is a simple example, originally posted by rCX. Code: include "c:\fasm\include\macro\if.inc" MAX_FILE_SIZE = 1024 org 100h call open_file .if ( CARRY? ) mov dx, error_open call print_text jmp exit .endif mov [handle], ax call read_file .if ( CARRY? ) mov dx, error_read call print_text call close_file jmp exit .endif mov di, ax add di, filedata mov al, '$' cld stosb mov dx, filedata call print_text call close_file exit: mov ax, 4c00h int 21h print_text: push ax mov ah, 09h int 21h pop ax ret open_file: push dx mov ah, 3Dh mov al, 00h mov dx, filename int 21h pop dx ret read_file: push bx cx dx mov bx, [handle] mov ah, 3Fh mov cx, MAX_FILE_SIZE mov dx, filedata int 21h pop dx cx bx ret close_file: push bx mov ah, 3Eh mov bx, [handle] int 21h pop bx ret handle dw ? filename db "C:\download\test\ciao.txt",0 error_open db "File not found.$" error_read db "Can't read file.$" filedata rb MAX_FILE_SIZE+1 if you like to output null-terminated strings you have to write your own print_text routine. Here is a very simple one, written on the fly. Code: print_text: push ax cx mov cx, MAX_FILE_SIZE mov ah, 0Eh cld @@: lodsb test al, al jz @F int 10h loop @B @@: pop cx ax ret In order to use it, dx must be replaced by si, these are the changes that must be made. Code: ;mov dx, error_open mov si, error_open ; ; ;mov dx, error_read mov si, error_read ; ; ;mov al, '$' mov al, 0 ; ; ;mov dx, filedata mov si, filedata ; ; error_open db "File not found.",0 error_read db "Can't read file.",0 |
|||
12 Oct 2012, 21:19 |
|
sbeng 13 Oct 2012, 08:32
EDIT
Hi, thank you for your replies. I've modified my code. Now i've resolved NTVDM error but during execute my program it does not show Error_String for path error. Code: format MZ entry main:start ; program entry point stack 100h ; stack size segment main ; main program segment start: ;read file and save content in memory array call OPEN_FILE jc PRINT_STATUS_KO mov [HANDLE16],AX call PRINT_STATUS_OK segment text HANDLE16 DW 0 File_CH16 db 'C:\download\test\ciaao.txt$' Error_String db 'Errore$' OK db 'OK$' segment extra OPEN_FILE: push dx mov ah, 3Dh mov al, 00h mov dx, File_CH16 int 21h pop dx ret CLOSE_ROM: push bx mov ah, 3Eh mov bx, [HANDLE16] int 21h pop bx ret PRINT_STATUS_OK: mov dx,OK call extra:write_text call extra:CLOSE_ROM jmp END_PROCESS PRINT_STATUS_KO: mov dx,Error_String call extra:write_text call extra:CLOSE_ROM jmp END_PROCESS END_PROCESS: mov ax,4Ch int 21h write_text: push ax mov ah, 09h int 21h pop ax ret Last edited by sbeng on 13 Oct 2012, 08:52; edited 1 time in total |
|||
13 Oct 2012, 08:32 |
|
revolution 13 Oct 2012, 08:39
You will need to use ret, instead of retf.
|
|||
13 Oct 2012, 08:39 |
|
sinsi 14 Oct 2012, 02:08
An EXE is segmented, you need to set up at least DS
Code: start: mov ax,text mov ds,ax |
|||
14 Oct 2012, 02:08 |
|
sbeng 14 Oct 2012, 08:00
Now is my updated code. Why it doesn't print error message?
It does not show CPU error but it does show only a cursor. Thank you for your patience: Code: format MZ entry main:start ; program entry point stack 100h ; stack size segment main ; main program segment start: mov ax,text mov ds,ax ;read file and save content in memory array call OPEN_FILE jc PRINT_STATUS_KO mov [HANDLE16],AX call PRINT_STATUS_OK segment text HANDLE16 DW 0 File_CH16 db "C:\download\test\ciaao.txt",0 Error_String db "Errore$" OK db "OK$" segment extra OPEN_FILE: push dx mov ah, 3Dh mov al, 00h mov dx, File_CH16 int 21h pop dx ret CLOSE_ROM: push bx mov ah, 3Eh mov bx, [HANDLE16] int 21h pop bx ret PRINT_STATUS_OK: mov dx,OK call write_text call CLOSE_ROM jmp END_PROCESS PRINT_STATUS_KO: mov dx,Error_String call write_text call CLOSE_ROM jmp END_PROCESS END_PROCESS: mov ax,4Ch int 21h write_text: push ax mov ah, 09h int 21h pop ax ret |
|||
14 Oct 2012, 08:00 |
|
revolution 14 Oct 2012, 08:29
Something like this might be suitable:
Code: format MZ entry main:start ; program entry point stack 100h ; stack size segment main ; main program segment start: mov ax,text mov ds,ax ;read file and save content in memory array call OPEN_FILE jc PRINT_STATUS_KO mov [HANDLE16],AX call PRINT_STATUS_OK jmp END_PROCESS OPEN_FILE: push dx mov ah, 3Dh mov al, 00h mov dx, File_CH16 int 21h pop dx ret CLOSE_ROM: push bx mov ah, 3Eh mov bx, [HANDLE16] int 21h pop bx ret PRINT_STATUS_OK: mov dx,OK call write_text call CLOSE_ROM jmp END_PROCESS PRINT_STATUS_KO: mov dx,Error_String call write_text call CLOSE_ROM jmp END_PROCESS END_PROCESS: mov ax,4Ch int 21h write_text: push ax mov ah, 09h int 21h pop ax ret segment text HANDLE16 DW 0 File_CH16 db "C:\download\test\ciaao.txt",0 Error_String db "Errore$" OK db "OK$" |
|||
14 Oct 2012, 08:29 |
|
sbeng 15 Oct 2012, 13:16
Sorry for my bad coding
Now i've modified my code but it doesn't appear no Error_String text. Code: format MZ entry main:start ; program entry point segment main ; main program segment include "c:\download\fasm\include\macro\if.inc" start: mov ax,text mov ds,ax ;read file and save content in memory array call OPEN_FILE .if ( CARRY? ) mov dx,Error_String call write_text call CLOSE_ROM jmp END_PROCESS .endif mov [HANDLE16], ax call CLOSE_ROM END_PROCESS: mov ax,4Ch int 21h segment extra OPEN_FILE: push dx mov ah, 3Dh mov al, 00h mov dx, filename int 21h pop dx ret CLOSE_ROM: push bx mov ah, 3Eh mov bx, [HANDLE16] int 21h pop bx ret PRINT_STATUS_OK: mov dx,OK call write_text call CLOSE_ROM call END_PROCESS ret PRINT_STATUS_KO: mov dx,Error_String call write_text call CLOSE_ROM call END_PROCESS ret write_text: push ax mov ah, 09h int 21h pop ax ret segment text HANDLE16 DW 0 filename db "C:\download\test\ciaao.txt",0 Error_String db "Errore$" OK db "OK$" |
|||
15 Oct 2012, 13:16 |
|
revolution 15 Oct 2012, 13:18
Try removing the "segment extra" line.
|
|||
15 Oct 2012, 13:18 |
|
sbeng 15 Oct 2012, 13:28
revolution wrote: Try removing the "segment extra" line. Removing this line, executing my code it does appear a crash |
|||
15 Oct 2012, 13:28 |
|
ctl3d32 15 Oct 2012, 14:12
null terminate your strings
|
|||
15 Oct 2012, 14:12 |
|
sbeng 16 Oct 2012, 12:00
Nothing
My code does show only cursor and doesn't write nothing. What is difference between call and jump. Thank you for all! Code: format MZ entry main:start ; program entry point segment main ; main program segment include "c:\download\fasm\include\macro\if.inc" start: mov ax,text mov ds,ax ;read file and save content in memory array call OPEN_FILE .if ( CARRY? ) mov dx,Error_String call write_text call CLOSE_ROM jmp END_PROCESS .endif mov [HANDLE16], ax call CLOSE_ROM END_PROCESS: mov ax,4Ch int 21h segment extra OPEN_FILE: push dx mov ah, 3Dh mov al, 00h mov dx, filename int 21h pop dx ret CLOSE_ROM: push bx mov ah, 3Eh mov bx, [HANDLE16] int 21h pop bx ret PRINT_STATUS_OK: mov dx,OK call write_text call CLOSE_ROM call END_PROCESS ret PRINT_STATUS_KO: mov dx,Error_String call write_text call CLOSE_ROM call END_PROCESS ret write_text: push ax mov ah, 09h int 21h pop ax ret segment text HANDLE16 DW 0 filename db "C:\download\test\ciaao.txt",0 Error_String db "Errore",0 OK db "OK",0 |
|||
16 Oct 2012, 12:00 |
|
revolution 16 Oct 2012, 12:10
Remove the "segment extra" line for a start. Then try with the different string formats. Start simple with a "hello world!" and work up from there.
|
|||
16 Oct 2012, 12:10 |
|
AsmGuru62 16 Oct 2012, 12:38
@sbeng:
1. How important is it for you to have a multi-segmented EXE program? COM file would be so much simpler in this case. Or you're preparing to code a very large program? I am asking, because with a COM file you still can code a program, where data (but not code) may take as much as 500Kb or so. Code however is limited to 64Kb minus (global variables + PSP), however you would be surprised how much of a functionality can be fit into that room. A lot! If I recall, Philippe Kahn (founder of Borland) has coded a full Pascal Compiler into a COM file! 2. What exactly are you trying to do? You open file, then what? Do you need read the file anywhere? Show it on console? Count any characters in that file? What exactly do you need? 3. Watch out for string termination. When you need to PRINT the text with (AH=9h / INT 21h) - the text MUST be terminated with a dollar character, like so: OK db 'OK$' However, any file names are to be terminated by a zero byte. So, terminators are different in case of file names and text to be printed on console. |
|||
16 Oct 2012, 12:38 |
|
sbeng 16 Oct 2012, 13:44
AsmGuru62 wrote: @sbeng: OK, now i will use COM format so i can to focus only functions of my code. I would write some example in ASM (FASM) to improve my ASM knowledge. In this case, i want load a file (txt or binary), if i doesn't find it i need to print a message otherwise i could open it. |
|||
16 Oct 2012, 13:44 |
|
sbeng 16 Oct 2012, 14:17
Ok i have win
Now my code does print "OK", but if you modify path it does print "Errore". Thank you for all! Code: org 100h start: include "c:\download\fasm\include\macro\if.inc" ;read file and save content in memory array call OPEN_FILE .if ( CARRY? ) mov dx,Error_String call PRINT_STATUS_KO .endif mov [HANDLE16], ax call PRINT_STATUS_OK END_PROCESS: mov ax,4Ch int 21h ret OPEN_FILE: mov ah, 3Dh mov al, 00h mov dx, filename int 21h ret CLOSE_ROM: mov ah, 3Eh mov bx, [HANDLE16] int 21h ret PRINT_STATUS_OK: mov dx,OK call write_text call CLOSE_ROM call END_PROCESS ret PRINT_STATUS_KO: mov dx,Error_String call write_text call CLOSE_ROM call END_PROCESS ret write_text: mov ah, 09h int 21h ret HANDLE16 DW 0 filename db "C:\download\test\ciao.txt",0 Error_String db "Errore$" OK db "OK$" |
|||
16 Oct 2012, 14:17 |
|
AsmGuru62 16 Oct 2012, 15:30
Status KO reminds me of old Arcade games where you can play Street Fighter and get KO-ed. Also, that scene from "BloodSport" where Frank Dux played with the big biker guy. Sweet! |
|||
16 Oct 2012, 15:30 |
|
sbeng 20 Oct 2012, 09:47
Hi,
now i would read file content I'm reading interrupt docs: Quote:
So, i've written this code also copying rCX post Quote:
What means stosb instruction? Best regards. |
|||
20 Oct 2012, 09:47 |
|
Goto page 1, 2 Next < Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.