Here's my code (it's a lot, I know). I have not implemented the function for printing the screen yet:
[GLOBAL mystart] [EXTERN _printf] [EXTERN _atoi] ;define constants for buffer size and interupt %define DOS 0f1h %define INBUFFSIZE 40 %define FILEBUFFSIZE 4096 ;define macro for printing on screen %macro printLn 1 mov ah, 09h mov edx, %1 int DOS %endmacro [SECTION .text] mystart: readFile: ;prints "Enter the filename: " on screen printLn string ;takes filename from user mov ah, 0Ah mov byte [infile], INBUFFSIZE mov byte [infile+1], 0 mov edx, infile int DOS ;pads filename string with 0 movzx ecx, byte [infile+1] mov byte [infile+ecx+2], 0 ;opens the file (read mode) mov ah, 3Dh mov al, 0 mov edx, infile+2 int DOS mov [inhandle], ax jc failureJump ;reads the file mov ah, 3Fh mov bx, [inhandle] mov edx, filebuff mov cx, FILEBUFFSIZE int DOS jc failureJump printLn string3 mov [nbytes], ax ;nbytes stores the number of bytes in the file, so that we can loop through it ;prepare for looping through characters mov ecx, 0 mov cl, [nbytes] mov ebx, 0 ; I want to see how many bytes are in the file printLn ecx processFile: printLn string4 jmp endProcess failureJump: printLn string2 endProcess: ret [SECTION .data] string db "Enter a filename: ", 13, 10, '$' string2 db "Found a dot!", 13, 10, '$' string3 db "First break!", 13, 10, '$' string4 db "Second break!", 13, 10, '$' string5 db "Third break!", 13, 10, '$' [SECTION .bss] infile: resb 512 filebuff: resb FILEBUFFSIZE inhandle: resw 1 nbytes: resw 1 nbytes2: resw 1
So as you can see, I have a couple break-strings and jc failureJumps in the code just to see where it's getting to. As it stands, the code does not work. Upon execution, it asks for the filename, but fails after first break, with a long error "Exiting due to signal SIGSEGV", among other things. It also mentions that the ecx register has the value ffffffff. If I comment out the "printLn ecx" line, the program seems to work (it gets to "Second break!"), though sluggishly, and I have no hard evidence that it is reading the file correctly (I do have a file for this: myfile.txt). Does anyone know what I'm doing wrong? Thanks in advance!