-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUTILS.ASM
1205 lines (1013 loc) · 23.6 KB
/
UTILS.ASM
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
IDEAL
P386
MODEL FLAT, C
ASSUME cs:_TEXT,ds:FLAT,es:FLAT,fs:FLAT,gs:FLAT
include "utils.inc"
CODESEG
;; =============================================================================
;; stdout functions
;; =============================================================================
;; Prints a singular character to STDOUT
;; NOT_TESTED
proc print_char
arg @@char:dword
uses eax, edx
ifdef NASM
push ebx
push ecx
mov eax, 4
mov ebx, 1
lea ecx, [@@char]
mov edx, 1
int 80h
pop ecx
pop ebx
else
mov ah, 02h
mov edx, [@@char]
;; dl: the character to print
int 21h
;; al: last character output
endif
ret
endp print_char
;; Prints a newline (CRLF) to STDOUT
proc print_newline
call print_char, 13
call print_char, 10
ret
endp print_newline
proc print_space
call print_char, ' '
ret
endp print_space
;; Prints a null terminated string to STDOUT (no newline added)
proc print_str
uses eax, ebx
arg @@string:DWORD
;; Loop until we find a zero character
mov eax, [@@string]
@@charloop:
mov ebx, [eax]
cmp bl, 0
je @@end
call print_char, ebx
inc eax
jmp @@charloop
@@end:
ret
endp print_str
;; Prints an integer to STDOUT
proc print_int
arg @@value:dword
uses eax
call itoa, [@@value], offset print_int_buffer, 10
call print_str, offset print_int_buffer
ret
endp print_int
proc pad_print_buffer
arg @@padding:dword
uses eax, ebx, edx
call strlen, offset print_int_buffer
cmp eax, [@@padding]
jge @@end
mov ebx, [@@padding]
sub ebx, eax
mov edx, offset print_int_buffer
add edx, ebx
inc eax
call memmove, edx, offset print_int_buffer, eax
call memset, offset print_int_buffer, '0', ebx
@@end:
ret
endp pad_print_buffer
proc print_int_padded
arg @@value:dword, @@padding:dword
uses eax
call itoa, [@@value], offset print_int_buffer, 10
call pad_print_buffer, [@@padding]
call print_str, offset print_int_buffer
ret
endp print_int_padded
;; Prints an integer to STDOUT in hexadecimal notation (prefixed with 0x)
proc print_hex
arg @@value:dword
uses eax
call print_str, offset hex_prefix
call itoa, [@@value], offset print_int_buffer, 16
call print_str, offset print_int_buffer
ret
endp print_hex
proc print_hex_padded
arg @@value:dword, @@padding:dword
uses eax
call itoa, [@@value], offset print_int_buffer, 16
call pad_print_buffer, [@@padding]
call print_str, offset print_int_buffer
ret
endp print_hex_padded
proc print_float
arg @@fl_value:dword
local @@temp:dword
uses eax
xor eax, eax
fldz
fld [@@fl_value]
fcompp
fnstsw ax
fld [@@fl_value]
shr eax, 8
and eax, 111B
cmp eax, 1
jne @@not_negative
call print_char, '-'
fld1
fchs
fmul
@@not_negative:
;; intpart:
fist [@@temp]
call print_int, [@@temp]
call print_char, '.'
fild [@@temp]
fsub
fld [float_1000000]
fmul
fistp [@@temp]
call print_int_padded, [@@temp], 6
ret
endp print_float
proc print_hex_multiple
arg @@count:dword
uses eax, ecx
mov eax, 12
mov ecx, 0
@@print_loop:
cmp ecx, [@@count]
je @@end
call print_hex, [dword ptr ebp+eax]
call print_space
add eax, 4
inc ecx
jmp @@print_loop
@@end:
ret
endp print_hex_multiple
proc print_hexdump
arg @@addr:PTR byte, @@amount:dword
uses eax, ebx, ecx
;; iterate through memory, print 16 bytes at a time
mov eax, [@@addr]
and eax, -10h
mov ecx, 0
@@print_loop:
cmp ecx, [@@amount]
jge @@end
call print_str, offset hex_prefix
mov ebx, eax
add ebx, ecx
call print_hex_padded, ebx, 8
call print_char, ':'
call print_space
call print_hex_padded, [dword ptr eax+ecx], 8
call print_space
add ecx, 4
call print_hex_padded, [dword ptr eax+ecx], 8
call print_space
add ecx, 4
call print_hex_padded, [dword ptr eax+ecx], 8
call print_space
add ecx, 4
call print_hex_padded, [dword ptr eax+ecx], 8
call print_newline
add ecx, 4
jmp @@print_loop
@@end:
ret
endp print_hexdump
proc log_prefix
uses eax
call print_char, '['
call print_space
call gettime_millis
call print_int, eax
call print_space
call print_char, ']'
call print_space
ret
endp log_prefix
proc log_str
arg @@str:dword
call log_prefix
call print_str, [@@str]
call print_newline
ret
endp log_str
proc log_char
arg @@char:dword
call log_prefix
call print_char, [@@char]
call print_newline
ret
endp log_char
proc log_int
arg @@value:dword
call log_prefix
call print_int, [@@value]
call print_newline
ret
endp log_int
proc log_hex
arg @@value:dword
call log_prefix
call print_hex, [@@value]
call print_newline
ret
endp log_hex
;; Exits the program with the given statuscode
proc exit
arg @@exitcode:dword
uses eax, ebx
ifdef NASM
mov eax, 1
mov ebx, 0
int 80h
else
mov ebx, [@@exitcode]
mov ah, 4ch
mov al, bl
int 21h
ret
endif
endp exit
;; =============================================================================
;; file io functions
;; =============================================================================
proc open_file
arg @@file_name:dword, @@access_mode:dword returns eax
uses ebx, ecx, edx
ifndef NASM
;; Since the return value is in ax, we want to make sure the entire
;; register is clean
xor eax, eax
mov edx, [@@file_name]
mov ecx, [@@access_mode]
mov ah, 3Dh
int 21h
else
mov eax, 5 ;; open syscall
mov ebx, [@@file_name]
mov ecx, [@@access_mode]
int 80h
endif
ret
endp open_file
;; Creates a file, returns the file handle. If the file already exists
;; it will trunctate the file.
proc create_file
arg @@file_name:dword, @@access_mode:dword returns eax
uses ebx, ecx, edx
ifndef NASM
;; Since the return value is in ax, we want to make sure the entire
;; register is clean
xor eax, eax
mov edx, [@@file_name]
mov ecx, [@@access_mode]
mov ah, 3Ch
int 21h
else
;; Delete it if it exists, for some reason this is the only way ????
mov eax, 10
mov ebx, [@@file_name]
int 80h
;mov eax, 5 ;; open syscall
mov eax, 8 ;; creat syscall
mov ebx, [@@file_name]
mov ecx, [@@access_mode]
or ecx, 00440 ;; Set readable
int 80h
endif
ret
endp create_file
;; Closes a file
proc close_file
arg @@file_handle:dword
uses eax, ebx
ifndef NASM
mov ebx, [@@file_handle]
mov ah, 3Eh
int 21h
else
mov eax, 6
mov ebx, [@@file_handle]
int 80h
endif
ret
endp close_file
;; Reads bytes from a file.
proc read_file
arg @@file_handle:dword, @@data:dword, @@count:dword returns eax
uses ebx, ecx, edx
ifndef NASM
mov ah, 3Fh
mov ebx, [@@file_handle]
mov ecx, [@@count]
mov edx, [@@data]
int 21h
else
mov eax, 3
mov ebx, [@@file_handle]
mov ecx, [@@data]
mov edx, [@@count]
int 80h
endif
ret
endp read_file
;; Reads 1 byte from a file, incredibly inefficient but it is easier than
;; buffering large files in memory, especially since we have so little memory in
;; dosbox.
proc read_file_char
arg @@file_handle:dword
local @@buf:dword
uses ebx, ecx, edx
mov [@@buf], 0
ifndef NASM
mov ah, 3Fh
mov ebx, [@@file_handle]
mov ecx, 1
lea edx, [@@buf]
int 21h
else
mov eax, 3
mov ebx, [@@file_handle]
lea ecx, [@@buf]
mov edx, 1
int 80h
endif
cmp eax, 0
je @@end
mov eax, [@@buf]
@@end:
ret
endp read_file_char
proc read_line_from_file
arg @@file_handle:dword, @@buffer:dword, @@max:dword
uses eax, ebx, ecx
;; Space for the nullbyte
dec [@@max]
mov ebx, [@@buffer]
xor ecx, ecx
@@read_loop:
cmp ecx, [@@max]
je @@end
call read_file_char, [@@file_handle]
;; EOF
cmp eax, 0
je @@end
;; Save the read byte
mov [byte ptr ebx+ecx], al
;; If we hit the end of the line (windows files have a CRLF lineending,
;; wheras linux has LF. To make sure the files we use work on both we will
;; check for both.
cmp al, 13 ;; carriage return (cr)
je @@cr_newline
cmp al, 10 ;; newline (lf)
je @@end
;; When we have a CRLF we want don't want to include the CR in our line so
;; we decrement ecx with one to make sure we overwrite it with a null byte
;; in the next iteration
jmp @@continue
@@cr_newline:
dec ecx
@@continue:
inc ecx
jmp @@read_loop
@@end:
;; Set the nullbyte
mov [byte ptr ebx+ecx], 0
ret
endp read_line_from_file
;; Writes bytes to a file.
proc write_file
arg @@file_handle:dword, @@data:dword, @@count:dword
uses eax, ebx, ecx, edx
ifndef NASM
mov ah, 40h
mov ebx, [@@file_handle]
mov ecx, [@@count]
mov edx, [@@data]
int 21h
else
mov eax, 4
mov ebx, [@@file_handle]
mov ecx, [@@data]
mov edx, [@@count]
int 80h
endif
ret
endp write_file
;; Writes a null terminated string to a file. Includes the nullbyte.
proc write_str
arg @@file_handle:dword, @@string:dword
uses eax
call strlen, [@@string]
;; We want to write the null byte as well
inc eax
call write_file, [@@file_handle], [@@string], eax
ret
endp write_str
proc lseek_file
arg @@file_handle:dword, @@offset:dword, @@origin:dword
uses ebx, ecx, edx
ifndef NASM
;; offset is passed via CX:DX
;; so here we make sure DX holds the lower half of origin
mov edx, [@@offset]
;; And here we shift so CX holds the upper half of origin
mov ecx, [@@offset]
shr ecx, 16
mov ebx, [@@file_handle]
mov al, [byte ptr @@origin]
mov ah, 42h
int 21h
;; Stitch dx:ax together to eax
xor ecx, ecx
mov cx, ax
shl edx, 16
or ecx, edx
mov eax, ecx
else
mov eax, 19
mov ebx, [@@file_handle]
mov ecx, [@@offset]
mov edx, [@@origin]
int 80h
endif
ret
endp lseek_file
proc wait_for_keypress
uses eax
ifndef NASM
mov ax, 01h
int 16h
endif
ret
endp wait_for_keypress
;; =============================================================================
;; C standard library functions
;; =============================================================================
;; ASM version of C's strlen() function. Returns the length of a null
;; terminated string.
proc strlen
arg @@data:dword returns eax
uses ebx, ecx
xor eax, eax
mov ebx, [@@data]
@@countloop:
mov ecx, [ebx+eax]
cmp cl, 0
je @@end
inc eax
jmp @@countloop
@@end:
ret
endp strlen
;; ASM version of C's memcmp() function. Compares two parts of memory. Returns
;; zero in case they are identical.
proc memcmp
arg @@d1:dword, @@d2:dword, @@count:dword returns eax
uses ebx, ecx, esi, edi, edx
mov eax, 0
mov ecx, 0
mov esi, [@@d1]
mov edi, [@@d2]
jmp @@cmploop
@@next:
inc ecx
@@cmploop:
cmp ecx, [@@count]
je @@end
movzx edx, [byte ptr esi + ecx]
movzx ebx, [byte ptr edi + ecx]
cmp edx, ebx
je @@next
mov eax, edx
sub eax, ebx
@@end:
ret
endp memcmp
;; ASM version of C's strcmp() function. Compares two null terminated strings
;; and returns 0 if they are identical.
proc strcmp
arg @@s1:dword, @@s2:dword returns eax
uses ebx
call strlen, [@@s2]
mov ebx, eax
call strlen, [@@s1]
sub ebx, eax
cmp ebx, 0
jne @@end
call memcmp, [@@s1], [@@s2], eax
@@end:
ret
endp strcmp
;; ASM version of C's strchr() function. Finds a needle (character) in a
;; haystack (string). Returns NULL if not found otherwise a pointer to the
;; first occurance of the character in the string.
proc strchr
arg @@str:PTR byte, @@char:dword
uses ebx
mov eax, [@@str]
mov ebx, [@@char]
@@search_loop:
cmp [byte ptr eax], 0
je @@end_fail
cmp [byte ptr eax], bl
je @@end
inc eax
jmp @@search_loop
@@end_fail:
mov eax, 0
@@end:
ret
endp strchr
;; Returns a pointer to the nullbyte of the string
proc strend
arg @@str:PTR byte
mov eax, [@@str]
@@search_loop:
cmp [byte ptr eax], 0
je @@end
inc eax
jmp @@search_loop
@@end:
ret
endp strend
;; ASM version of C's itoa() function. Converts an integer value to a
;; null terminated string using the specified base.
proc itoa
arg @@value:dword, @@buffer:dword, @@base:dword returns eax
local @@is_neg:dword
uses ebx, ecx, edx
mov [@@is_neg], 0
mov ebx, [@@value]
mov ecx, [@@buffer]
;; Check if value is zero, if so we handle that seperately here
cmp ebx, 0
jne @@not_zero
mov [byte ptr ecx], '0'
inc ecx
mov [byte ptr ecx], 0
jmp @@end
@@not_zero:
;; Only base 10 numbers are handled as signed
cmp [@@base], 10
jne @@not_neg
cmp ebx, 0
jge @@not_neg
mov [@@is_neg], 1
neg ebx
@@not_neg:
cmp ebx, 0
je @@check_neg
xor edx, edx
mov eax, ebx
div [@@base]
mov ebx, eax
mov eax, offset itoa_lookup
mov edx, [eax + edx]
mov [ecx], edx
inc ecx
jmp @@not_neg
@@check_neg:
cmp [@@is_neg], 0
je @@add_trailing_zero
mov [byte ptr ecx], "-"
inc ecx
@@add_trailing_zero:
mov [byte ptr ecx], 0
call strrev, [@@buffer]
@@end:
mov eax, [@@buffer]
ret
endp itoa
;; ASM implementation of C's atof. Will read a float from a string and return
;; it will return 0.f on failure.
proc atof
arg @@str:dword
local @@mantissa:dword, @@exponent:dword, @@negative:dword, @@divide_by:dword, @@res:dword
uses ebx, ecx, edx
;; Little bit of pseudo code for the function
;;
;; mantissa = 0
;; exponent = 0
;; negative = false
;; divide_by = 0
;;
;; if line[0] == '-':
;; negative = true
;; line = line++
;;
;; for x in line:
;; if x == '.':
;; jmp read_mantissa
;; if x not in 0123456789:
;; jmp assemble_and_exit
;; exponent *= 10
;; exponent += x - '0'
;;
;; read_mantissa:
;; for x in line
;; if x not in 012456789
;; jmp assemble_and_exit
;;
;; divide_by += 1
;; mantissa *= 10
;; mantissa += x - '0'
;;
;; assemble_and_exit:
;; fld mantissa
;; for i in range(divide_by):
;; fdiv 10
;; fild exponent
;; fadd
;; if negate:
;; fchs
;;
mov [@@mantissa], 0
mov [@@exponent], 0
mov [@@negative], 0
mov [@@divide_by], 0
mov ecx, [@@str]
cmp [byte ptr ecx], '-'
jne @@exponent_loop
mov [@@negative], 1
inc ecx
@@exponent_loop:
movzx ebx, [byte ptr ecx]
;; When we read a '.' we have to start interpreting the mantissa
cmp bl, '.'
je @@read_mantissa
;; If we read a character out of range (0-9), we simply return
cmp bl, '0'
jl @@assemble_and_exit
cmp bl, '9'
jg @@assemble_and_exit
;; Add the next number to the exponent
mov eax, 10
mul [@@exponent]
mov [@@exponent], eax
sub ebx, '0'
add [@@exponent], ebx
inc ecx
jmp @@exponent_loop
@@read_mantissa:
;; Skip over the '.' symbol
inc ecx
@@mantissa_loop:
movzx ebx, [byte ptr ecx]
;; If we read a character out of range (0-9), we simply return
cmp bl, '0'
jl @@assemble_and_exit
cmp bl, '9'
jg @@assemble_and_exit
;; Will later be used to calculate the actual mantissa
inc [@@divide_by]
;; Add the next number to the mantissa
mov eax, 10
mul [@@mantissa]
mov [@@mantissa], eax
sub ebx, '0'
add [@@mantissa], ebx
inc ecx
jmp @@mantissa_loop
@@assemble_and_exit:
fild [@@mantissa]
mov ebx, [@@divide_by]
@@divide_loop:
cmp ebx, 0
je @@after_divide
fdiv [float_10]
fst [@@res]
dec ebx
jmp @@divide_loop
@@after_divide:
fild [@@exponent]
fadd
fst [@@res]
cmp [@@negative], 0
je @@end
fchs
@@end:
fstp [@@res]
mov eax, [@@res]
ret
endp atof
proc atoi
arg @@str:PTR byte
uses ebx, ecx, edx
;; eax will contain the int we are extracting
mov eax, 0
mov ebx, [@@str]
@@convert_loop:
cmp [byte ptr ebx], 0
je @@end
;; If the character is out of range (0-9) return from the function
cmp [byte ptr ebx], '0'
jl @@end
cmp [byte ptr ebx], '9'
jg @@end
;; Multiply by 10 and add the next value
mov edx, 10
mul edx
movzx ecx, [byte ptr ebx]
sub ecx, '0'
add eax, ecx
inc ebx
jmp @@convert_loop
@@end:
ret
endp atoi
;; ASM version of C's strrev() function. Reverses a null-terminated string
proc strrev
arg @@string:DWORD
uses ebx, eax, ecx, edx
call strlen, [@@string]
mov ebx, eax
dec ebx
mov eax, 0
@@count_loop:
cmp eax, ebx
jge @@end
mov ecx, [@@string]
mov edx, [ecx + eax]
push edx
mov edx, [ecx + ebx]
add ecx, eax
mov [byte ptr ecx], dl
mov ecx, [@@string]
add ecx, ebx
pop edx
mov [byte ptr ecx], dl
inc eax
dec ebx
jmp @@count_loop
@@end:
ret
endp strrev
;; ASM version of C's memset() function
proc memset
arg @@data:dword, @@value:dword, @@count:dword returns eax
uses ecx, edi
mov ecx, [@@count]
mov edi, [@@data]
mov al, [byte ptr @@value]
rep stosb
mov eax, [@@data]
ret
endp memset
;; Non optimized memcpy
;; TODO: untested
proc memcpy
arg @@dest:PTR byte, @@src:PTR byte, @@count:dword returns eax
uses ecx, edi, esi
mov edi, [@@dest]
mov esi, [@@src]
mov ecx, [@@count]
rep movsb
mov eax, [@@dest]
ret
endp memcpy
;; Non optimized memmove
;; TODO: untested (pretty damn sure it works tho)
proc memmove
arg @@dest:PTR byte, @@src:PTR byte, @@count:dword returns eax
uses ecx, ebx, edi, esi
mov edi, [@@dest]
mov esi, [@@src]
mov ecx, [@@count]
cmp edi, esi
je @@end ;; Obviously we don't need to do anything dest == src
js @@regular ;; We can do a regular memcpy memmove dest < src
@@right_to_left:
std ;; Set direction flag to right to left
mov ebx, ecx
dec ebx
add edi, ebx
add esi, ebx
rep movsb
cld
jmp @@end
@@regular:
rep movsb
@@end:
mov eax, [@@dest]
ret
endp memmove
;; =============================================================================
;; time functions
;; =============================================================================
;; Returns the current time in milliseconds
proc gettime_millis
arg returns eax
uses ebx, ecx, edx, esi
ifdef NASM
mov eax, 0
else
mov ah, 2Ch
int 21h
movzx eax, ch
;; eax holds the hours
push edx
mov esi, 60
mul esi
movzx ebx, cl
add eax, ebx
;; eax holds the minutes
mov esi, 60
mul esi
pop edx
movzx ebx, dh
add eax, ebx