Topshiriqlar. Berilgan topshiriqlarga mos 16- va 32-bitli dasturlar tuzilsin va dastur natijalari tahlili hisobotda talab qilingan bandlar bo‘yicha yozma shaklda keltirilsin.
Topshiriqlar
Ekranda matn hosil qiluvchi konsol ilovali dastur tuzilsin.
Asmp fayl Kodi:
include win64a.inc
MAXSCREENX = 80
MAXSCREENY = 25
.code
WinMain proc
local hIn:qword
local hOut:qword
local hFile:qword
local result:qword
local FileSize:qword
local hMem:qword
local ConsoleWindow:SMALL_RECT
local cci:CONSOLE_CURSOR_INFO
local MOUSE_KEY:INPUT_RECORD
push rbp
mov ebp,esp
sub esp,(38h+6*8+sizeof SMALL_RECT+\
sizeof CONSOLE_CURSOR_INFO+INPUT_RECORD+15)and(-16)
xor ebx,ebx
call FreeConsole
call AllocConsole
mov [rsp+30h],rbx ;it has to be equal to zero
mov [rsp+28h],rbx ;attribute of the file (if we create it)
mov qword ptr [rsp+20h],OPEN_EXISTING;how to open the file
xor r8d,r8d ;mode of the general access
xor r9d,r9d ;the index on security attr
mov edx,GENERIC_READ or GENERIC_WRITE;access mode
mov ecx,offset filenameIn ;file name
call CreateFile
mov hIn,rax ; hConsoleInput
mov [rsp+30h],rbx ;it has to be equal to zero
mov [rsp+28h],rbx ;attribute of the file (if we create it)
mov qword ptr [rsp+20h],OPEN_EXISTING;how to open the file
xor r8d,r8d ;mode of the general access
xor r9d,r9d ;the index on security attr
mov edx,GENERIC_READ or GENERIC_WRITE;access mode
mov ecx,offset filenameOut ;file name
call CreateFile
mov hOut,rax
mov rcx,rax ; hConsoleOutput
call GetLargestConsoleWindowSize
; eax return in 31-16 bits: dwCoord.y
; 15-00 bits: dwCoord.x
lea r8d,ConsoleWindow ;lpConsoleWindow
mov [r8],ebx
; lpConsoleWindow.Left = 0 lpConsoleWindow.Top = 0
sub ax, MAXSCREENX
sbb edx, edx
and ax, dx
add ax, MAXSCREENX-1
mov [r8+SMALL_RECT.Right],ax
shr eax, 16
sub eax, MAXSCREENY
sbb edx, edx
and eax, edx
add eax, MAXSCREENY-1
mov [r8+SMALL_RECT.Bottom],ax
mov edx,TRUE ; bAbsolute
mov rcx,hOut ; hConsoleOutput
call SetConsoleWindowInfo
mov ecx,offset ConsoleTitle
call SetConsoleTitle
;hide cursor----------------------------------------
lea edx,cci ; lpConsoleCursorInfo
mov rcx,hOut ; hConsoleOutput
call GetConsoleCursorInfo
lea edx,cci ; lpConsoleCursorInfo
mov [rdx+CONSOLE_CURSOR_INFO.bVisible],ebx;FALSE
mov rcx,hOut ; hConsoleOutput
call SetConsoleCursorInfo
;------------------------------------------------------
mov [rsp+30h],rbx ;it has to be equal to zero
mov [rsp+28h],rbx ;attribute of the file (if we create it)
mov qword ptr [rsp+20h],OPEN_EXISTING;how to open the file
xor r8d,r8d ;mode of the general access
xor r9d,r9d ;the index on security attr
mov edx,GENERIC_READ or GENERIC_WRITE;access mode
mov ecx,offset filename ;file name
call CreateFile ;to open the file
inc eax;cmp eax,-1
jz EXIT
dec eax
mov hFile,rax
xor edx,edx ;0
mov rcx,rax ;hFile
call GetFileSize
mov FileSize,rax
mov rdx,rax
mov ecx,GMEM_FIXED or GMEM_ZEROINIT
call GlobalAlloc
mov hMem,rax
mov [rsp+20h],rbx
lea r9d,result
mov r8,FileSize
mov rdx,rax ;hMem
mov rcx,hFile
call ReadFile ;to read in the buffer
mov [rsp+20h],rbx
lea r9d,result
mov r8,FileSize
mov rdx,hMem
mov rcx,hOut
call WriteConsole ;to bring buffer contents to the console
mov rcx,hFile
call CloseHandle ;to close the file
;--------------------------------------------------------
mov [rsp+20h],rbx
lea r9d,result
mov r8d,sizeof Str2
mov edx,offset Str2
mov rcx,hOut
call WriteConsole ;to bring Str2 to the console
;--------------------------------------------------------
@@: lea r9d,result
mov r8d,1
lea edx,MOUSE_KEY
mov rcx,hIn
call ReadConsoleInput
lea eax,MOUSE_KEY
cmp [rax+INPUT_RECORD.EventType],MOUSE_EVENT
je @b
cmp [rax+INPUT_RECORD.EventType],KEY_EVENT
jne @b
cmp [rax+INPUT_RECORD.KeyEvent.wVirtualKeyCode],VK_ESCAPE
jne @b
EXIT: call FreeConsole
xor ecx,ecx
call ExitProcess
WinMain endp
ConsoleTitle db 'Output to the console of text file contents. Second variant.',0
Str2 db 0Dh,0Ah,'For exit press ESC or CTRL+C or CTRL+Break'
filename db 'c09.asm',0
filenameOut db 'CONOUT$',0
filenameIn db 'CONIN$',0
end
Do'stlaringiz bilan baham: |