about summary refs log tree commit diff stats
path: root/subx/ex3.subx
blob: 4dcb10e93e2f0f2c761fec865f77ee399ee688e1 (plain) (blame)
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
## add the first 10 numbers, and return the result in the exit code
#
# To run:
#   $ subx translate ex3.subx ex3
#   $ subx run ex3
# Expected result:
#   $ echo $?
#   55

== 0x08048054  # code segment, after leaving room for ELF header
# instruction                     effective address                                           operand     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
  # result: EBX = 0
# 0: e_entry = 0x08048054
  bb                                                                                                                      0/imm32           # copy 0 to EBX
  # counter: ECX = 1
  b9                                                                                                                      1/imm32           # copy 1 to ECX

# 10: loop: 0x0804805e
  # while (ECX <= 10)
  81            7/subop/compare   3/mod/direct    1/rm32/ecx                                                              0xa/imm32         # compare ECX, 10/imm
  7f                                                                                                      0xa/disp8                         # jump-if-greater exit (+10 bytes)
  # EBX += ECX
  01                              3/mod/direct    3/rm32/ebx                                  1/r32/ecx                                     # add ECX to EBX
  # ECX++
  81            0/subop/add       3/mod/direct    1/rm32/ecx                                                              1/imm32           # add 1 to ECX
  # loop
  eb                                                                                                      -0x12/disp8                       # jump loop (-18 bytes)

# 28: exit: 0x08048070
  # exit(EBX)
  b8                                                                                                                      1/imm32           # copy 1 to EAX
  cd                                                                                                                      0x80/imm8         # int 80h

# vim:ft=subx:nowrap
*/ .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 */
-- simple immediate-mode buttons

button_handlers = {}

-- draw button and queue up event handlers
function button(name, params)
  love.graphics.setColor(params.color[1], params.color[2], params.color[3])
  love.graphics.rectangle('fill', params.x,params.y, params.w,params.h, 5,5)
  if params.icon then params.icon(params.x, params.y) end
  table.insert(button_handlers, params)
end

-- process button event handlers
function propagate_to_button_handlers(x, y, mouse_button)
  for _,ev in ipairs(button_handlers) do
    if x>ev.x and x<ev.x+ev.w and y>ev.y and y<ev.y+ev.h then
      if ev.onpress1 and mouse_button == 1 then ev.onpress1() end
    end
  end
end