2018-10-16 07:15:51 +00:00
|
|
|
# Rudimentary test harness
|
|
|
|
|
2018-10-01 19:22:59 +00:00
|
|
|
== code
|
2018-11-30 19:10:44 +00:00
|
|
|
# instruction effective address register displacement immediate
|
|
|
|
# . op subop mod rm32 base index scale r32
|
|
|
|
# . 1-3 bytes 3 bits 2 bits 3 bits 3 bits 3 bits 2 bits 2 bits 0/1/2/4 bytes 0/1/2/4 bytes
|
2018-10-01 22:12:56 +00:00
|
|
|
|
2019-02-19 05:48:19 +00:00
|
|
|
Entry: # manual test
|
2018-11-30 18:54:42 +00:00
|
|
|
# check-ints-equal(34, 34)
|
2018-12-01 00:45:15 +00:00
|
|
|
# . . push args
|
2018-11-30 18:54:42 +00:00
|
|
|
68/push "error in check-ints-equal"/imm32
|
|
|
|
68/push 34/imm32
|
|
|
|
68/push 34/imm32
|
2018-12-01 00:45:15 +00:00
|
|
|
# . . call
|
2018-11-30 18:54:42 +00:00
|
|
|
e8/call check-ints-equal/disp32
|
2018-12-01 00:45:15 +00:00
|
|
|
# . . discard args
|
2018-11-30 18:54:42 +00:00
|
|
|
81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32 # add to ESP
|
|
|
|
# syscall(exit, 0)
|
|
|
|
bb/copy-to-EBX 0/imm32
|
2018-12-01 00:45:15 +00:00
|
|
|
b8/copy-to-EAX 1/imm32/exit
|
2018-11-30 18:54:42 +00:00
|
|
|
cd/syscall 0x80/imm8
|
2018-10-11 05:21:26 +00:00
|
|
|
|
2018-10-01 19:22:59 +00:00
|
|
|
# print msg to stderr if a != b, otherwise print "."
|
2018-12-06 17:27:26 +00:00
|
|
|
check-ints-equal: # (a : int, b : int, msg : (address array byte)) -> <void>
|
2018-11-30 19:10:44 +00:00
|
|
|
# . prolog
|
2018-11-30 18:54:42 +00:00
|
|
|
55/push-EBP
|
|
|
|
89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . . # copy ESP to EBP
|
2018-11-30 19:10:44 +00:00
|
|
|
# . save registers
|
2018-12-06 17:27:26 +00:00
|
|
|
50/push-EAX
|
2018-11-30 18:54:42 +00:00
|
|
|
51/push-ECX
|
|
|
|
53/push-EBX
|
|
|
|
# load first 2 args into EAX and EBX
|
2018-12-29 21:36:06 +00:00
|
|
|
8b/copy 1/mod/*+disp8 5/rm32/EBP . . . 0/r32/EAX 8/disp8 . # copy *(EBP+8) to EAX
|
|
|
|
8b/copy 1/mod/*+disp8 5/rm32/EBP . . . 3/r32/EBX 0xc/disp8 . # copy *(EBP+12) to EBX
|
2019-02-15 00:24:20 +00:00
|
|
|
# if (EAX == EBX) success
|
2018-11-30 18:54:42 +00:00
|
|
|
39/compare 3/mod/direct 0/rm32/EAX . . . 3/r32/EBX . . # compare EAX and EBX
|
|
|
|
75/jump-if-unequal $check-ints-equal:else/disp8
|
2018-12-01 00:45:15 +00:00
|
|
|
# . _write(2/stderr, '.')
|
2018-11-30 19:10:44 +00:00
|
|
|
# . . push args
|
2018-11-30 18:54:42 +00:00
|
|
|
68/push "."/imm32
|
|
|
|
68/push 2/imm32/stderr
|
2018-11-30 19:10:44 +00:00
|
|
|
# . . call
|
2018-11-30 18:54:42 +00:00
|
|
|
e8/call _write/disp32
|
2018-11-30 19:10:44 +00:00
|
|
|
# . . discard args
|
2018-11-30 18:54:42 +00:00
|
|
|
81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP
|
2018-12-01 00:45:15 +00:00
|
|
|
# . return
|
2018-11-30 18:54:42 +00:00
|
|
|
eb/jump $check-ints-equal:end/disp8
|
2018-12-01 00:45:15 +00:00
|
|
|
# otherwise print error message
|
2018-10-06 02:49:47 +00:00
|
|
|
$check-ints-equal:else:
|
2018-12-01 00:45:15 +00:00
|
|
|
# . _write(2/stderr, msg)
|
2018-11-30 19:10:44 +00:00
|
|
|
# . . push args
|
2018-12-29 21:36:06 +00:00
|
|
|
8b/copy 1/mod/*+disp8 5/rm32/EBP . . . 1/r32/ECX 0x10/disp8 . # copy *(EBP+16) to ECX
|
2018-11-30 18:54:42 +00:00
|
|
|
51/push-ECX
|
|
|
|
68/push 2/imm32/stderr
|
2018-11-30 19:10:44 +00:00
|
|
|
# . . call
|
2018-11-30 18:54:42 +00:00
|
|
|
e8/call _write/disp32
|
2018-11-30 19:10:44 +00:00
|
|
|
# . . discard args
|
2018-11-30 18:54:42 +00:00
|
|
|
81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP
|
2018-12-01 00:45:15 +00:00
|
|
|
# . _write(2/stderr, Newline)
|
2018-11-30 19:10:44 +00:00
|
|
|
# . . push args
|
2018-11-30 18:54:42 +00:00
|
|
|
68/push Newline/imm32
|
|
|
|
68/push 2/imm32/stderr
|
2018-11-30 19:10:44 +00:00
|
|
|
# . . call
|
2018-11-30 18:54:42 +00:00
|
|
|
e8/call _write/disp32
|
2018-11-30 19:10:44 +00:00
|
|
|
# . . discard args
|
2018-11-30 18:54:42 +00:00
|
|
|
81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP
|
2018-10-06 02:49:47 +00:00
|
|
|
# increment Num-test-failures
|
2018-11-30 18:54:42 +00:00
|
|
|
ff 0/subop/increment 0/mod/indirect 5/rm32/.disp32 . . . Num-test-failures/disp32 # increment *Num-test-failures
|
2018-10-06 02:49:47 +00:00
|
|
|
$check-ints-equal:end:
|
2018-11-30 19:10:44 +00:00
|
|
|
# . restore registers
|
2018-11-30 18:54:42 +00:00
|
|
|
5b/pop-to-EBX
|
|
|
|
59/pop-to-ECX
|
2018-12-06 17:27:26 +00:00
|
|
|
58/pop-to-EAX
|
2018-11-30 19:10:44 +00:00
|
|
|
# . epilog
|
2018-11-30 18:54:42 +00:00
|
|
|
89/copy 3/mod/direct 4/rm32/ESP . . . 5/r32/EBP . . # copy EBP to ESP
|
|
|
|
5d/pop-to-EBP
|
|
|
|
c3/return
|
2018-10-01 19:22:59 +00:00
|
|
|
|
|
|
|
== data
|
|
|
|
|
2018-12-30 08:16:32 +00:00
|
|
|
# length-prefixed string containing just a single newline
|
|
|
|
# convenient to have when printing messages and so on
|
2018-10-01 19:22:59 +00:00
|
|
|
Newline:
|
2018-11-30 18:54:42 +00:00
|
|
|
# size
|
2019-02-16 01:20:57 +00:00
|
|
|
1/imm32
|
2018-11-30 18:54:42 +00:00
|
|
|
# data
|
|
|
|
0a/newline
|
2018-10-01 22:12:56 +00:00
|
|
|
|
2018-12-30 08:16:32 +00:00
|
|
|
# every test failure increments this counter
|
2018-10-06 02:49:47 +00:00
|
|
|
Num-test-failures:
|
2019-02-16 01:20:57 +00:00
|
|
|
0/imm32
|
2018-10-05 20:31:53 +00:00
|
|
|
|
2018-11-30 19:10:44 +00:00
|
|
|
# . . vim:nowrap:textwidth=0
|