:biggrin: Yes i want to share this program because this forum is a good place and i want to contribute in some how. :icon14:
This time i use processor instructions, trying not to use assembler directives apart for the very basic. Is just some kind of exercise of course. But it's commented and may help beginners like me (right?), to have a little of invokes and protos and offsets in some programs, and in others to have calls and lea, or whatever instruction that can do the same, than this one (lea), than is more efficient (but not an assembler directive i mean. And, for now i don't know one).
Well the program do too little and will not check anything. Here is an example of good entries for it:
for the first prompt: c:\masm32\include\windows.inc
for the second: c:\users\felipe\desktop\w.txt (of course you have to write other one here. Well probably. Your name is not Felipe, right?) :lol:.
(Try other entries of course).
Have a look if you want (especially if you are a beginner) and comment, if you want to.
.386
.model flat,stdcall
option casemap:none
include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
includelib \masm32\lib\kernel32.lib
.data?
hconsoleinput dd ?
hconsoleoutput dd ?
charsset dd ?
charsread dd ?
charswrite dd ?
strsize dd ?
.data
progname db "Copy a file",0
copyoffile db 100 dup(" "),0
originfile db 100 dup(" "),0
inbuf db 256 dup(" "),0
str1 db "Enter the path ",0ah,0dh
db 5 dup(20h),"of the file you want to copy: ",0
str2 db "Enter the path",0ah,0dh
db 5 dup(20h),"you want for the copy of the file: ",0
.code
main proc
call AllocConsole ; Allocate a console for us.
push STD_OUTPUT_HANDLE
call GetStdHandle ; Give us the handle for writing in the console.
mov hconsoleoutput,eax
push STD_INPUT_HANDLE
call GetStdHandle ; The same but now for reading.
mov hconsoleinput,eax
lea eax,progname
push eax
call SetConsoleTitle ; Put a title to the console title's bar.
push 0
push 0
call painbac ; Paint the background to blue.
push 0
push 0
call curspos ; Set the cursor location.
push FOREGROUND_GREEN or FOREGROUND_INTENSITY or BACKGROUND_BLUE
push hconsoleoutput
call SetConsoleTextAttribute ; The foreground color.
push 5
push 5
call curspos ; Cursor moves to here.
mov strsize,52
lea ecx,str1
call write ; For writing to the user.
mov strsize,256
call read ; To read their input.
lea edi,originfile
call movestr ; We move what he just wrote.
mov byte ptr[edi],0 ; We end that string with a null.
push 9
push 5
call curspos ; The cursor moves down.
mov strsize,56
lea ecx,str2
call write ; We write.
mov strsize,256
call read ; We read the user input.
lea edi,copyoffile
call movestr ; We move what he wrote.
mov byte ptr[edi],0 ; And we add a null to the end of that string.
lea eax,copyoffile
push eax ; Pointer to the new file (the copy).
lea eax,originfile
push eax ; Pointer to the old file (the one copied).
call CopyFile ; Copies the file.
call FreeConsole ; We dont need the console anymore.
push 0
call ExitProcess ; Terminates this simple and improveable program.
main endp
curspos proc col:word,row:word ; Moves the cursor to col and row of the console.
local cc:COORD
mov ax,col
mov cc.x,ax
mov ax,row
mov cc.y,ax
mov eax,cc
push eax
push hconsoleoutput
call SetConsoleCursorPosition
ret
curspos endp
painbac proc colx:word,rowy:word ; Paints all from colx and rowx.
local cc:COORD
mov ax,colx
mov cc.x,ax
mov ax,rowy
mov cc.y,ax
mov eax,cc
push offset charsset
push eax
push 30000
push BACKGROUND_BLUE or FOREGROUND_BLUE
push hconsoleoutput
call FillConsoleOutputAttribute
ret
painbac endp
write proc ; Console output.
push NULL
lea eax,charswrite
push eax
push strsize
push ecx
push hconsoleoutput
call WriteConsole
ret
write endp
read proc ; Console input.
push NULL
lea eax,charsread
push eax
push strsize
lea eax,inbuf
push eax
push hconsoleinput
call ReadConsole
ret
read endp
movestr proc ; We move the input buffer content to some
lea esi,inbuf ; other buffer.
cld
xor ebx,ebx
until:
cmp byte ptr[esi],0ah
je fin
cmp byte ptr[esi],0dh
je fin
movsb
inc ebx
jmp until
fin:
ret
movestr endp
end main