about summary refs log tree commit diff stats
path: root/subx/ex3.subx
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2018-07-07 14:31:56 -0700
committerKartik Agaram <vc@akkartik.com>2018-07-07 14:31:56 -0700
commit97a9bd1756d5ea934372847bb9f1dfa8a4ad256d (patch)
tree359caa004ebc46ce1bfe9d6e1c6054e395567604 /subx/ex3.subx
parentbc394aaf39da72d980933a720b6deb8876036c07 (diff)
downloadmu-97a9bd1756d5ea934372847bb9f1dfa8a4ad256d.tar.gz
4324 - new example: add first ten numbers
Result has to be small enough to fit in AL so exit() can return it.
Diffstat (limited to 'subx/ex3.subx')
-rw-r--r--subx/ex3.subx23
1 files changed, 23 insertions, 0 deletions
diff --git a/subx/ex3.subx b/subx/ex3.subx
new file mode 100644
index 00000000..df793f5d
--- /dev/null
+++ b/subx/ex3.subx
@@ -0,0 +1,23 @@
+## add the first 10 numbers
+
+# opcode        ModR/M                    SIB                   displacement    immediate
+# instruction   mod, reg, Reg/Mem bits    scale, index, base
+# 1-3 bytes     0/1 byte                  0/1 byte              0/1/2/4 bytes   0/1/2/4 bytes
+  # result: EBX
+# 0: e_entry = 0x08048054
+  bb                                                                            0/imm32       # copy 0 to EBX
+  # counter: ECX
+  b9                                                                            1/imm32       # copy 1 to ECX
+
+# 10: loop: 0x0804805e
+  81            f9                                                              10/imm32      # compare ECX, 10/imm
+  7f                                                            0a                            # jump-if-greater exit (+10)
+  01            cb                                                                            # add ECX to EBX
+  81            c1                                                              1/imm32       # add 1 to ECX
+  eb                                                            ee                            # jump loop (-18; -00010010; 11101110)
+
+# 28: exit: 0x08048070
+  b8                                                                            1/imm32       # copy 1 to EAX
+  cd                                                                            128/imm8      # int 80h
+
+# vim:ft=subx:nowrap