; Pentium assembly code macros, with start_clock. ; Put the INCLUDE directive for this file before the .data and .code sections ; of source files that need the macros. EXTERN timeSetEvent@20:NEAR EXTERN timeKillEvent@4:NEAR EXTERN putchar:NEAR EXTERN getchar:NEAR EXTERN puts:NEAR EXTERN mainCRTStartup:NEAR EXTERN _kbhit:NEAR EXTERN printf:NEAR public main done MACRO LOCAL wait_on_input, exit_msg ;; kill timer mov EAX, timer_ID push EAX call timeKillEvent@4 ;; ignore return value (in EAX) lea EAX, exit_msg push EAX call puts add ESP, 4 ;; clean up stack from _printf call wait_on_input: ;;call _kbhit ;; cmp EAX, 0 ;;je wait_on_input xor EAX, EAX ;; return without error pop edi pop esi pop ebx leave ret 0 exit_msg db 'Program completed.',0 ENDM at_my_code MACRO xor EAX, EAX ;; clears EAX int 3 ENDM put_ch MACRO thechar:REQ push EAX push EBX push ECX push EDX push thechar call putchar add ESP, 4 pop EDX pop ECX pop EBX pop EAX ENDM get_ch MACRO push EBX push ECX push EDX call getchar ;; character in EAX pop EDX pop ECX pop EBX ENDM put_str MACRO stradr:REQ push EAX push EBX push ECX push EDX lea EAX, stradr push EAX call puts add ESP, 4 pop EDX pop ECX pop EBX pop EAX ENDM put_i MACRO the_int:REQ push the_int lea EAX, format_int push EAX call printf add ESP, 8 ENDM .data format_int db '%d', 0 start_clock MACRO handler_addr:REQ LOCAL sclock_rtn push 1 ;; 1 for periodic timer push 0 ;; user data passed to handler, ignored push handler_addr ;; address of handler push 50 ;; resolution of event in milliseconds push 1000 ;; timeout value, in milliseconds call timeSetEvent@20 ;; function cleans up the stack ;; if timeSetEvent@20 returns with EAX=0, then ;; there has been an error. mov timer_ID, EAX cmp EAX, 0 jne sclock_rtn lea EAX, bad_clock_str push EAX call puts add ESP, 4 xor EAX, EAX ;; return without error pop edi pop esi pop ebx leave ret 0 sclock_rtn: ENDM .data timer_ID dd ? bad_clock_str db 'start_clock failed. Exiting program.', 0