2018-12-03 04:43:39 +00:00
|
|
|
# Print an error message and exit.
|
|
|
|
|
|
|
|
== code
|
|
|
|
# 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-12-03 18:15:24 +00:00
|
|
|
# main:
|
|
|
|
e8/call run-tests/disp32 # 'run-tests' is a function created automatically by SubX. It calls all functions that start with 'test-'.
|
|
|
|
# syscall(exit, Num-test-failures)
|
|
|
|
8b/copy 0/mod/indirect 5/rm32/.disp32 . . 3/r32/EBX Num-test-failures/disp32 # copy *Num-test-failures to EBX
|
2018-12-28 16:56:21 +00:00
|
|
|
b8/copy-to-EAX 1/imm32/exit
|
2018-12-03 18:15:24 +00:00
|
|
|
cd/syscall 0x80/imm8
|
|
|
|
|
2018-12-03 04:43:39 +00:00
|
|
|
# write(out, "Error: "+msg+"\n") then stop(ed, 1)
|
|
|
|
error: # ed : (address exit-descriptor), out : fd or (address stream), msg : (address array byte) -> <void>
|
|
|
|
# . prolog
|
|
|
|
55/push-EBP
|
|
|
|
89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . . # copy ESP to EBP
|
|
|
|
# write(out, "Error: ")
|
|
|
|
# . . push args
|
|
|
|
68/push "Error: "/imm32
|
|
|
|
ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none . . 0xc/disp8 . # push *(EBP+12)
|
|
|
|
# . . call
|
|
|
|
e8/call write/disp32
|
|
|
|
# . . discard args
|
|
|
|
81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP
|
|
|
|
# write(out, msg)
|
|
|
|
# . . push args
|
|
|
|
ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none . . 0x10/disp8 . # push *(EBP+16)
|
|
|
|
ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none . . 0xc/disp8 . # push *(EBP+12)
|
|
|
|
# . . call
|
|
|
|
e8/call write/disp32
|
|
|
|
# . . discard args
|
|
|
|
81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP
|
|
|
|
# write(out, Newline)
|
|
|
|
# . . push args
|
|
|
|
68/push Newline/imm32
|
|
|
|
ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none . . 0xc/disp8 . # push *(EBP+12)
|
|
|
|
# . . call
|
|
|
|
e8/call write/disp32
|
|
|
|
# . . discard args
|
|
|
|
81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP
|
|
|
|
# stop(ed, 1)
|
|
|
|
# . . push args
|
|
|
|
68/push 1/imm32
|
|
|
|
ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none . . 8/disp8 . # push *(EBP+8)
|
|
|
|
# . . call
|
|
|
|
e8/call stop/disp32
|
|
|
|
# should never get past this point
|
2018-12-04 08:29:06 +00:00
|
|
|
$error:dead-end:
|
2018-12-03 04:43:39 +00:00
|
|
|
# . epilog
|
|
|
|
89/copy 3/mod/direct 4/rm32/ESP . . . 5/r32/EBP . . # copy EBP to ESP
|
|
|
|
5d/pop-to-EBP
|
|
|
|
c3/return
|
2018-12-04 08:17:40 +00:00
|
|
|
|
|
|
|
# . . vim:nowrap:textwidth=0
|