about summary refs log tree commit diff stats
path: root/README.md
Commit message (Expand)AuthorAgeFilesLines
* 6218 - link to Mu's first forkKartik Agaram2020-05-101-0/+9
* 6200 - --dump is not needed for incremental tracesKartik Agaram2020-04-091-1/+1
* 6174Kartik Agaram2020-03-271-1/+1
* 6171Kartik Agaram2020-03-251-2/+2
* 6168Kartik Agaram2020-03-251-1/+1
* 6167Kartik Agaram2020-03-251-1/+1
* 6166Kartik Agaram2020-03-251-2/+2
* 6165Kartik Agaram2020-03-251-10/+10
* 6154 - include link to the Mu paperKartik Agaram2020-03-161-1/+1
* 6151Kartik Agaram2020-03-151-2/+6
* 6142Kartik Agaram2020-03-141-6/+9
* 6141Kartik Agaram2020-03-141-0/+12
* 6140Kartik Agaram2020-03-141-2/+1
* 6127Kartik Agaram2020-03-111-0/+11
* 5968Kartik Agaram2020-02-011-8/+10
* 5966 - document all supported Mu instructionsKartik Agaram2020-01-311-2/+3
* 5965Kartik Agaram2020-01-311-10/+1
* 5886Kartik Agaram2020-01-121-3/+4
* 5874Kartik Agaram2020-01-021-7/+1
* 5873Kartik Agaram2020-01-021-25/+20
* 5872Kartik Agaram2020-01-021-7/+7
* 5871Kartik Agaram2020-01-021-2/+2
* 5869Kartik Agaram2020-01-021-7/+8
* 5868Kartik Agaram2020-01-021-0/+791
#0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
# Rudimentary test harness

== 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

Entry:  # manual test
    # check-ints-equal(34, 34)
    # . . push args
    68/push  "error in check-ints-equal"/imm32
    68/push  34/imm32
    68/push  34/imm32
    # . . call
    e8/call  check-ints-equal/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               0xc/imm32         # add to esp
    # syscall(exit, 0)
    bb/copy-to-ebx  0/imm32
    e8/call  syscall_exit/disp32

# print msg to stderr if a != b, otherwise print "."
check-ints-equal:  # a: int, b: int, msg: (addr array byte)
    # . prologue
    55/push-ebp
    89/copy                         3/mod/direct    5/rm32/ebp    .           .             .           4/r32/esp   .               .                 # copy esp to ebp
    # . save registers
    50/push-eax
    51/push-ecx
    53/push-ebx
    # load first 2 args into eax and ebx
    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
    # if (eax == ebx) success
    39/compare                      3/mod/direct    0/rm32/eax    .           .             .           3/r32/ebx   .               .                 # compare eax and ebx
    75/jump-if-unequal  $check-ints-equal:else/disp8
    # . _write(2/stderr, '.')
    # . . push args
    68/push  "."/imm32
    68/push  2/imm32/stderr
    # . . call
    e8/call  _write/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               8/imm32           # add to esp
    # . return
    eb/jump  $check-ints-equal:end/disp8
    # otherwise print error message
$check-ints-equal:else:
    # . _write(2/stderr, msg)
    # . . push args
    8b/copy                         1/mod/*+disp8   5/rm32/ebp    .           .             .           1/r32/ecx   0x10/disp8      .                 # copy *(ebp+16) to ecx
    51/push-ecx
    68/push  2/imm32/stderr
    # . . call
    e8/call  _write/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               8/imm32           # add to esp
    # . _write(2/stderr, Newline)
    # . . push args
    68/push  Newline/imm32
    68/push  2/imm32/stderr
    # . . call
    e8/call  _write/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               8/imm32           # add to esp
    # increment Num-test-failures
    ff          0/subop/increment   0/mod/indirect  5/rm32/.disp32            .             .           .           Num-test-failures/disp32          # increment *Num-test-failures
$check-ints-equal:end:
    # . restore registers
    5b/pop-to-ebx
    59/pop-to-ecx
    58/pop-to-eax
    # . epilogue
    89/copy                         3/mod/direct    4/rm32/esp    .           .             .           5/r32/ebp   .               .                 # copy ebp to esp
    5d/pop-to-ebp
    c3/return

== data

# length-prefixed string containing just a single newline
# convenient to have when printing messages and so on
Newline:  # (array byte)
    # size: int
    1/imm32
    # data
    0a/newline

# every test failure increments this counter
Num-test-failures:  # int
    0/imm32

# length-prefixed string containing just a single space
Space:  # (array byte)
    # size: int
    1/imm32
    # data
    20/space

# length-prefixed string containing just a single slash
Slash:  # (array byte)
    # size: int
    1/imm32
    # data
    2f/slash

# . . vim:nowrap:textwidth=0