ARM7 Mystery Programs

From BenningtonWiki
Jump to: navigation, search

Mystery Program #1

   0:   b500            push    {lr}
   2:   fffef7ff        bl      start_main
   6:   fffef7ff        bl      get_number      (result goes into r0)
   a:   2804            cmp     r0, #4
   c:   d005            beq     1a
   e:   2806            cmp     r0, #6
  10:   d003            beq     1a
  12:   2809            cmp     r0, #9
  14:   d001            beq     1a
  16:   280b            cmp     r0, #11
  18:   d101            bne     1e
  1a:   221e            mov     r2, #30
  1c:   e004            b       28
  1e:   2802            cmp     r0, #2
  20:   d101            bne     26
  22:   221c            mov     r2, #28
  24:   e000            b       28
  26:   221f            mov     r2, #31
  28:   2000            mov     r0, #0
  2a:   2100            mov     r1, #0
  2c:   fffef7ff        bl      draw_number
  30:   e7fe            b       30

What are the results when get_number() returns 11? 5? 2?

Mystery Program #2

   0:   b500            push    {lr}
   2:   fffef7ff        bl      start_main
   6:   fffef7ff        bl      get_number      (result goes into r0)
   a:   2200            mov     r2, #0
   c:   2800            cmp     r0, #0
   e:   dd03            ble     18
  10:   1812            add     r2, r2, r0
  12:   3801            sub     r0, #1
  14:   2800            cmp     r0, #0
  16:   dcfb            bgt     10
  18:   2000            mov     r0, #0
  1a:   2100            mov     r1, #0
  1c:   fffef7ff        bl      draw_number
  20:   e7fe            b       20

What are the results when get_number() returns 3? 7?

Mystery Program #3

   0:   b500            push    {lr}
   2:   fffef7ff        bl      start_main
   6:   2264            mov     r2, #100
   8:   2300            mov     r3, #0
   a:   2b04            cmp     r3, #4
   c:   dc01            bgt     12
   e:   3a01            sub     r2, #1
  10:   e000            b       14
  12:   3202            add     r2, #2
  14:   3301            add     r3, #1
  16:   2b09            cmp     r3, #9
  18:   ddf7            ble     a
  1a:   2000            mov     r0, #0
  1c:   2100            mov     r1, #0
  1e:   fffef7ff        bl      draw_number
  22:   e7fe            b       22

What is the result?