RAČUNARSKA ELEKTRONIKA VEŽBE 4

Size: px
Start display at page:

Download "RAČUNARSKA ELEKTRONIKA VEŽBE 4"

Transcription

1 RAČUNARSKA ELEKTRONIKA VEŽBE 4 Aleksandra Lekić lekic.aleksandra@etf.bg.ac.rs Elektrotehnički fakultet, Univerzitet u Beogradu 2016/2017 ETF Beograd RE VEŽBE / / 47

2 MS-Windows Programianje Radi kao 16-bitno MS-DOS u tekstualnom modu. Biblioteka Irvine32.inc sadrži podršku za standardne MS-Windows funkcije. Postoji podrška za: čitanje sa standardnog ulaza ispis na standardni izlaz ispis teksta u boji Radi sa 8-bitnim ASCII i 16-bitnim Unicode setom karaktera. Objašnjenje biblioteke Irvine 2Fabout.htm ETF Beograd RE VEŽBE / / 47

3 Console Handle procedure Function GetStdHandle ReadConsole WriteConsole Description Retrieves a handle for the standard input, standard output, or standard error device. Reads character input from the console input buffer and removes it from the buffer. Writes a character string to a console screen buffer beginning at the current cursor location. ETF Beograd RE VEŽBE / / 47

4 Console Handle procedure Write Message Write Message MessageBoxA PROTO, hwnd:dword, ; handle to window (can be null) lptext:ptr BYTE, ; string, inside of box lpcaption:ptr BYTE, ; string, dialog box title utype:dword ; contents and behavior Write Message utype - MB_OK, MB_OKCANCEL, MB_YESNO, MB_YESNOCANCEL, MB_RETRYCANCEL, MB_ABORTRETRYIGNORE i MB_CANCELTRYCONTINUE. ETF Beograd RE VEŽBE / / 47

5 Console Handle procedure 1 ; Demonstrate MessageBoxA (MessageBox.asm) 2 INCLUDE Irvine32.inc 3 4.data 5 captionw BYTE "Warning",0 6 warningmsg BYTE "The current operation may take years to complete.",0 7 captionq BYTE "Question",0 8 questionmsg BYTE "A matching user account was not found." 9 BYTE 0dh,0ah,"Do you wish to continue?",0 10 captionc BYTE "Information",0 11 infomsg BYTE "Select Yes to save a backup file before continuing,",0dh,0ah 12 BYTE "or click Cancel to stop the operation",0 13 captionh BYTE "Cannot View User List",0 14 haltmsg BYTE "This operation not supported by your user account.", code 17 main PROC 18 ; Display Exclamation icon with OK button 19 INVOKE MessageBox, NULL, ADDR warningmsg, ADDR captionw, 20 MB_OK + MB_ICONEXCLAMATION 21 ; Display Question icon with Yes/No buttons 22 INVOKE MessageBox, NULL, ADDR questionmsg, 23 ADDR captionq, MB_YESNO + MB_ICONQUESTION 24 ; interpret the button clicked by the user 25 cmp eax,idyes ; YES button clicked? 26 ; Display Information icon with Yes/No/Cancel buttons 27 INVOKE MessageBox, NULL, ADDR infomsg, 28 ADDR captionc, MB_YESNOCANCEL + MB_ICONINFORMATION + MB_DEFBUTTON2 29 ; Display stop icon with OK button 30 INVOKE MessageBox, NULL, ADDR haltmsg, ADDR captionh, MB_OK + MB_ICONSTOP 31 exit 32 main ENDP 33 END main ETF Beograd RE VEŽBE / / 47

6 Console Input Console Input Read Console ReadConsole PROTO, hconsoleinput:handle, ; input handle lpbuffer:ptr BYTE, ; pointer to buffer nnumberofcharstoread:dword, ; number of chars to read lpnumberofcharsread:ptr DWORD, ; ptr to num bytes read lpreserved:dword ; (not used) Read Console Čita podatak sa standardnog ulaza i stavlja ga u bafer. ETF Beograd RE VEŽBE / / 47

7 Console Input 1 ; Read From the Console (ReadConsole.asm) 2 3 ; Read a line of input from standard input. 4 5 INCLUDE Irvine32.inc 6 7 BufSize = data 10 buffer BYTE BufSize DUP(?) 11 stdinhandle HANDLE? 12 bytesread DWORD? code 15 main PROC 16 ; Get handle to standard input 17 INVOKE GetStdHandle, STD_INPUT_HANDLE 18 mov stdinhandle,eax ; Wait for user input 21 INVOKE ReadConsole, stdinhandle, ADDR buffer, 22 BufSize, ADDR bytesread, ; Display the buffer 25 mov esi,offset buffer 26 mov ecx,bytesread 27 mov ebx,type buffer 28 call DumpMem exit 31 main ENDP 32 END main ETF Beograd RE VEŽBE / / 47

8 Console Input Keyboard procedure ReadChar - čeka se da se ukuca karakter u ASCII kodu na tastaturi i upisuje se u AL registar. ReadKey - ne čeka na karakter. Ako nema karaktera setuje se zero flag, a ako postoji karakter zero flag nije setovan. U tom se slučaju upisuje u registar AL karakter ili nula. Gornje polovine registara EAX i EDX su prepisane. ETF Beograd RE VEŽBE / / 47

9 Console Input 1 ; Testing ReadKey (TestReadkey.asm) INCLUDE Irvine32.inc 5 INCLUDE Macros.inc 6 7.code 8 main PROC 9 10 L1: mov eax,10 ; delay for msg processing 11 call Delay 12 call ReadKey ; wait for a keypress 13 jz L test ebx,capslock_on 16 jz L2 17 mwrite <"CapsLock is ON",0dh,0ah> 18 jmp L L2: mwrite <"CapsLock is OFF",0dh,0ah> L3: exit 23 main ENDP 24 END main ETF Beograd RE VEŽBE / / 47

10 Console Input Čitanje stanja tastature Program testira vrednost registra EAX prema tabeli: ETF Beograd RE VEŽBE / / 47

11 Console Input 1 ; Keyboard Toggle Keys (Keybd.asm) 2 3 ; This program shows how to detect the states of various 4 ; keyboard toggle keys. Before you run the program, hold 5 ; down a selected key. 6 7 INCLUDE Irvine32.inc 8 INCLUDE Macros.inc 9 10 ; GetKeyState sets bit 0 in EAX if a toggle key is 11 ; currently on (CapsLock, NumLock, ScrollLock). 12 ; It sets the high bit of EAX if the specified key is 13 ; currently down code 16 main PROC INVOKE GetKeyState, VK_NUMLOCK 19 test al,1 20.IF!Zero? 21 mwrite <"The NumLock key is ON",0dh,0ah> 22.ENDIF INVOKE GetKeyState, VK_LSHIFT 25 call DumpRegs 26 test eax, h 27.IF!Zero? 28 mwrite <"The Left Shift key is currently DOWN",0dh,0ah> 29.ENDIF exit 32 main ENDP 33 END main ETF Beograd RE VEŽBE / / 47

12 Console Output Console Output WriteConsole WriteConsole PROTO, hconsoleoutput:handle, lpbuffer:ptr BYTE, nnumberofcharstowrite:dword, lpnumberofcharswritten:ptr DWORD, lpreserved:dword ETF Beograd RE VEŽBE / / 47

13 Console Output 1 ; Win32 Console Example #1 (Console1.asm) 2 ; This program calls the following Win32 Console functions: 3 ; GetStdHandle, ExitProcess, WriteConsole 4 INCLUDE Irvine32.inc 5 6.data 7 endl EQU <0dh,0ah> ; end of line sequence 8 9 message LABEL BYTE 10 BYTE "This program is a simple demonstration of " 11 BYTE "console mode output, using the GetStdHandle " 12 BYTE "and WriteConsole functions.", endl 13 messagesize DWORD ($ message) consolehandle HANDLE 0 ; handle to standard output device 16 byteswritten DWORD? ; number of bytes written code 19 main PROC 20 ; Get the console output handle: 21 INVOKE GetStdHandle, STD_OUTPUT_HANDLE 22 mov consolehandle,eax ; Write a string to the console: 25 INVOKE WriteConsole, 26 consolehandle, ; console output handle 27 ADDR message, ; string pointer 28 messagesize, ; string length 29 ADDR byteswritten, ; returns num bytes written 30 0 ; not used INVOKE ExitProcess,0 33 main ENDP 34 END main ETF Beograd RE VEŽBE / / 47

14 Console Output Console Output WriteConsoleOutputCharacter WriteConsoleOutputCharacter PROTO, hconsoleoutput:handle, ; console output handle lpcharacter:ptr BYTE, ; pointer to buffer nlength:dword, ; size of buffer dwwritecoord:coord, ; first cell coordinates lpnumberofcharswritten:ptr DWORD ; output count Ako tekst dođe do kraja reda, prelomi se u novi. Ako funkcija ne može da ispiše karaktere (npr. tab), vraća nulu. ETF Beograd RE VEŽBE / / 47

15 Čitanje i upis u fajlove Kreiranje fajla Create File CreateFile PROTO, ; create new file lpfilename:ptr BYTE, ; ptr to filename dwdesiredaccess:dword, ; access mode dwsharemode:dword, ; share mode lpsecurityattributes:dword, ; ptr security attrib dwcreationdisposition:dword, ; file creation options dwflagsandattributes:dword, ; file attributes htemplatefile:dword ; handle to template file ETF Beograd RE VEŽBE / / 47

16 Čitanje i upis u fajlove Parametri prilikom kreiranja fajla ETF Beograd RE VEŽBE / / 47

17 Čitanje i upis u fajlove Parametri prilikom kreiranja fajla dwdesiredaccess Specificira pristup čitanja fajla i upisa u fajl. Može imati vrednosti: 0 - za proveru da li fajl postoji ili prosleđivanje osobina bez pristupa fajlu, GENERIC_READ - fajl namenjen čitanju, GENERIC_WRITE - fajl namenjen upisu. Za upis/čitanje se koristi GENERIC_READ kombinovano sa GENERIC_WRITE. dwcreationdisposition Podrazumeva akciju koju treba sprovesti nad fajlom: CREATE_NEW, CREATE_ALWAYS, OPEN_EXISTING, OPEN_ALWAYS, TRUNCATE_EXISTING. ETF Beograd RE VEŽBE / / 47

18 Čitanje i upis u fajlove Parametri prilikom kreiranja fajla dwflagsandattributes ETF Beograd RE VEŽBE / / 47

19 Čitanje i upis u fajlove File procedure CloseHandle CloseHandle PROTO, hobject:handle ; handle to object ReadFile ReadFile PROTO, hfile:handle, ; input handle lpbuffer:ptr BYTE, ; ptr to buffer nnumberofbytestoread:dword, ; num bytes to read lpnumberofbytesread:ptr DWORD, ; bytes actually read lpoverlapped:ptr DWORD ; ptr to asynch info ETF Beograd RE VEŽBE / / 47

20 Čitanje i upis u fajlove File procedure WriteFile WriteFile PROTO, hfile:handle, ; output handle lpbuffer:ptr BYTE, ; pointer to buffer nnumberofbytestowrite:dword, ; size of buffer lpnumberofbyteswritten:ptr DWORD, ; num bytes written lpoverlapped:ptr DWORD ; ptr to asynch info SetFilePointer SetFilePointer PROTO, hfile:handle, ; file handle ldistancetomove:sdword, ; bytes to move pointer lpdistancetomovehigh:ptr SDWORD, ; ptr bytes to move, high dwmovemethod:dword ; starting point ETF Beograd RE VEŽBE / / 47

21 Čitanje i upis u fajlove 1 ; Creating a File (CreateFile.asm) 2 3 ; Inputs text from the user, writes the text to an output file. 4 5 INCLUDE Irvine32.inc 6 7 BUFFER_SIZE = data 9 buffer BYTE BUFFER_SIZE DUP(?) 10 filename BYTE "output.txt",0 11 filehandle HANDLE? 12 stringlength DWORD? 13 byteswritten DWORD? 14 str1 BYTE "Cannot create file",0dh,0ah,0 15 str2 BYTE "Bytes written to file [output.txt]: ",0 16 str3 BYTE "Enter up to 500 characters and press " 17 BYTE "[Enter]: ",0dh,0ah, code 20 main PROC 21 ; Create a new text file. 22 mov edx,offset filename 23 call CreateOutputFile 24 mov filehandle,eax ; Check for errors. 27 cmp eax, INVALID_HANDLE_VALUE ; error found? 28 jne file_ok ; no: skip 29 mov edx,offset str1 ; display error 30 call WriteString 31 call WriteString 32 jmp quit 33 file_ok: ; Ask the user to input a string. 36 mov edx,offset str3 ; "Enter up to..." 37 call WriteString 38 mov ecx,buffer_size ; Input a string 39 mov edx,offset buffer 40 call ReadString 41 mov stringlength,eax ; counts chars entered ; Write the buffer to the output file. 44 mov eax,filehandle 45 mov edx,offset buffer 46 mov ecx,stringlength 47 call WriteToFile 48 mov byteswritten,eax ; save return value 49 call CloseFile ; Display the return value. 52 mov edx,offset str2 ; "Bytes written" 53 call WriteString 54 mov eax,byteswritten 55 call WriteDec 56 call Crlf quit: 59 exit 60 main ENDP 61 END main ETF Beograd RE VEŽBE / / 47

22 Čitanje i upis u fajlove 1 ; Reading a File (ReadFile.asm) 2 ; Opens, reads, and displays a text file using 3 ; procedures from Irvine32.lib. 4 INCLUDE Irvine32.inc 5 INCLUDE macros.inc 6 7 BUFFER_SIZE = data 10 buffer BYTE BUFFER_SIZE DUP(?) 11 filename BYTE 80 DUP(0) 12 filehandle HANDLE? code 15 main PROC ; Let user input a filename. 18 mwrite "Enter an input filename: " 19 mov edx,offset filename 20 mov ecx,sizeof filename 21 call ReadString ; Open the file for input. 24 mov edx,offset filename 25 call OpenInputFile 26 mov filehandle,eax ; Check for errors. 29 cmp eax,invalid_handle_value ; error opening file? 30 jne file_ok ; no: skip 31 mwrite <"Cannot open file",0dh,0ah> 32 jmp quit ; and quit 33 file_ok: 34 ; Read the file into a buffer. 35 mov edx,offset buffer 36 mov ecx,buffer_size 37 call ReadFromFile 38 jnc check_buffer_size ; error reading? 39 mwrite "Error reading file. " ; yes: show error message 40 call WriteWindowsMsg 41 jmp close_file check_buffer_size: 44 cmp eax,buffer_size ; buffer large enough? 45 jb buf_size_ok ; yes 46 mwrite <"Error: Buffer too small for the file",0dh,0ah> 47 jmp quit ; and quit 48 buf_size_ok: 49 mov buffer[eax],0 ; insert null terminator 50 mwrite "File size: " 51 call WriteDec ; display file size 52 call Crlf 53 ; Display the buffer. 54 mwrite <"Buffer:",0dh,0ah,0dh,0ah> 55 mov edx,offset buffer ; display the buffer 56 call WriteString 57 call Crlf close_file: 60 mov eax,filehandle 61 call CloseFile 62 quit: 63 exit 64 main ENDP 65 END main ETF Beograd RE VEŽBE / / 47

23 Manipulacija prozora konzole Manipulacija prozora konzole Win32 API omogućava da se kontroliše veličina prozora konzole i veličina bafera prozora. Prozor konzole prikazuje deo bafera kao što se vidi na slici: ETF Beograd RE VEŽBE / / 47

24 Screen buffer Funkcija SetConsoleWindowInfo GetConsoleScreenBufferInfo SetConsoleCursorPosition ScrollConsoleScreenBuffer Značenje podešava veličinu i poziciju prozora konzole relativno u odnosu na screen buffer vraća koordinate pravougaonika konzolnog prozora relativnog u odnosu na screen buffer postavlja kursor na željenu lokaciju na ekranu; ako nije ta pozicija vidljiva, pomera prozor konzole pomera deo teksta kroz bafer kako ne bi uticao na prikazan tekst u prozoru konzole ETF Beograd RE VEŽBE / / 47

25 Screen buffer SetConsoleTitle Menja se naziv prozora konzole..data titlestr BYTE Console title,0.code INVOKE SetConsoleTitle, ADDR titlestr ETF Beograd RE VEŽBE / / 47

26 Screen buffer GetConsoleScreenBufferInfo Vraća informaciju o tekućem stanju prozora konzole. Ima dva parametra - HANDLE na prozor konzole i pokazivač na strukturu screen buffer-a. GetConsoleScreenBufferInfo PROTO, hconsoleoutput:handle, lpconsolescreenbufferinfo:ptr CONSOLE_SCREEN_BUFFER_INFO ETF Beograd RE VEŽBE / / 47

27 Screen buffer GetConsoleScreenBufferInfo CONSOLE_SCREEN_BUFFER_INFO struktura: CONSOLE_SCREEN_BUFFER_INFO STRUCT dwsize COORD <> dwcursorposition COORD <> wattributes WORD? srwindow SMALL_RECT <> dwmaximumwindowsize COORD <> CONSOLE_SCREEN_BUFFER_INFO ENDS COORD je struktura od dva elementa veličine WORD, u fajlu SmallWin.inc. RECT je struktura od četiri elementa veličine WORD, u fajlu SmallWin.inc. ETF Beograd RE VEŽBE / / 47

28 Screen buffer GetConsoleScreenBufferInfo dwsize - veličina screen buffer-a dwcursorposition - lokacija kursora wattributes - boja karaktera u konzolnom baferu srwindow - koordinate konzolnog prozora relativnih u donosu na screen buffer dwmaximumwindowsize - maksimalna veličina prozora konzole Primer.data consoleinfo CONSOLE_SCREEN_BUFFER_INFO <> outhandle HANDLE?.code INVOKE GetConsoleScreenBufferInfo, outhandle, ADDR consoleinfo ETF Beograd RE VEŽBE / / 47

29 Screen buffer SetConsoleWindowInfo podešava veličinu i lokaciju prozora konzole relativno u odnosu na screen buffer. SetConsoleWindowInfo PROTO, hconsoleoutput:handle, ; screen buffer handle babsolute:dword, ; coordinate type lpconsolewindow:ptr SMALL_RECT ; ptr to window rectangle ETF Beograd RE VEŽBE / / 47

30 Screen buffer SetConsoleScreenBufferSize podešava se veličina screen buffer-a kao broj redova i broj kolona. SetConsoleScreenBufferSize PROTO, hconsoleoutput:handle, ; handle to screen buffer dwsize:coord ; new screen buffer size ETF Beograd RE VEŽBE / / 47

31 Screen buffer 1 ; Scrolling the Console Window (Scroll.asm) 2 3 ; This program writes 50 lines of text to the console buffer, 4 ; resizes, and scrolls the console window back to line 0. 5 ; Demonstrates the SetConsoleWindowInfo function. 6 7 INCLUDE Irvine32.inc 8 9.data 10 message BYTE ": This line of text was written " 11 BYTE "to the screen buffer",0dh,0ah 12 messagesize DWORD ($ message) outhandle HANDLE 0 ; standard output handle 15 byteswritten DWORD? ; number of bytes written 16 linenum DWORD 0 17 windowrect SMALL_RECT <0,0,60,11> ; left,top,right,bottom code 20 main PROC 21 INVOKE GetStdHandle, STD_OUTPUT_HANDLE 22 mov outhandle,eax 23.REPEAT 24 mov eax,linenum 25 call WriteDec ; display each line number 26 INVOKE WriteConsole, 27 outhandle, ; console output handle 28 ADDR message, ; string pointer 29 messagesize, ; string length 30 ADDR byteswritten, ; returns num bytes written 31 0 ; not used 32 inc linenum ; next line number 33.UNTIL linenum > ; Resize and reposition the console window relative to the 36 ; screen buffer. 37 INVOKE SetConsoleWindowInfo, 38 outhandle, 39 TRUE, 40 ADDR windowrect call Readchar ; wait for a key 43 call Clrscr ; clear the screen buffer 44 call Readchar ; wait for a second key INVOKE ExitProcess,0 47 main ENDP 48 END main ETF Beograd RE VEŽBE / / 47

32 Kontrola kursora Funkcija Značenje GetConsoleCursorInf vraća veličinu i vidljivost kursora SetConsoleCursorInfo podešava veličinu i vidljivost kursora SetConsoleCursorPosition podešava X, Y poziciju kursora ETF Beograd RE VEŽBE / / 47

33 Kontrola kursora Struktura kursora CONSOLE_CURSOR_INFO STRUCT dwsize DWORD? bvisible DWORD? CONSOLE_CURSOR_INFO ENDS dwsize - veličina kursora, obično 25 bvisible - vidljivost kursora - TRUE ako je vidljiv ETF Beograd RE VEŽBE / / 47

34 Kontrola kursora GetConsoleCursorInfo/SetConsoleCursorInfo GetConsoleCursorInfo GetConsoleCursorInfo PROTO, hconsoleoutput:handle, lpconsolecursorinfo:ptr CONSOLE_CURSOR_INFO SetConsoleCursorInfo SetConsoleCursorInfo PROTO, hconsoleoutput:handle, lpconsolecursorinfo:ptr CONSOLE_CURSOR_INFO ETF Beograd RE VEŽBE / / 47

35 Kontrola kursora SetConsoleCursorPosition SetConsoleCursorPosition PROTO, hconsoleoutput:dword, ; input mode handle dwcursorposition:coord ; screen X,Y coordinates ETF Beograd RE VEŽBE / / 47

36 Kontrola kursora 1 ; Console Demo #2 (Console2.asm) 2 3 ; Demonstration of SetConsoleCursorPosition, 4 ; GetConsoleCursorInfo, SetConsoleCursorInfo, 5 ; SetConsoleScreenBufferSize, SetConsoleCursorPosition, 6 ; SetConsoleTitle, and GetConsoleScreenBufferInfo. 7 8 INCLUDE SmallWin.inc 9 10.data 11 outhandle DWORD? 12 scrsize COORD <120,50> 13 xypos COORD <20,5> 14 consoleinfo CONSOLE_SCREEN_BUFFER_INFO <> 15 cursorinfo CONSOLE_CURSOR_INFO <> 16 titlestr BYTE "Console2 Demo Program", code 19 main PROC 20 ; Get Console output handle. 21 INVOKE GetStdHandle, STD_OUTPUT_HANDLE 22 mov outhandle,eax ; Get console cursor information. 25 INVOKE GetConsoleCursorInfo, outhandle, 26 ADDR cursorinfo 27 ; Set console cursor size to 75% 28 mov cursorinfo.dwsize,75 29 INVOKE SetConsoleCursorInfo, outhandle, 30 ADDR cursorinfo ; Set the screen buffer size. 33 INVOKE SetConsoleScreenBufferSize, 34 outhandle,scrsize ; Set the cursor position to (20,5). 37 INVOKE SetConsoleCursorPosition, outhandle, xypos ; Set the console window s title. 40 INVOKE SetConsoleTitle, ADDR titlestr ; Get screen buffer & window size information. 43 INVOKE GetConsoleScreenBufferInfo, outhandle, 44 ADDR consoleinfo INVOKE ExitProcess,0 47 main ENDP 48 END main ETF Beograd RE VEŽBE / / 47

37 Promena boje teksta Promena boje teksta SetConsoleTextAttribute Podešava foreground i background boju teksta. SetConsoleTextAttribute PROTO, hconsoleoutput:handle, ; console output handle wattributes:word ; color attribute WriteConsoleOutputAttribute Kopira niz vrednosti atributa u uzastopne registre screen buffer-a počevši na specificiranoj lokaciji. WriteConsoleOutputAttribute PROTO, hconsoleoutput:dword, ; output handle lpattribute:ptr WORD, ; write attributes nlength:dword, ; number of cells dwwritecoord:coord, ; first cell coordinates lpnumberofattrswritten:ptr DWORD ; output count ETF Beograd RE VEŽBE / / 47

38 Promena boje teksta 1 ; Writing Text Colors (WriteColors.asm) 2 3 ; Demonstration of WriteConsoleOutputCharacter, 4 ; and WriteConsoleOutputAttribute functions. 5 6 INCLUDE Irvine32.inc 7.data 8 outhandle HANDLE? 9 cellswritten DWORD? 10 xypos COORD <10,2> ; Array of character codes: 13 buffer BYTE 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 14 BYTE 16,17,18, BufSize DWORD ($ buffer) 16 ; Array of attributes: 17 attributes WORD 0Fh,0Eh,0Dh,0Ch,0Bh,0Ah,9,8,7,6 18 WORD 5,4,3,2,1,0F0h,0E0h,0D0h,0C0h,0B0h code 21 main PROC ; Get the Console standard output handle: 24 INVOKE GetStdHandle, STD_OUTPUT_HANDLE 25 mov outhandle,eax ; Set the colors from (10,2) to (30,2): 28 INVOKE WriteConsoleOutputAttribute, 29 outhandle, ADDR attributes, 30 BufSize, xypos, 31 ADDR cellswritten 32 ; Write character codes 1 to 20: 33 INVOKE WriteConsoleOutputCharacter, 34 outhandle, ADDR buffer, BufSize, 35 xypos, ADDR cellswritten call ReadChar 38 exit 39 main ENDP 40 END main ETF Beograd RE VEŽBE / / 47

39 Time/Date funkcije Time/Date funkcije Funkcije i strukture su: GetLocalTime, SetLocalTime GetTickCount, Sleep GetDateTime SYSTEMTIME struktura ETF Beograd RE VEŽBE / / 47

40 Time/Date funkcije SYSTEMTIME struktura SYSTEMTIME se koristi sa time/date Win32 API funkcijama. SYSTEMTIME STRUCT wyear WORD? ; year (4 digits) wmonth WORD? ; month (1-12) wdayofweek WORD? ; day of week (0-6) wday WORD? ; day (1-31) whour WORD? ; hours (0-23) wminute WORD? ; minutes (0-59) wsecond WORD? ; seconds (0-59) wmilliseconds WORD? ; milliseconds (0-999) SYSTEMTIME ENDS ETF Beograd RE VEŽBE / / 47

41 Time/Date funkcije GetLocalTime/SetLocalTime GetLocalTime vraća vreme i datum tekućeg dana na osnovu sistemskog sata. GetLocalTime PROTO, lpsystemtime:ptr SYSTEMTIME SetLocalTime podešava sistemsko vreme i datum. SetLocalTime PROTO, lpsystemtime:ptr SYSTEMTIME ETF Beograd RE VEŽBE / / 47

42 Time/Date funkcije GetTickCount, Sleep GetTickCount vraća broj ms proteklih od startovanja sistema. Sleep GetTickCount PROTO ; return value in EAX pauzira tekući program na specificirani broj ms. Sleep PROTO, dwmilliseconds:dword ETF Beograd RE VEŽBE / / 47

43 Time/Date funkcije 1 ; Calculate Elapsed Time (Timer.asm) 2 3 ; Demonstrate a simple stopwatch timer, using 4 ; the Win32 GetTickCount function. 5 6 INCLUDE Irvine32.inc 7 INCLUDE macros.inc 8 9.data 10 starttime DWORD? code 13 main PROC 14 INVOKE GetTickCount ; get starting tick count 15 mov starttime,eax ; save it ; Create a useless calculation loop. 18 mov ecx, h 19 L1: imul ebx 20 imul ebx 21 imul ebx 22 loop L1 23 INVOKE GetTickCount ; get new tick count 24 cmp eax,starttime ; lower than starting one? 25 jb error ; it wrapped around sub eax,starttime ; get elapsed milliseconds 28 call WriteDec ; display it 29 mwrite <" milliseconds have elapsed",0dh,0ah > 30 jmp quit error: 33 mwrite "Error: GetTickCount invalid--system has " 34 mwrite <"been active for more than 49.7 days ",0dh,0ah> 35 quit: 36 exit 37 main ENDP END main ETF Beograd RE VEŽBE / / 47

44 Time/Date funkcije 1 ; Calculate Elapsed Time (TimingLoop.asm) 2 3 ; This program uses GetTickCount to calculate the number 4 ; of milliseconds that have elapsed since the program 5 ; started. 6 7 INCLUDE Irvine32.inc 8 9 TIME_LIMIT = data 11 starttime DWORD? 12 dot BYTE ".", code 15 main PROC 16 INVOKE GetTickCount 17 mov starttime,eax L1: 20 mov edx,offset dot ; display a dot 21 call WriteString INVOKE Sleep,100 ; sleep for 100ms INVOKE GetTickCount 26 sub eax,starttime ; check the elapsed time 27 cmp eax,time_limit 28 jb L L2: exit 31 main ENDP 32 END main ETF Beograd RE VEŽBE / / 47

45 Primer programa Bouncing Ball Bouncing Ball Write a program that simulates a ball bouncing within a rectangle. Your rectangle will be the size of the standard MS-DOS screen: 25 rows by 80 columns (X = 0-79 and Y = 0-24). The rectangle should contain an internal vertical wall consisting of a single column of block characters (ASCII code 0DBh) starting at row 5, column 40, extending down to row 19, column 40. The background should be blue, and the wall and ball should be white. The ball travels at a constant speed, determined by a delay value of 20 ms inside the loop that displays, erases, and moves the ball. The following sequence of actions will be in the loop: display, delay, erase, move. The ball is just a single character, drawn with the ASCII code 2. To move the ball, you write over it with a blank, move the cursor position to a new location, and redraw the ball. The ball can only move 1 row and 1 column during each loop cycle. You will need to call the following library procedures: Clrscr, Delay, SetTextColor, WriteChar and Gotoxy. You will (probably) need to use the high-level.if,.else and.endif directives explained at the end of Chapter 6. ETF Beograd RE VEŽBE / / 47

46 Primer programa Bouncing Ball Suggested Algorithm: Suppose you have a current location (X, Y), and two direction values, dx, and dy. The latter control the ball s movement. For example, if dx = 1 and dy = 1, the ball is moving downward and to the right. Evaluate the potential new X and Y location: 1 If the new location is outside the rectangle s X and Y coordinates, reverse the ball s direction by negating dx or dy, whichever is appropriate. 2 If the new location is in the middle of the vertical wall, negate dx. 3 If the new location is either the top or the bottom of the vertical wall, negate dy. Next, add dx and dy to your current X and Y coordinates, generating the ball s new location. Redraw the ball at this new location. ETF Beograd RE VEŽBE / / 47

47 KRAJ! ETF Beograd RE VEŽBE / / 47

UNIVERZITET U BEOGRADU ELEKTROTEHNIČKI FAKULTET

UNIVERZITET U BEOGRADU ELEKTROTEHNIČKI FAKULTET UNIVERZITET U BEOGRADU ELEKTROTEHNIČKI FAKULTET Katedra za elektroniku Računarska elektronika Grupa br. 11 Projekat br. 8 Studenti: Stefan Vukašinović 466/2013 Jelena Urošević 99/2013 Tekst projekta :

More information

AM2: Programming with Contemporary Instruction Set

AM2: Programming with Contemporary Instruction Set : Programming with Contemporary Instruction Set Duration: 3 hours Components: Lab exercises and report. Objectives: (a) To examine how protected-mode programming is done on x86 based computer. (b) To evaluate

More information

AM2: Protected-Mode Programming

AM2: Protected-Mode Programming : Protected-Mode Programming Duration: 3 hours Components: Lab exercises and report. Objectives: (a) To examine how protected-mode programming is done on x86 based computer. (b) To evaluate the advantages

More information

Assembly Language for Intel-Based Computers, 4 th Edition. Chapter 10: Structures and Macros

Assembly Language for Intel-Based Computers, 4 th Edition. Chapter 10: Structures and Macros Assembly Language for Intel-Based Computers, 4 th Edition Kip R. Irvine Chapter 10: Structures and Macros (c) Pearson Education, 2002. All rights reserved. Chapter Overview Structures Macros Conditional-Assembly

More information

Assembly Language for Intel-Based Computers, 4 th Edition. Chapter 5: Procedures. Chapter Overview. The Book's Link Library

Assembly Language for Intel-Based Computers, 4 th Edition. Chapter 5: Procedures. Chapter Overview. The Book's Link Library Assembly Language for Intel-Based Computers, 4 th Edition Kip R Irvine Chapter 5: Procedures Slides prepared by Kip R Irvine Revision date: 10/3/2003 Chapter corrections (Web) Assembly language sources

More information

Islamic University Gaza Engineering Faculty Department of Computer Engineering ECOM 2125: Assembly Language LAB

Islamic University Gaza Engineering Faculty Department of Computer Engineering ECOM 2125: Assembly Language LAB Islamic University Gaza Engineering Faculty Department of Computer Engineering ECOM 2125: Assembly Language LAB Lab # 6 Input/output using a Library of Procedures April, 2014 1 Assembly Language LAB Using

More information

Lab 5: Input/Output using a Library of Procedures

Lab 5: Input/Output using a Library of Procedures COE 205 Lab Manual Lab 5: Input/Output using a Library of Procedures - Page 46 Lab 5: Input/Output using a Library of Procedures Contents 5.1. Using an External Library of Procedures for Input and Output

More information

Računarska elektronika Projekat 12

Računarska elektronika Projekat 12 Računarska elektronika Projekat 12 Problem: Zadatak je bio da se napravi program koji, nakon što se zada pozicija kursora, crta horizontalne (pritiskom strelice na gore/dole) i vertikalne linije (pritiskom

More information

Assembly Language for Intel-Based Computers, 4 th Edition

Assembly Language for Intel-Based Computers, 4 th Edition Assembly Language for Intel-Based Computers, 4 th Edition Kip R. Irvine Chapter 5: Procedures Lecture 18 Linking to External Library The Book s Link Library Stack Operations Slides prepared by Kip R. Irvine

More information

Assembly Language. Lecture 5 Procedures

Assembly Language. Lecture 5 Procedures Assembly Language Lecture 5 Procedures Ahmed Sallam Slides based on original lecture slides by Dr. Mahmoud Elgayyar Linking to External Library The Irvine library Stack Operations Runtime Stack PUSH, POP

More information

Assembly Language. Lecture 5 Procedures

Assembly Language. Lecture 5 Procedures Assembly Language Lecture 5 Procedures Ahmed Sallam Slides based on original lecture slides by Dr. Mahmoud Elgayyar Data Transfer Instructions Operand types MOV, MOVZX, MOVSX instructions LAHF, SAHF instructions

More information

In order to run the program, go to the folder Release and run project.exe.

In order to run the program, go to the folder Release and run project.exe. Assembly Language and System Software Lab exercise You need to implement seven programs. In this lab exercise, you are going to get familiar with assembly programming. You should follow the guideline to

More information

Assembly Language for Intel-Based Computers, 4 th Edition. Chapter 5: Procedures

Assembly Language for Intel-Based Computers, 4 th Edition. Chapter 5: Procedures Assembly Language for Intel-Based Computers, 4 th Edition Kip R. Irvine Chapter 5: Procedures Slides prepared by the author Revision date: June 4, 2006 (c) Pearson Education, 2002. All rights reserved.

More information

Libraries and Procedures

Libraries and Procedures Computer Organization and Assembly Language Computer Engineering Department Chapter 5 Libraries and Procedures Presentation Outline Link Library Overview The Book's Link Library Runtime Stack and Stack

More information

Islamic University Gaza Engineering Faculty Department of Computer Engineering ECOM 2125: Assembly Language LAB. Lab # 10. Advanced Procedures

Islamic University Gaza Engineering Faculty Department of Computer Engineering ECOM 2125: Assembly Language LAB. Lab # 10. Advanced Procedures Islamic University Gaza Engineering Faculty Department of Computer Engineering ECOM 2125: Assembly Language LAB Lab # 10 Advanced Procedures May, 2014 1 Assembly Language LAB Stack Parameters There are

More information

Required Setup for 32-bit Applications

Required Setup for 32-bit Applications 1 of 23 8/25/2015 09:30 Getting Started with MASM and Visual Studio 2012 Updated 4/6/2015. This tutorial shows you how to set up Visual Studio 2012 (including Visual Studio 2012 Express for Windows Desktop)

More information

Libraries and Procedures

Libraries and Procedures Libraries and Procedures COE 205 Computer Organization and Assembly Language Computer Engineering Department King Fahd University of Petroleum and Minerals Presentation Outline Link Library Overview The

More information

Macros. Introducing Macros Defining Macros Invoking Macros Macro Examples Nested Macros Example Program: Wrappers

Macros. Introducing Macros Defining Macros Invoking Macros Macro Examples Nested Macros Example Program: Wrappers Macros Introducing Macros Defining Macros Invoking Macros Macro Examples Nested Macros Example Program: Wrappers Irvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 1 Introducing Macros A

More information

Marking Scheme. Examination Paper Department of CE. Module: Microprocessors (630313)

Marking Scheme. Examination Paper Department of CE. Module: Microprocessors (630313) Philadelphia University Faculty of Engineering Marking Scheme Examination Paper Department of CE Module: Microprocessors (630313) Final Exam Second Semester Date: 02/06/2018 Section 1 Weighting 40% of

More information

COE 205. Computer Organization and Assembly Language Dr. Aiman El-Maleh

COE 205. Computer Organization and Assembly Language Dr. Aiman El-Maleh Libraries i and Procedures COE 205 Computer Organization and Assembly Language Dr. Aiman El-Maleh College of Computer Sciences and Engineering King Fahd University of Petroleum and Minerals [Adapted from

More information

Call DLL from Limnor Applications

Call DLL from Limnor Applications Call DLL from Limnor Applications There is a lot of computer software in the format of dynamic link libraries (DLL). DLLCaller performer allows your applications to call DLL functions directly. Here we

More information

Lab 6: Conditional Processing

Lab 6: Conditional Processing COE 205 Lab Manual Lab 6: Conditional Processing Page 56 Lab 6: Conditional Processing Contents 6.1. Unconditional Jump 6.2. The Compare Instruction 6.3. Conditional Jump Instructions 6.4. Finding the

More information

Islamic University Gaza Engineering Faculty Department of Computer Engineering ECOM 2125: Assembly Language LAB. Lab # 8. Conditional Processing

Islamic University Gaza Engineering Faculty Department of Computer Engineering ECOM 2125: Assembly Language LAB. Lab # 8. Conditional Processing Islamic University Gaza Engineering Faculty Department of Computer Engineering ECOM 2125: Assembly Language LAB Lab # 8 Conditional Processing April, 2014 1 Assembly Language LAB Unconditional Jump The

More information

Files, Registry and Databases for storing data

Files, Registry and Databases for storing data REAL TIME OPERATING SYSTEM PROGRAMMING-II: II: Windows CE, OSEK and Real time Linux Lesson-4: Files, Registry and Databases for storing data 1 1. WCE Files 2 File Creation function arguments CreateFile

More information

Answers to Odd-Numbered Section Review Questions

Answers to Odd-Numbered Section Review Questions Answers to Odd-Numbered Section Review Questions for: Irvine, Kip R. Assembly Language for Intel-Based Computers, 4th Edition Prepared by the author. Recent revision history: 11/24/2002: 11.2 (notes) 12/3/2002:

More information

Programiranje Programski jezik C. Sadržaj. Datoteke. prof.dr.sc. Ivo Ipšić 2009/2010

Programiranje Programski jezik C. Sadržaj. Datoteke. prof.dr.sc. Ivo Ipšić 2009/2010 Programiranje Programski jezik C prof.dr.sc. Ivo Ipšić 2009/2010 Sadržaj Ulazno-izlazne funkcije Datoteke Formatirane datoteke Funkcije za rad s datotekama Primjeri Datoteke komunikacija između programa

More information

Marking Scheme. Examination Paper. Module: Microprocessors (630313)

Marking Scheme. Examination Paper. Module: Microprocessors (630313) Philadelphia University Faculty of Engineering Marking Scheme Examination Paper Department of CE Module: Microprocessors (630313) Final Exam Second Semester Date: 12/06/2017 Section 1 Weighting 40% of

More information

COMPUTER ENGINEERING DEPARTMENT

COMPUTER ENGINEERING DEPARTMENT Page 1 of 11 COMPUTER ENGINEERING DEPARTMENT December 31, 2007 COE 205 COMPUTER ORGANIZATION & ASSEMBLY PROGRAMMING Major Exam II First Semester (071) Time: 7:00 PM-9:30 PM Student Name : KEY Student ID.

More information

Assembly Language for Intel-Based Computers, 5 th Edition. Chapter 9: Strings and Arrays

Assembly Language for Intel-Based Computers, 5 th Edition. Chapter 9: Strings and Arrays Assembly Language for Intel-Based Computers, 5 th Edition Kip R. Irvine Chapter 9: Strings and Arrays Slide show prepared by the author Revision date: June 4, 2006 (c) Pearson Education, 2006-2007. All

More information

Marking Scheme. Examination Paper Department of CE. Module: Microprocessors (630313)

Marking Scheme. Examination Paper Department of CE. Module: Microprocessors (630313) Philadelphia University Faculty of Engineering Marking Scheme Examination Paper Department of CE Module: Microprocessors (630313) Final Exam Second Semester Date: 08/06/2014 Section 1 Weighting 40% of

More information

;this variable is used to keep the mans position. ;this variable is used to keep the zombies position

;this variable is used to keep the mans position. ;this variable is used to keep the zombies position TITLE MASM Template (main.asm) ; Description: This was my final project for my Assembly Language Course. It is a Zombie Video game. You as the player move around with your arrow keys and try to avoid getting

More information

Marking Scheme. Examination Paper. Module: Microprocessors (630313)

Marking Scheme. Examination Paper. Module: Microprocessors (630313) Philadelphia University Faculty of Engineering Marking Scheme Examination Paper Department of CE Module: Microprocessors (630313) Final Exam First Semester Date: 30/01/2018 Section 1 Weighting 40% of the

More information

Assembly Language for Intel-Based Computers, 4 th Edition. Chapter 3: Assembly Language Fundamentals

Assembly Language for Intel-Based Computers, 4 th Edition. Chapter 3: Assembly Language Fundamentals Assembly Language for Intel-Based Computers, 4 th Edition Kip R. Irvine Chapter 3: Assembly Language Fundamentals (c) Pearson Education, 2002. Chapter Overview Basic Elements of Assembly Language Example:

More information

Microprocessors ( ) Fall 2010/2011 Lecture Notes # 15. Stack Operations. 10 top

Microprocessors ( ) Fall 2010/2011 Lecture Notes # 15. Stack Operations. 10 top Microprocessors (0630371) Fall 2010/2011 Lecture Notes # 15 Stack Operations Objectives of the Lecture Runtime Stack PUSH Operation POP Operation Initializing the Stack PUSH and POP Instructions Stack

More information

Assembly Language for Intel-Based Computers, 4 th Edition

Assembly Language for Intel-Based Computers, 4 th Edition Assembly Language for Intel-Based Computers, 4 th Edition Kip R. Irvine Chapter 3: Assembly Language Fundamentals Assembling, Linking and Running Programs Example Programs Slides prepared by Kip R. Irvine

More information

Introduction to Assembly Language

Introduction to Assembly Language Introduction to Assembly Language COE 205 Computer Organization and Assembly Language Computer Engineering Department King Fahd University of Petroleum and Minerals Presentation Outline Basic Elements

More information

Assembly Language for Intel-Based Computers, 5 th Edition. Kip Irvine. Chapter 3: Assembly Language Fundamentals

Assembly Language for Intel-Based Computers, 5 th Edition. Kip Irvine. Chapter 3: Assembly Language Fundamentals Assembly Language for Intel-Based Computers, 5 th Edition Kip Irvine Chapter 3: Assembly Language Fundamentals Chapter Overview Basic Elements of Assembly Language Example: Adding and Subtracting Integers

More information

Assembly Fundamentals

Assembly Fundamentals Chapter Overview Assembly Fundamentals Basic Elements of Assembly Language Example: Adding and Subtracting Integers Assembling, Linking, and Running Programs Defining Data Symbolic Constants Computer Organization

More information

Assembly Language for Intel-Based Computers, 4 th Edition. Lecture 25: Interface With High-Level Language

Assembly Language for Intel-Based Computers, 4 th Edition. Lecture 25: Interface With High-Level Language Assembly Language for Intel-Based Computers, 4 th Edition Kip R. Irvine Lecture 25: Interface With High-Level Language Slide show prepared by Kip R. Irvine, Revision date: 07/07/2002 Modified on April

More information

Assembly Language Programming

Assembly Language Programming Assembly Language Programming Integer Constants Optional leading + or sign Binary, decimal, hexadecimal, or octal digits Common radix characters: h hexadecimal d decimal b binary r encoded real q/o - octal

More information

ELEC 242 Using Library Procedures

ELEC 242 Using Library Procedures ELEC 242 Using Library Procedures There are a number of existing procedures that are already written for you that you will use in your programs. In order to use the library procedures that come with the

More information

Overview: 1. Overview: 2

Overview: 1. Overview: 2 1: TITLE Binary equivalent of characters BINCHAR.ASM 3: Objective: To print the binary equivalent of 4: ASCII character code. 5: Input: Requests a character from keyboard. 6: Output: Prints the ASCII code

More information

COMPUTER ENGINEERING DEPARTMENT

COMPUTER ENGINEERING DEPARTMENT Page 1 of 14 COMPUTER ENGINEERING DEPARTMENT Jan. 7, 2010 COE 205 COMPUTER ORGANIZATION & ASSEMBLY PROGRAMMING Major Exam II First Semester (091) Time: 3:30 PM-6:00 PM Student Name : KEY Student ID. :

More information

Assembly Language for Intel-Based Computers, 5 th Edition

Assembly Language for Intel-Based Computers, 5 th Edition Assembly Language for Intel-Based Computers, 5 th Edition Kip Irvine Chapter 3: Assembly Language Fundamentals Slides prepared by the author Revision date: June 4, 2006 (c) Pearson Education, 2006-2007.

More information

CVE EXPLOIT USING 108 BYTES AND DOWNLOADING A FILE WITH YOUR UNLIMITED CODE BY VALTHEK

CVE EXPLOIT USING 108 BYTES AND DOWNLOADING A FILE WITH YOUR UNLIMITED CODE BY VALTHEK CVE-2017-11882 EXPLOIT USING 108 BYTES AND DOWNLOADING A FILE WITH YOUR UNLIMITED CODE BY VALTHEK First words of thank to Embedy Company to discover the initial exploit and POC of 44 bytes máximum, Ridter

More information

Experiment #5. Using BIOS Services and DOS functions Part 1: Text-based Graphics

Experiment #5. Using BIOS Services and DOS functions Part 1: Text-based Graphics Experiment #5 Using BIOS Services and DOS functions Part 1: Text-based Graphics 5.0 Objectives: The objective of this experiment is to introduce BIOS and DOS interrupt service routines to be utilized in

More information

Računarske osnove Interneta (SI3ROI, IR4ROI)

Računarske osnove Interneta (SI3ROI, IR4ROI) Računarske osnove terneta (SI3ROI, IR4ROI) Vežbe MPLS Predavač: 08.11.2011. Dražen Drašković, drazen.draskovic@etf.rs Autori: Dražen Drašković Naučili ste na predavanjima MPLS (Multi-Protocol Label Switching)

More information

Chapter 3 (Part a) Assembly Language Fundamentals

Chapter 3 (Part a) Assembly Language Fundamentals Islamic University Gaza Engineering Faculty Department of Computer Engineering ECOM 2025: Assembly Language Discussion Chapter 3 (Part a) Assembly Language Fundamentals Eng. Eman R. Habib February, 2014

More information

Assembly Language Fundamentals

Assembly Language Fundamentals ECOM 2325 Computer Organization and Assembly Language Chapter 3 Assembly Language Fundamentals Presentation Outline Basic Elements of Assembly Language Flat Memory Program Template Example: Adding and

More information

Chapter Overview. Assembly Language for Intel-Based Computers, 4 th Edition. Chapter 3: Assembly Language Fundamentals.

Chapter Overview. Assembly Language for Intel-Based Computers, 4 th Edition. Chapter 3: Assembly Language Fundamentals. Assembly Language for Intel-Based Computers, 4 th Edition Chapter 3: Assembly Language Fundamentals Slides prepared by Kip R. Irvine Revision date: 09/15/2002 Kip R. Irvine Chapter Overview Basic Elements

More information

Bricscad V VLE LISP Function Summary

Bricscad V VLE LISP Function Summary VLE-ENAMEP DataType (vle-enamep obj) Predicator function to determine T - if 'obj' is a ENAME whether 'obj' is of ENAME type NIL - if 'obj' is not a ENAME 'ENAME) VLE-FILEP DataType (vle-filep obj) Predicator

More information

Introduction to Assembly Language

Introduction to Assembly Language Introduction to Assembly Language COE 205 Computer Organization and Assembly Language Dr. Aiman El-Maleh College of Computer Sciences and Engineering King Fahd University of Petroleum and Minerals [Adapted

More information

Assembly Language for Intel-Based Computers, 5 th Edition. Chapter 3: Assembly Language Fundamentals

Assembly Language for Intel-Based Computers, 5 th Edition. Chapter 3: Assembly Language Fundamentals Assembly Language for Intel-Based Computers, 5 th Edition Kip Irvine Chapter 3: Assembly Language Fundamentals Slides prepared by the author Revision date: June 4, 2006 (c) Pearson Education, 2006-2007.

More information

Assembly Language for Intel-Based Computers, 4 th Edition. Chapter 13: 16-Bit MS-DOS Programming

Assembly Language for Intel-Based Computers, 4 th Edition. Chapter 13: 16-Bit MS-DOS Programming Assembly Language for Intel-Based Computers, 4 th Edition Kip R. Irvine Chapter 13: 16-Bit MS-DOS Programming (c) Pearson Education, 2002. All rights reserved. Chapter Overview MS-DOS and the IBM-PC MS-DOS

More information

Assembly Language for Intel-Based Computers, 4 th Edition. Chapter 6: Conditional Processing. Chapter Overview. Boolean and Comparison Instructions

Assembly Language for Intel-Based Computers, 4 th Edition. Chapter 6: Conditional Processing. Chapter Overview. Boolean and Comparison Instructions Assembly Language for Intel-Based Computers, 4 th Edition Kip R. Irvine Chapter 6: Conditional Processing Slides prepared by Kip R. Irvine Revision date: 10/19/2002 Chapter corrections (Web) Assembly language

More information

; GRC Server Logging

; GRC Server Logging 1.nolist sqrl.asm SQRL SERVICE PROVIDER INTERFACE 08/31/2018 This code supports these =FOUR= PUBLIC HTTP API calls: /nut.sqrl /png.sqrl /pag.sqrl /cps.sqrl?{-sqrl-server-provided-cps-nonce-} This code

More information

Chapter 3: Assembly Language Fundamentals. Cristina G. Rivera

Chapter 3: Assembly Language Fundamentals. Cristina G. Rivera Chapter 3: Assembly Language Fundamentals Cristina G. Rivera Basic Elements of Assembly Language Example: Adding and Subtracting Integers Assembling, Linking, and Running Programs Defining Data Symbolic

More information

EECE.3170: Microprocessor Systems Design I Summer 2017 Homework 4 Solution

EECE.3170: Microprocessor Systems Design I Summer 2017 Homework 4 Solution 1. (40 points) Write the following subroutine in x86 assembly: Recall that: int f(int v1, int v2, int v3) { int x = v1 + v2; urn (x + v3) * (x v3); Subroutine arguments are passed on the stack, and can

More information

namespace spojneice { public partial class Form1 : Form { public Form1() { InitializeComponent(); }

namespace spojneice { public partial class Form1 : Form { public Form1() { InitializeComponent(); } Spojnice using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.IO;

More information

Computer Architecture and Assembly Language. Practical Session 5

Computer Architecture and Assembly Language. Practical Session 5 Computer Architecture and Assembly Language Practical Session 5 Addressing Mode - "memory address calculation mode" An addressing mode specifies how to calculate the effective memory address of an operand.

More information

Lab 3: Defining Data and Symbolic Constants

Lab 3: Defining Data and Symbolic Constants COE 205 Lab Manual Lab 3: Defining Data and Symbolic Constants - page 25 Lab 3: Defining Data and Symbolic Constants Contents 3.1. MASM Data Types 3.2. Defining Integer Data 3.3. Watching Variables using

More information

Strings and Arrays. Overview. String primitive instructions MOVSB, MOVSW, MOVSD

Strings and Arrays. Overview. String primitive instructions MOVSB, MOVSW, MOVSD Overview Strings and Arrays Computer Organization and Assembly Languages Yung-Yu Chuang 00//0 Assembly is for efficient code. Loops are what you likely want to optimize. Loops are usually used to process

More information

ECOM Computer Organization and Assembly Language. Computer Engineering Department CHAPTER 7. Integer Arithmetic

ECOM Computer Organization and Assembly Language. Computer Engineering Department CHAPTER 7. Integer Arithmetic ECOM 2325 Computer Organization and Assembly Language Computer Engineering Department CHAPTER 7 Integer Arithmetic Presentation Outline Shift and Rotate Instructions Shift and Rotate Applications Multiplication

More information

Osnove programskog jezika C# Čas 5. Delegati, događaji i interfejsi

Osnove programskog jezika C# Čas 5. Delegati, događaji i interfejsi Osnove programskog jezika C# Čas 5. Delegati, događaji i interfejsi DELEGATI Bezbedni pokazivači na funkcije Jer garantuju vrednost deklarisanog tipa. Prevodilac prijavljuje grešku ako pokušate da povežete

More information

We will first study the basic instructions for doing multiplications and divisions

We will first study the basic instructions for doing multiplications and divisions MULTIPLICATION, DIVISION AND NUMERICAL CONVERSIONS We will first study the basic instructions for doing multiplications and divisions We then use these instructions to 1. Convert a string of ASCII digits

More information

Development of the Game Hangman in Assembly Programming Language

Development of the Game Hangman in Assembly Programming Language 134 Telfor Journal, Vol. 10,. 2, 2018. Development of the Game Hangman in Assembly Programming Language Stefan Tešanović and Predrag Mitrović Abstract This paper describes the realization of the Hangman

More information

Assembler Programming. Lecture 10

Assembler Programming. Lecture 10 Assembler Programming Lecture 10 Lecture 10 Mixed language programming. C and Basic to MASM Interface. Mixed language programming Combine Basic, C, Pascal with assembler. Call MASM routines from HLL program.

More information

Assembly Language for Intel-Based Computers, 4 th Edition. Chapter 6: Conditional Processing

Assembly Language for Intel-Based Computers, 4 th Edition. Chapter 6: Conditional Processing Assembly Language for Intel-Based Computers, 4 th Edition Kip R. Irvine Chapter 6: Conditional Processing (c) Pearson Education, 2002. All rights reserved. Chapter Overview Boolean and Comparison Instructions

More information

Tema 8: Koncepti i teorije relevantne za donošenje odluka (VEŽBE)

Tema 8: Koncepti i teorije relevantne za donošenje odluka (VEŽBE) Tema 8: Koncepti i teorije relevantne za donošenje odluka (VEŽBE) SISTEMI ZA PODRŠKU ODLUČIVANJU dr Vladislav Miškovic vmiskovic@singidunum.ac.rs Fakultet za računarstvo i informatiku 2013/2014 Tema 8:

More information

Assembly Language for Intel-Based Computers, 4 th Edition. Chapter 8:Advanced Procedures

Assembly Language for Intel-Based Computers, 4 th Edition. Chapter 8:Advanced Procedures Assembly Language for Intel-Based Computers, 4 th Edition Kip R. Irvine Chapter 8:Advanced Procedures (c) Pearson Education, 2002. All rights reserved. Chapter Overview Local Variables Stack Parameters

More information

var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject); begin ListBox1.Items.LoadFromFile('d:\brojevi.

var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject); begin ListBox1.Items.LoadFromFile('d:\brojevi. 1 PANEL komponenta kontejnerska, slična GropBox. Roditeljska komponenta za komp. postavljene na nju. Zajedno se pomeraju. Caption svojstvo za naziv; Alighment pomera svojstvo Caption levo i desno; Align

More information

COE 205 Lab Manual Experiment N o 12. Experiment N o Using the Mouse

COE 205 Lab Manual Experiment N o 12. Experiment N o Using the Mouse Experiment N o 12 12 Using the Mouse Introduction The mouse is an I/O device that replaces the arrow keys on the keyboard for graphical and text style programs. This experiment shows how to add the mouse

More information

22 Assembly Language for Intel-Based Computers, 4th Edition. 3. Each edge is a transition from one state to another, caused by some input.

22 Assembly Language for Intel-Based Computers, 4th Edition. 3. Each edge is a transition from one state to another, caused by some input. 22 Assembly Language for Intel-Based Computers, 4th Edition 6.6 Application: Finite-State Machines 1. A directed graph (also known as a diagraph). 2. Each node is a state. 3. Each edge is a transition

More information

Macros in Pentium. Assembly Language. October 25

Macros in Pentium. Assembly Language. October 25 Macros in Pentium Assembly Language October 25 CSC201 Section 002 Fall, 2000 Equates PI equ 3.1415926 MAXRECS equ 200 RECSIZE equ 5 move equ mov la equ lea float1 dd PI recarray db MAXRECS*RECSIZE dup

More information

Assembly Language Fundamentals

Assembly Language Fundamentals Computer Organization & Assembly Languages Assembly Language Fundamentals Pu-Jen Cheng Adapted from the slides prepared by Kip Irvine for the book, Assembly Language for Intel-Based Computers, 5th Ed.

More information

Assembly Language. Lecture 3 Assembly Fundamentals

Assembly Language. Lecture 3 Assembly Fundamentals Assembly Language Lecture 3 Assembly Fundamentals Ahmed Sallam Slides based on original lecture slides by Dr. Mahmoud Elgayyar General Concepts CPU Design, Instruction execution cycle IA-32 Processor Architecture

More information

Lecture 13: I/O I/O. Interrupts. How?

Lecture 13: I/O I/O. Interrupts. How? Lecture 13: I/O I/O Interrupts MS-DOS Function Calls Input,Output, File I/O Video Keyboard Getting data into your program: define it in the data area use immediate operands Very limiting Most programs

More information

Islamic University Gaza Engineering Faculty Department of Computer Engineering ECOM 2125: Assembly Language LAB

Islamic University Gaza Engineering Faculty Department of Computer Engineering ECOM 2125: Assembly Language LAB Islamic University Gaza Engineering Faculty Department of Computer Engineering ECOM 2125: Assembly Language LAB Lab # 9 Integer Arithmetic and Bit Manipulation April, 2014 1 Assembly Language LAB Bitwise

More information

Jump instructions. Unconditional jumps Direct jump. do not change flags. jmp label

Jump instructions. Unconditional jumps Direct jump. do not change flags. jmp label do not change flags Unconditional jumps Direct jump jmp label Jump instructions jmp Continue xor eax,eax Continue: xor ecx,ecx Machine code: 0040340A EB 02 0040340C 33 C0 0040340E 33 C9 displacement =

More information

Assembly Language for Intel-Based Computers, 4 th Edition

Assembly Language for Intel-Based Computers, 4 th Edition Assembly Language for Intel-Based Computers, 4 th Edition Kip R. Irvine Lecture 28: Strings and Arrays Slides prepared by Kip R. Irvine, Revision date: 07/11/2002 Modified by Dr. Nikolay Metodiev Sirakov

More information

Conditional Processing

Conditional Processing Announcements Conditional Processing Midterm exam: Room 103, 10:00am-12:00am next Thursday, open book, chapters 1-5. Assignment #2 is online. Computer Organization and Assembly Languages Yung-Yu Chuang

More information

COMP211 ASSEMBLY PROGRAMMING

COMP211 ASSEMBLY PROGRAMMING COMP211 ASSEMBLY PROGRAMMING Chapter 6: Conditional Processing Cristina G. Rivera 2 Chapter Overview Boolean and Comparison Instructions Conditional Jumps Conditional Loop Instructions Conditional Structures

More information

SOEN228, Winter Revision 1.2 Date: October 25,

SOEN228, Winter Revision 1.2 Date: October 25, SOEN228, Winter 2003 Revision 1.2 Date: October 25, 2003 1 Contents Flags Mnemonics Basic I/O Exercises Overview of sample programs 2 Flag Register The flag register stores the condition flags that retain

More information

Assembly Language for Intel-Based Computers, 4 th Edition

Assembly Language for Intel-Based Computers, 4 th Edition Assembly Language for Intel-Based Computers, 4 th Edition Kip R. Irvine Chapter 13: 16-Bit MS-DOS Programming Interrupts Slide show prepared by Kip R. Irvine, Revision date: 08/04/02 Modified by Dr. Nikolay

More information

X86 Addressing Modes Chapter 3" Review: Instructions to Recognize"

X86 Addressing Modes Chapter 3 Review: Instructions to Recognize X86 Addressing Modes Chapter 3" Review: Instructions to Recognize" 1 Arithmetic Instructions (1)! Two Operand Instructions" ADD Dest, Src Dest = Dest + Src SUB Dest, Src Dest = Dest - Src MUL Dest, Src

More information

Assembly Language for Intel-Based Computers, 5 th Edition. Kip R. Irvine. Chapter 6: Conditional Processing

Assembly Language for Intel-Based Computers, 5 th Edition. Kip R. Irvine. Chapter 6: Conditional Processing Assembly Language for Intel-Based Computers, 5 th Edition Kip R. Irvine Chapter 6: Conditional Processing Chapter Overview Boolean and Comparison Instructions Conditional Jumps Conditional Loop Instructions

More information

Design Guide Using the SDK in a C or C++ Application

Design Guide Using the SDK in a C or C++ Application Table of Contents Overview Overview of the SDK Design Guide Using the SDK in a C or C++ Application Function Reference Basic Functions Generator Mode Functions External 1 PPS Mode Functions Time Code Mode

More information

Conditional Processing

Conditional Processing ١ Conditional Processing Computer Organization & Assembly Language Programming Dr Adnan Gutub aagutub at uqu.edu.sa Presentation Outline [Adapted from slides of Dr. Kip Irvine: Assembly Language for Intel-Based

More information

Experiment 8 8 Subroutine Handling Instructions and Macros

Experiment 8 8 Subroutine Handling Instructions and Macros Introduction Experiment 8 8 Subroutine Handling Instructions and Macros In this experiment you will be introduced to subroutines and how to call them. You will verify the exchange of data between a main

More information

Lab 2: Introduction to Assembly Language Programming

Lab 2: Introduction to Assembly Language Programming COE 205 Lab Manual Lab 2: Introduction to Assembly Language Programming - page 16 Lab 2: Introduction to Assembly Language Programming Contents 2.1. Intel IA-32 Processor Architecture 2.2. Basic Program

More information

mith College Computer Science CSC231 Assembly Week #11 Fall 2017 Dominique Thiébaut

mith College Computer Science CSC231 Assembly Week #11 Fall 2017 Dominique Thiébaut mith College Computer Science CSC231 Assembly Week #11 Fall 2017 Dominique Thiébaut dthiebaut@smith.edu Back to Conditional Jumps Review sub eax, 10 jz there xxx xxx there:yyy yyy Review cmp eax, 10 jz

More information

3: 4: 5: 9: ',0 10: ',0 11: ',0 12: 13:.CODE 14: INCLUDE

3: 4: 5: 9: ',0 10: ',0 11: ',0 12: 13:.CODE 14: INCLUDE 1: TITLE Parameter passing via registers PROCEX1.ASM 2: COMMENT 3: Objective: To show parameter passing via registers 4: Input: Requests two integers from the user. 5: Output: Outputs the sum of the input

More information

Stack -- Memory which holds register contents. Will keep the EIP of the next address after the call

Stack -- Memory which holds register contents. Will keep the EIP of the next address after the call Call without Parameter Value Transfer What are involved? ESP Stack Pointer Register Grows by 4 for EIP (return address) storage Stack -- Memory which holds register contents Will keep the EIP of the next

More information

Tutorial 03: MASM Program Structure, Debugging, and Addressing Mode

Tutorial 03: MASM Program Structure, Debugging, and Addressing Mode CSCI2510 Computer Organization Tutorial 03: MASM Program Structure, Debugging, and Addressing Mode Bentian Jiang btjiang@cse.cuhk.edu.hk Outline Program Structure (quick review) Assembler Directives Data

More information

REAL TIME OPERATING SYSTEM PROGRAMMING-II: II: Windows CE, OSEK and Real time Linux. Lesson-9: WCE Serial Communication, Network, device-to

REAL TIME OPERATING SYSTEM PROGRAMMING-II: II: Windows CE, OSEK and Real time Linux. Lesson-9: WCE Serial Communication, Network, device-to REAL TIME OPERATING SYSTEM PROGRAMMING-II: II: Windows CE, OSEK and Real time Linux Lesson-9: WCE Serial Communication, Network, device-to to-device socket and Communication Functions 1 1. Windows CE Serial

More information

16.317: Microprocessor Systems Design I Fall 2014

16.317: Microprocessor Systems Design I Fall 2014 16.317: Microprocessor Systems Design I Fall 2014 Exam 2 Solution 1. (16 points, 4 points per part) Multiple choice For each of the multiple choice questions below, clearly indicate your response by circling

More information

db "Please enter up to 256 characters (press Enter Key to finish): ",0dh,0ah,'$'

db Please enter up to 256 characters (press Enter Key to finish): ,0dh,0ah,'$' PA4 Sample Solution.model large.stack 100h.data msg1 db "This programs scans a string of up to 256 bytes and counts the repetitions of the number 4206 and sums them.",0dh,0ah,'$' msg2 db "Please enter

More information

Lecture 16: Passing Parameters on the Stack. Push Examples. Pop Examples. CALL and RET

Lecture 16: Passing Parameters on the Stack. Push Examples. Pop Examples. CALL and RET Lecture 1: Passing Parameters on the Stack Push Examples Quick Stack Review Passing Parameters on the Stack Binary/ASCII conversion ;assume SP = 0202 mov ax, 124h push ax push 0af8h push 0eeeh EE 0E F8

More information

Language of x86 processor family

Language of x86 processor family Assembler lecture 2 S.Šimoňák, DCI FEEI TU of Košice Language of x86 processor family Assembler commands: instructions (processor, instructions of machine language) directives (compiler translation control,

More information

Programming in Module. Near Call

Programming in Module. Near Call Programming in Module Main: sub1: call sub1 sub ax,ax sub1 sub1 proc near sub ax,ax endp sub1 sub1 proc Far sub ax,ax endp Near Call sub1 sub1 Main: call sub1 sub1: sub ax,ax proc near sub ax,ax endp SP

More information